TopoToolbox / libtopotoolbox

A C library for the analysis of digital elevation models.
https://topotoolbox.github.io/libtopotoolbox/
GNU General Public License v3.0
0 stars 3 forks source link

Refactor tests in random_dem.cpp #66

Closed wkearn closed 2 days ago

wkearn commented 4 days ago

Relevant to #55

This PR refactors test/random_dem.cpp to make the tests more clear. Each test is extracted to its own function, and the random_dem_test function sets up the data, calls the appropriate libtopotoolbox functions, and calls the appropriate test functions.

test/gwdt.cpp, which largely duplicated test/random_dem.cpp, is not merged with test/random_dem.cpp. Its tests are put into a function test_gwdt, which is run with the others. This improves the test speed, because the flow routing functions like fillsinks only need to be run once.

This is not exactly what I would like to do for #55. Adding a new property still requires a lot of boilerplate code for scanning through the result arrays. I am using the assert macro now to throw errors, which is simpler and more readable, but provides less information. Also the assert macro immediately aborts upon test failure, so a single failing property halts the entire testing process.

wkearn commented 4 days ago

Test failures are due to unused variable errors in Release builds. The assert macros don't get expanded in Release builds, so any variables that are only used in the asserts count as unused. Since we do want to test on the Release builds, I think we need to use something other than assert for the tests.