diff --git a/DESCRIPTION b/DESCRIPTION index 18e7294..540a98a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Language: es Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Suggests: + rlecuyer, testthat, withr Config/Needs/website: rmarkdown diff --git a/src/nhppp.h b/src/nhppp.h index 8ccebf1..8308a59 100644 --- a/src/nhppp.h +++ b/src/nhppp.h @@ -63,14 +63,6 @@ Rcpp::NumericMatrix vztdraw_sc_step_regular2( const bool atmost1 ); -// Rcpp::NumericMatrix vdraw_intensity_step_regular( -// const Rcpp::Function & lambda, -// const Rcpp::NumericMatrix & rate_maj, -// const bool is_cumulative, -// const Rcpp::NumericMatrix & range_t, -// const double tol, -// const bool atmost1); - Rcpp::NumericMatrix vdraw_intensity_step_regular( const Rcpp::Function & lambda, const Rcpp::NumericMatrix & rate_maj, diff --git a/tests/testthat/test-vdraw_intensity_step_regular_cpp.R b/tests/testthat/test-vdraw_intensity_step_regular_cpp.R index 7dc721b..182b182 100644 --- a/tests/testthat/test-vdraw_intensity_step_regular_cpp.R +++ b/tests/testthat/test-vdraw_intensity_step_regular_cpp.R @@ -102,3 +102,60 @@ test_that("vdraw_intensity_step_regular_cpp() works with subinterval", { )) check_ppp_sample_validity(Z, t_min = 2.3, t_max = 4.8, atmost1 = FALSE) }) + + +test_that("vdraw_intensity_step_regular_cpp() uses user-supplied RNGs", { + l <- matrix(rep(1, 50), ncol = 5) + L <- mat_cumsum_columns(l) + + seed <- rep(1, 6) + rlecuyer::.lec.SetPackageSeed(seed) + rlecuyer::.lec.CreateStream(c("a", "b")) + + res <- list() + + # seed the old.kind generator (default ) hereon "R" + set.seed(123) + res[["R0"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + set.seed(123) + res[["R1"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + expect_equal(res[["R0"]], res[["R1"]]) + + # activate "a" and reseed "R" -- If the function uses the "R", the test will fail + set.seed(123) + old.kind <- rlecuyer::.lec.CurrentStream("a") + res[["a0"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + rlecuyer::.lec.CurrentStreamEnd(old.kind) + expect_false(identical(res[["R0"]], res[["a0"]])) + + # activate "b", again, re-seed "R" + set.seed(123) + old.kind <- rlecuyer::.lec.CurrentStream("b") + res[["b0"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + rlecuyer::.lec.CurrentStreamEnd(old.kind) + expect_false(identical(res[["R0"]], res[["b0"]])) + expect_false(identical(res[["b0"]], res[["a0"]])) + + # reset the RNGs -- but advance the "R" + burn <- runif(10000) + rm("burn") + rlecuyer::.lec.ResetStartStream("a") + rlecuyer::.lec.ResetStartStream("b") + + # activate "a" -- do not reseed "R" + old.kind <- rlecuyer::.lec.CurrentStream("a") + res[["a1"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + rlecuyer::.lec.CurrentStreamEnd(old.kind) + expect_equal(res[["a0"]], res[["a1"]]) + expect_false(identical(res[["R0"]], res[["a1"]])) + + # activate "b" -- do not reseed "R" + old.kind <- rlecuyer::.lec.CurrentStream("b") + res[["b1"]] <- vdraw_sc_step_regular_cpp(Lambda_matrix = L, range_t = c(100, 110)) + rlecuyer::.lec.CurrentStreamEnd(old.kind) + expect_equal(res[["b0"]], res[["b1"]]) + expect_false(identical(res[["R0"]], res[["b1"]])) + expect_false(identical(res[["a1"]], res[["b1"]])) + + rlecuyer::.lec.exit() +})