mrc-ide / individual

R Package for individual based epidemiological models
https://mrc-ide.github.io/individual
Other
30 stars 16 forks source link

fix variable reset update and standardize all variable error handling #156

Closed slwu89 closed 3 years ago

slwu89 commented 3 years ago

This will fix #152, and adds a large suite of tests for each variable type (integer, double, and categorical) to check for this and quite a few other bugs. All variables now have a function variable_type_get_size defined in the .cpp file that gets the maximum size of the variable so that we can check at the R level if incoming Bitset objects are the right size, even if they are empty.

Tests akin to this https://github.com/slwu89/individual/blob/bug/variable_reset_update/tests/testthat/test-integervariable-update.R#L296 are set up for each variable type to make sure that resizing problem in #152 is caught in the future (well, it will throw an error).

This also adds new testthat files, test-variabletype-update.R which test the queue_update and update methods of each type in a more rigorous way.

Finally I took out all of any calls to stopifnot, as it already handles the case of a vector of logical values as well as a single logical value.

codecov[bot] commented 3 years ago

Codecov Report

Merging #156 (922dd3b) into dev (52b9487) will increase coverage by 1.23%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #156      +/-   ##
==========================================
+ Coverage   94.68%   95.92%   +1.23%     
==========================================
  Files          26       26              
  Lines        1185     1201      +16     
==========================================
+ Hits         1122     1152      +30     
+ Misses         63       49      -14     
Impacted Files Coverage Δ
R/bitset.R 85.10% <100.00%> (+2.12%) :arrow_up:
R/categorical_variable.R 100.00% <100.00%> (ø)
R/double_variable.R 100.00% <100.00%> (ø)
R/integer_variable.R 96.55% <100.00%> (+0.39%) :arrow_up:
R/targeted_event.R 85.18% <100.00%> (ø)
inst/include/DoubleVariable.h 100.00% <100.00%> (ø)
inst/include/IntegerVariable.h 100.00% <100.00%> (+7.40%) :arrow_up:
src/categorical_variable.cpp 100.00% <100.00%> (ø)
src/double_variable.cpp 96.55% <100.00%> (-3.45%) :arrow_down:
src/integer_variable.cpp 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7be533d...922dd3b. Read the comment docs.