Skip to content

Commit

Permalink
New tests for DiseaseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
japilo committed Sep 27, 2024
1 parent 3b26a27 commit a98f40c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 8 deletions.
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# v 1.0.0 (27 Sep 2024)

## Enhancements

- A vignette has been added using `epizootic` to model house finch conjunctivitis.
- Examples have been added to two of the functions.
- `aspatial_siri` now runs much faster.
- `check_aspatial_siri_inputs` now checks inputs much more thoroughly.
- There are now unit tests to ensure that no dispersers are created or destroyed.
- New tests have been added for `DiseaseModel`.

## Bug fixes
- Broken links to other packages have been fixed.
- `siri_model` functions can now handle one active population.
- `disease_simulator` no longer breaks when demographic rates are given as lists and masks are given as vectors.
- Non-breeding season length is now calculated correctly.
- `disease_dispersal` can now handle the case when dispersal does not change over time.
- `disease_dispersal` was not working properly when there was density dependent dispersal and matrix-formatted dispersal data. This is now fixed.

# v 0.2.1 (2 Apr 2024)

- Important bug fix: the number of occupied indices now updates more frequently within the
Expand Down
94 changes: 86 additions & 8 deletions tests/testthat/test-DiseaseModel.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,87 @@
test_that("active get and set", {
region = Region$new(coordinates = array(c(1:4, 4:1), c(7, 2)))
disease_model <- DiseaseModel$new(time_steps = 10)
expect_null(disease_model$populations)
disease_model$initial_abundance <- seq(10, 60, by = 10)
expect_equal(disease_model$populations, 6)
disease_model$region <- region
expect_equal(disease_model$populations, 7)
test_that("DiseaseModel initializes correctly", {
model <- DiseaseModel$new()
expect_true(inherits(model, "DiseaseModel"))
expect_true(inherits(model, "SimulationModel"))
expect_equal(model$seasons, 1)
expect_equal(model$results_breakdown, "segments")
expect_equal(model$stages, 1)
expect_equal(model$compartments, 1)
})

test_that("DiseaseModel sets and gets attributes correctly", {
model <- DiseaseModel$new()
model$populations <- 100
expect_equal(model$populations, 100)

model$initial_abundance <- matrix(1:100, nrow = 10)
expect_equal(model$initial_abundance, matrix(1:100, nrow = 10))

model$demographic_stochasticity <- FALSE
expect_false(model$demographic_stochasticity)

model$standard_deviation <- 0.1
expect_equal(model$standard_deviation, 0.1)

model$correlation <- list(type = "spatial", value = 0.5)
expect_equal(model$correlation, list(type = "spatial", value = 0.5))

model$stages <- 3
expect_equal(model$stages, 3)

model$compartments <- 2
expect_equal(model$compartments, 2)

model$results_breakdown <- "pooled"
expect_equal(model$results_breakdown, "pooled")

model$carrying_capacity <- matrix(1:100, nrow = 10)
expect_equal(model$carrying_capacity, matrix(1:100, nrow = 10))

model$density_dependence <- "logistic"
expect_equal(model$density_dependence, "logistic")

model$growth_rate_max <- 1.2
expect_equal(model$growth_rate_max, 1.2)

model$fecundity <- c(0.5, 0.6, 0.7)
expect_equal(model$fecundity, c(0.5, 0.6, 0.7))

model$density_stages <- c(1, 0.5, 0.2)
expect_equal(model$density_stages, c(1, 0.5, 0.2))

model$dispersal_source_n_k <- list(cutoff = 0.5, threshold = 0.2)
expect_equal(model$dispersal_source_n_k, list(cutoff = 0.5, threshold = 0.2))

model$dispersal_target_k <- 0.8
expect_equal(model$dispersal_target_k, 0.8)

model$dispersal_target_n <- list(threshold = 0.3, cutoff = 0.1)
expect_equal(model$dispersal_target_n, list(threshold = 0.3, cutoff = 0.1))

model$dispersal_target_n_k <- list(threshold = 0.4, cutoff = 0.2)
expect_equal(model$dispersal_target_n_k, list(threshold = 0.4, cutoff = 0.2))

model$abundance_threshold <- 10
expect_equal(model$abundance_threshold, 10)

model$seasons <- 4
expect_equal(model$seasons, 4)

model$results_selection <- c("abundance", "occupancy")
expect_equal(model$results_selection, c("abundance", "occupancy"))
})

test_that("DiseaseModel handles attribute aliases correctly", {
model <- DiseaseModel$new(attribute_aliases = list(dispersal_data = "dispersal"))
model$set_attributes(dispersal_data = list(strategy = "random", rate = 0.1))
expect_equal(model$dispersal, list(strategy = "random", rate = 0.1))
})

# Test set_sample_attributes method
test_that("DiseaseModel set_sample_attributes works correctly", {
model <- DiseaseModel$new()

model$set_sample_attributes(params = list(populations = 100, seasons = 2))
expect_equal(model$populations, 100)
expect_equal(model$seasons, 2)
})

0 comments on commit a98f40c

Please sign in to comment.