Source: vignettes/UnitTests.Rmd
Unit Tests
Unit Tests are written using the testthat R package. The tests are
stored in the file: tests/tests_rpath.R. They may be
run explicitly by the user clicking the Test or Check buttons under the
Build tab in RStudio. They also run automatically via git actions when
the user does a push or pull request. The output of the unit tests is a
pdf file with a variety of comparison plots, examples of which are given
below in Figures 1-3.
Details
Unit Tests consist of comparing a “current” model value (i.e.,
string, table) to a previously stored “baseline” value. Differences are
shown in the testing output as well as reflected in the generated plots
which are written to: Rplots.pdf. Difference
“tolerances” are defined by the variable:
which can be modified as necessary.
Regenerating Baseline Files
If the user needs to regenerate the baseline files, the following
variable should be set to TRUE and the tests re-run manually (by
clicking the Test button under the Build tab). This will regenerate all
of the baseline data files.
CREATE_BASELINE_FILES <- TRUE
After the baseline files have been generated, the user should reset
the variable back:
CREATE_BASELINE_FILES <- FALSE
List of Tests
The following unit tests have been developed. Note that some tests
consist of additional/finer tests that compare out_Biomass, out_Catch,
and out_Gear_Catch* for AB (Adams-Bashforth) and RK4 (4th Order Runge
Kutta) numerical differential equation methods.
Unit Tests
Is model balanced?
- Looks for “Balanced” string in Rpath summary file output
Does model run silent?
- Tests if model runs without producing print statements, warnings, or
error messages.
Compare Rpath summaries
- Is the baseline Rpath object the same as the current Rpath
object?
Compare Rpath summaries
- Is the baseline Rpath summary the same as the current Rpath
summary?
Compare baseline AB sim run to current AB sim run
- Checks if baseline Rpath AB sim run is same as current AB sim run
(checks top level data structure only)
- Compare out_Biomass from baseline and current AB sim runs
- Compare out_Catch from baseline and current AB sim runs
- Compare out_Gear_Catch from baseline and current AB sim
runs
Compare baseline RK4 sim run to current RK4 sim run
- Checks if baseline RK4 sim run same as current RK4 sim run (checks
top level data structure only)
- Compare out_Biomass from baseline and current RK4 sim runs
- Compare out_Catch from baseline and current RK4 sim runs
- Compare out_Gear_Catch from baseline and current RK4 sim
runs
Compare baseline AB sim run to current RK4 sim run
- Checks if baseline AB sim run same as current RK4 sim run (checks
top level data structure only)
- Compare out_Biomass from baseline AB run and current RK4 sim
run
- Compare out_Catch from baseline AB run and current RK4 sim
run
- Compare out_Gear_Catch from baseline AB run and current RK4 sim
run
Compare sim runs with random noise (i.e., jitter) added to
$forcing$ForcedBio
- Compare out_Biomass from baseline AB run and current AB run with
noise added to ForcedBio
- Compare out_Catch from baseline AB run and current AB run with noise
added to ForcedBio
- Compare out_Gear_Catch from baseline AB run and current AB run with
noise added to ForcedBio
- Compare out_Biomass from baseline RK4 run and current RK4 run with
noise added to ForcedBio
- Compare out_Catch from baseline RK4 run and current RK4 run with
noise added to ForcedBio
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with noise added to ForcedBio
Compare sim runs with random noise (i.e., jitter) added to
$forcing$ForcedMigrate
- Compare out_Biomass from baseline AB run and current AB run with
noise added to ForcedMigrate
- Compare out_Catch from baseline AB run and current AB run with noise
added to ForcedMigrate
- Compare out_Gear_Catch from baseline AB run and current AB run with
noise added to ForcedMigrate
- Compare out_Biomass from baseline RK4 run and current RK4 run with
noise added to ForcedMigrate
- Compare out_Catch from baseline RK4 run and current RK4 run with
noise added to ForcedMigrate
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with noise added to ForcedMigrate
Compare sim runs with stepped noise added to $forcing$ForcedBio
- Compare out_Biomass from baseline AB run and current AB run with
stepped noise added to ForcedBio
- Compare out_Catch from baseline AB run and current AB run with
stepped noise added to ForcedBio
- Compare out_Gear_Catch from baseline AB run and current AB run with
stepped noise added to ForcedBio
- Compare out_Biomass from baseline RK4 run and current RK4 run with
stepped noise added to ForcedBio
- Compare out_Catch from baseline RK4 run and current RK4 run with
stepped noise added to ForcedBio
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with stepped noise added to ForcedBio
Compare sim runs with stepped noise added to $forcing$ForcedMigrate
- Compare out_Biomass from baseline AB run and current AB run with
stepped noise added to ForcedMigrate
- Compare out_Catch from baseline AB run and current AB run with
stepped noise added to ForcedMigrate
- Compare out_Gear_Catch from baseline AB run and current AB run with
stepped noise added to ForcedMigrate
- Compare out_Biomass from baseline RK4 run and current RK4 run with
stepped noise added to ForcedMigrate
- Compare out_Catch from baseline RK4 run and current RK4 run with
stepped noise added to ForcedMigrate
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with stepped noise added to ForcedMigrate
Compare sim runs with random noise (i.e., jitter) added to
$fishing$ForcedEffort
- Compare out_Biomass from baseline AB run and current AB run with
noise added to ForcedEffort
- Compare out_Catch from baseline AB run and current AB run with noise
added to ForcedEffort
- Compare out_Gear_Catch from baseline AB run and current AB run with
noise added to ForcedEffort
- Compare out_Biomass from baseline RK4 run and current RK4 run with
noise added to ForcedEffort
- Compare out_Catch from baseline RK4 run and current RK4 run with
noise added to ForcedEffort
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with noise added to ForcedEffort
Compare sim runs with random noise (i.e., jitter) added to
$fishing$ForcedFRate
- Compare out_Biomass from baseline AB run and current AB run with
noise added to ForcedFRate
- Compare out_Catch from baseline AB run and current AB run with noise
added to ForcedFRate
- Compare out_Gear_Catch from baseline AB run and current AB run with
noise added to ForcedFRate
- Compare out_Biomass from baseline RK4 run and current RK4 run with
noise added to ForcedFRate
- Compare out_Catch from baseline RK4 run and current RK4 run with
noise added to ForcedFRate
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with noise added to ForcedFRate
Compare sim runs with random noise (i.e., jitter) added to
$fishing$ForcedCatch
- Compare out_Biomass from baseline AB run and current AB run with
noise added to ForcedCatch
- Compare out_Catch from baseline AB run and current AB run with noise
added to ForcedCatch
- Compare out_Gear_Catch from baseline AB run and current AB run with
noise added to ForcedCatch
- Compare out_Biomass from baseline RK4 run and current RK4 run with
noise added to ForcedCatch
- Compare out_Catch from baseline RK4 run and current RK4 run with
noise added to ForcedCatch
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with noise added to ForcedCatch
Compare sim runs with stepped noise added to $fishing$ForcedEffort
- Compare out_Biomass from baseline AB run and current AB run with
stepped noise added to ForcedEffort
- Compare out_Catch from baseline AB run and current AB run with
stepped noise added to ForcedEffort
- Compare out_Gear_Catch from baseline AB run and current AB run with
stepped noise added to ForcedEffort
- Compare out_Biomass from baseline RK4 run and current RK4 run with
stepped noise added to ForcedEffort
- Compare out_Catch from baseline RK4 run and current RK4 run with
stepped noise added to ForcedEffort
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with stepped noise added to ForcedEffort
Compare sim runs with stepped noise added to $fishing$ForcedFRate
- Compare out_Biomass from baseline AB run and current AB run with
stepped noise added to ForcedFRate
- Compare out_Catch from baseline AB run and current AB run with
stepped noise added to ForcedFRate
- Compare out_Gear_Catch from baseline AB run and current AB run with
stepped noise added to ForcedFRate
- Compare out_Biomass from baseline RK4 run and current RK4 run with
stepped noise added to ForcedFRate
- Compare out_Catch from baseline RK4 run and current RK4 run with
stepped noise added to ForcedFRate
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with stepped noise added to ForcedFRate
Compare sim runs with stepped noise added to $fishing$ForcedCatch
- Compare out_Biomass from baseline AB run and current AB run with
stepped noise added to ForcedCatch
- Compare out_Catch from baseline AB run and current AB run with
stepped noise added to ForcedCatch
- Compare out_Gear_Catch from baseline AB run and current AB run with
stepped noise added to ForcedCatch
- Compare out_Biomass from baseline RK4 run and current RK4 run with
stepped noise added to ForcedCatch
- Compare out_Catch from baseline RK4 run and current RK4 run with
stepped noise added to ForcedCatch
- Compare out_Gear_Catch from baseline RK4 run and current RK4 run
with stepped noise added to ForcedCatch
*The out_Gear_Catch tests are currently awaiting issue #74 to be
resolved.
The Unit Tests compare current runs with baseline runs and produce
plots in a pdf file. These plots may be useful for diagnostic purposes.
The plots depict the output of a current run in blue and of the baseline
run in red. If there are no errors, then there should be no red visible
on the plots. There are two types of plots available, also set by a
variable in tests/tests_rpath.R:
If PLOT_TYPE is set to 1, then the plot depicts the current model in
blue superimposed over the baseline model in red. If PLOT_TYPE is set to
2, then the difference (current-baseline) is displayed.
Example plots:
Figure 1 depicts an Rpath Simulation run of Biomass Density vs Time
for 3 species. The REcosystem_scene$forcing$ForcedBio
table, where
has been modified with random noise. Both the baseline and current
model runs use the AB (Adams-Bashforth) numerical differential equation
method. Notice that there is no red line visible in this plot. That is,
the current (blue) line is identical (and covers completely) the
baseline (red) plot.
Figure 2 depicts the same information as Figure 1 with the
difference being that the randomization factor was slightly changed in
the current model from what was used in the baseline model. This was
done to only to highlight how the plot would appear if the current model
deviated from the baseline. Notice that the underlying baseline plot (in
red) is now clearly visible.
Figure 3 shows the difference of the current and baseline
models. If the models were identical, the difference would be 0, and the
plots should be completely flat lines. This plot shows the
current-baseline plots for the data shown in Figure 2. Notice that the
plot lines are not completely flat, denoting that the difference is not
0. The scale of the y-axis may be modified by changing the following
line in tests/tests_rpath.R:
YLIMIT_DIFFERENCE_PLOTS <- 0.05