-
Notifications
You must be signed in to change notification settings - Fork 4
Unit Tests
The purpose of the unit tests are twofold:
- Ensure proper installation.
- Regression testing.
The second is the most important. Run these tests often to make sure you are not breaking the code.
Unit tests are implemented using a Python wrapper to MachLine and pytest. In a nutshell, the command py.test
will instruct pytest to go look for any Python files with "test" in the name. In these files, it will look for functions that start with "test". After collecting all such functions, it will run all of them and report any errors (Python errors; it won't automatically detect a segmentation fault or something similar for you). Each test is then simply a Python function that runs MachLine in a way that a certain feature or combination of features is ensured to work.
If you use the run_machline()
function defined in test_machline.py
(which you should), then it will raise a Python error if MachLine does not execute properly. Otherwise, it will return the minimum and maximum pressure coefficients, and the force coefficients calculated by MachLine. You may then use Python assert()
statements to check whether these returned values are correct. What assert()
does is raise an error if the argument is false, and does nothing if it is true.
Unit tests should be fast to run (<1 second per test). If they take a long time to run, then it's likely developers won't run them. With that, it's best to implement unit tests using relatively coarse meshes. The point of unit tests is not to get good data. The point is to make sure MachLine is computing what it's supposed to.
4/8/2022 (CDG) When implementing OpenMP as part of MachLine, I discovered that the calculated pressure results were dependent upon the order in which wake edges were declared. Digging deeper, I found that this was simply a function of the order in which the wake panel influences were calculated. I assume this has to do with the errors introduced when using floating point arithmetic to compute sums and differences of values having varying orders of magnitude. Because of this, I chose to relax the failure tolerance for the unit tests to 1e-7, rather than 1e-12.