Skip to content

Commit

Permalink
add some tests for aspects of #265 and #266
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsimpson committed Mar 25, 2024
1 parent 8114d8c commit c117471
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/data-sim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# data sim for gfam works

Code
print(sim)
Output
# A tibble: 400 x 12
y index family x0 x1 x2 x3 f f0 f1 f2
<dbl> <int> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 1 binary 0.897 0.148 0.348 0.0457 1.59 0.128 0.269 1.20
2 0.237 2 tweedie 0.266 0.659 0.859 0.367 1.10 0.296 0.747 0.0596
3 0.0156 3 normal 0.372 0.185 0.0344 0.741 0.715 0.368 0.290 0.0575
4 1 1 binary 0.573 0.954 0.971 0.934 1.74 0.390 1.35 0.0000172
5 1.98 3 normal 0.908 0.898 0.745 0.673 1.75 0.114 1.20 0.432
6 11.1 2 tweedie 0.202 0.944 0.273 0.701 3.24 0.237 1.32 1.68
7 0.904 2 tweedie 0.898 0.724 0.677 0.848 1.61 0.126 0.850 0.629
8 0 1 binary 0.945 0.370 0.348 0.706 1.69 0.0692 0.419 1.20
9 0 1 binary 0.661 0.781 0.947 0.859 1.30 0.350 0.954 0.000486
10 1 1 binary 0.629 0.0111 0.339 0.446 1.84 0.368 0.205 1.27
# i 390 more rows
# i 1 more variable: f3 <dbl>

7 changes: 7 additions & 0 deletions tests/testthat/test-data-sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ test_that("test data_sim() reproduces reference output", {
expect_equal(new_sims[[!!(i)]], ref_sims[[!!(i)]])
}
})

test_that("data sim for gfam works", {
expect_silent(sim <- data_sim("gfam", n = 400, seed = 2))
skip_on_ci()
skip_on_cran()
expect_snapshot(print(sim))
})
12 changes: 12 additions & 0 deletions tests/testthat/test-gfam.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# testing gratia's ability to handle gfam models - not much yet
test_that("gfam data sim and model works", {
expect_silent(
gfam_df <- data_sim("gfam", n = 400, seed = 2,
gfam_families = c("binary", "tweedie", "normal"))
)
expect_silent(
m_gfam <- gam(cbind(y, index) ~ s(x0) + s(x1) + s(x2) + s(x3),
family = gfam(list(binomial, tw, gaussian)),
data = gfam_df, method = "REML")
)
})

0 comments on commit c117471

Please sign in to comment.