diff --git a/inst/include/dust2/r/helpers.hpp b/inst/include/dust2/r/helpers.hpp index 80447910..dd2db460 100644 --- a/inst/include/dust2/r/helpers.hpp +++ b/inst/include/dust2/r/helpers.hpp @@ -124,7 +124,7 @@ std::vector check_time_sequence(real_type time_start, cpp11::stop("Expected 'time[%d]' to be integer-like", i + 1); } if (t <= prev) { - cpp11::stop("Expected 'time[%d]' (%d) to larger than the previous value (%d)", + cpp11::stop("Expected 'time[%d]' (%d) to be larger than the previous value (%d)", i + 1, static_cast(prev), static_cast(t)); } prev = t; diff --git a/tests/testthat/test-filter.R b/tests/testthat/test-filter.R index 68e7a28e..88245029 100644 --- a/tests/testthat/test-filter.R +++ b/tests/testthat/test-filter.R @@ -64,3 +64,25 @@ test_that("can run run unfilter on structured model", { ptr <- obj[[1]] expect_equal(dust2_cpu_sir_unfilter_run(ptr, NULL, FALSE), f(pars)) }) + + +test_that("validate time for filter", { + pars <- list(beta = 0.1, gamma = 0.2, N = 1000, I0 = 10, exp_noise = 1e6) + time_start <- 0 + time <- as.integer(c(4, 8, 12, 16)) + data <- lapply(1:4, function(i) list(incidence = i)) + dt <- 1 + + expect_error( + dust2_cpu_sir_unfilter_alloc(pars, 5, time, dt, data, 0), + "Expected 'time[1]' (5) to be larger than the previous value (4)", + fixed = TRUE) + expect_error( + dust2_cpu_sir_unfilter_alloc(pars, 0, time + c(0, 0, .1, 0), dt, data, 0), + "Expected 'time[3]' to be integer-like", + fixed = TRUE) + expect_error( + dust2_cpu_sir_unfilter_alloc(pars, 0, as.character(time), dt, data, 0), + "'time' must be a numeric vector", + fixed = TRUE) +}) diff --git a/tests/testthat/test-sir.R b/tests/testthat/test-sir.R index 53388fc7..1777d0c6 100644 --- a/tests/testthat/test-sir.R +++ b/tests/testthat/test-sir.R @@ -96,3 +96,23 @@ test_that("validate data size on compare", { dust2_cpu_sir_compare_data(ptr, vector("list", 3), TRUE), "'data' must have length 4") }) + + +test_that("can update parameters", { + base <- list(beta = 0.1, gamma = 0.2, N = 1000, I0 = 10, exp_noise = 1e6) + update <- list(beta = 0.3, gamma = 0.2) + combined <- modifyList(base, update) + + obj1 <- dust2_cpu_sir_alloc(base, 0, 1, 10, 0, 42, FALSE) + ptr1 <- obj1[[1]] + expect_null(dust2_cpu_sir_update_pars(ptr1, update, FALSE)) + expect_null(dust2_cpu_sir_run_steps(ptr1, 10)) + + obj2 <- dust2_cpu_sir_alloc(combined, 0, 1, 10, 0, 42, FALSE) + ptr2 <- obj2[[1]] + expect_null(dust2_cpu_sir_run_steps(ptr2, 10)) + + expect_equal( + dust2_cpu_sir_state(ptr2, FALSE), + dust2_cpu_sir_state(ptr1, FALSE)) +})