BDI-pathogens / OpenABM-Covid19

OpenABM-Covid19: an agent-based model for modelling the spread of SARS-CoV-2 (coronavirus) and control interventions for the Covid-19 epidemic
GNU General Public License v3.0
114 stars 76 forks source link

Expose functions in utilities.c for testing #116

Closed p-robot closed 4 years ago

p-robot commented 4 years ago

Exposes the C functions within utilities.c so they can be tested within the pytest framework. This includes tests for all but the most straight-forward tests (no tests for print_now, print_exit, compare_longs). copy_normalize_array is also not tested since it's simply a combination of two other functions that are both tested. Calling the functions that generate random numbers requires first instantiating the objects associated with GSL random number generation so a new function setup_gsl_rng(seed) is added. covid19.i was adjusted to include the declaration of SWIG_PYTHON_CAST_MODE as this bypassed issues when passing arrays of longs to C. There were minor differences in the arrays generated from geometric_max_draw_list and numpy, presumably from rounding error, so this test compares mean values to 2 dp, instead of the whole array. Note that the setup/teardown functions that occur at the pytest class level or pytest "session" level (i.e. a test file) will still be called when running these tests of the utilities even though they're unneccessary. Changing this behaviour will require adjustment of pytest fixtures on all tests so is saved for a separate PR (at the moment it's very little overhead anyway).