Skip to content

Commit

Permalink
Added internal testing data so no data is created within test_that() …
Browse files Browse the repository at this point in the history
…functions, y_single and y_multi are not evaluated globally #1
  • Loading branch information
fontikar committed Mar 20, 2024
1 parent 9cddbc4 commit bab2e1b
Show file tree
Hide file tree
Showing 8 changed files with 1,484 additions and 2,708 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^LICENSE\.md$
^\.github$
^codecov\.yml$
^data-raw$
Binary file added R/sysdata.rda
Binary file not shown.
13 changes: 13 additions & 0 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## code to prepare `DATASET` dataset goes here

true_single <- seq(from=1, by=2.5, length.out=7)
set.seed(2024)
y_single <- true_single + true_single*rnorm(n=7, 0, 0.02) + rnorm(n=7, 0, 0.2)


true_multi <- c(seq(from=1, by=2.5, length.out=7),
seq(from=2, by=2, length.out=7))
set.seed(2024)
y_multi <- true_multi + true_multi*rnorm(n=14, 0, 0.02) + rnorm(n=14, 0, 0.2)

usethis::use_data(y_single, y_multi, overwrite = TRUE, internal = TRUE)
1,188 changes: 550 additions & 638 deletions src/stanExports_constant_multi_ind.h

Large diffs are not rendered by default.

932 changes: 440 additions & 492 deletions src/stanExports_constant_single_ind.h

Large diffs are not rendered by default.

661 changes: 311 additions & 350 deletions src/stanExports_linear.h

Large diffs are not rendered by default.

1,378 changes: 163 additions & 1,215 deletions tests/testthat/_snaps/rmot_models.md

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions tests/testthat/test-rmot_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ test_that("Execution and output: Linear", {
rmot_run(chains = 2, iter = 300, verbose = FALSE, show_messages = FALSE)
)

samps_linear <- rstan::extract(lm_test, permuted=FALSE, inc_warmup=TRUE)
expect_snapshot(samps_linear)
samps_linear_summary <- rstan::summary(lm_test)
expect_snapshot(samps_linear_summary)
expect_visible(lm_test)
expect_s4_class(lm_test, "stanfit")
})

test_that("Execution and output: Constant single individual", {
# Test constant single individual
set.seed(2024)
true_single <- seq(from=1, by=2.5, length.out=7)
y_single <- true_single + true_single*rnorm(n=7, 0, 0.02) + rnorm(n=7, 0, 0.2)

suppressWarnings( #Suppresses stan warnings
constant_single_ind_test <- rmot_model("constant_single_ind") |>
Expand All @@ -48,9 +46,8 @@ test_that("Execution and output: Constant single individual", {
rmot_run(chains = 2, iter = 300, verbose = FALSE, show_messages = FALSE)
)

samps_const_single_ind <- rstan::extract(constant_single_ind_test,
permuted=FALSE, inc_warmup=TRUE)
expect_snapshot(samps_const_single_ind)
samps_const_single_ind_summary <- rstan::summary(constant_single_ind_test)
expect_snapshot(samps_const_single_ind_summary$summary)
expect_visible(constant_single_ind_test)
expect_s4_class(constant_single_ind_test, "stanfit")

Expand All @@ -59,9 +56,6 @@ test_that("Execution and output: Constant single individual", {
test_that("Execution and output: Constant multiple individuals", {
# Test constant multi-individual
set.seed(2024)
true_multi <- c(seq(from=1, by=2.5, length.out=7),
seq(from=2, by=2, length.out=7))
y_multi <- true_multi + true_multi*rnorm(n=14, 0, 0.02) + rnorm(n=14, 0, 0.2)

suppressWarnings( #Suppresses stan warnings
constant_multi_ind_test <- rmot_model("constant_multi_ind") |>
Expand All @@ -76,9 +70,8 @@ test_that("Execution and output: Constant multiple individuals", {
rmot_run(chains = 2, iter = 300, verbose = FALSE, show_messages = FALSE)
)

samps_const_multi_ind <- rstan::extract(constant_multi_ind_test,
permuted=FALSE, inc_warmup=TRUE)
expect_snapshot(samps_const_multi_ind)
samps_const_multi_ind_summary <- rstan::summary(constant_multi_ind_test)
expect_snapshot(samps_const_multi_ind_summary$summary)
expect_visible(constant_multi_ind_test)
expect_s4_class(constant_multi_ind_test, "stanfit")
})

0 comments on commit bab2e1b

Please sign in to comment.