Skip to content

Commit

Permalink
tidy.mvgam() snapshot value tests
Browse files Browse the repository at this point in the history
The snapshots (note: not snapshot values) record what's printed, and the `check()` call led to a different truncation compared to `test_active_file()`, so I'll just use `expect_snapshot_value()` instead, even though it's harder to read.
  • Loading branch information
swpease committed Jan 16, 2025
1 parent d88b0c9 commit 996c23e
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 103 deletions.
261 changes: 174 additions & 87 deletions tests/testthat/_snaps/tidier_methods.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,122 @@
# `tidy()` snapshot of `mvgam_example1`
# `tidy()` snapshot value of `mvgam_example1`

Code
tidy.mvgam(mvgam_example1)
Output
# A tibble: 7 × 7
parameter type mean sd `2.5%` `50%` `97.5%`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_obs[1] observation_family_extra_param 0.49 0.087 0.34 0.49 0.63
2 sigma_obs[2] observation_family_extra_param 0.47 0.1 0.32 0.48 0.69
3 sigma_obs[3] observation_family_extra_param 0.37 0.22 0.097 0.44 0.65
4 (Intercept) observation_beta 0.48 0.099 0.3 0.48 0.63
5 sigma[1] trend_model_param 0.016 0.0068 0.0083 0.013 0.027
6 sigma[2] trend_model_param 0.097 0.058 0.039 0.071 0.21
7 sigma[3] trend_model_param 0.44 0.27 0.11 0.36 0.84

# `tidy()` snapshot of `mvgam_example2`

Code
tidy.mvgam(mvgam_example2)
Output
# A tibble: 9 × 7
parameter type mean sd `2.5%` `50%` `97.5%`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_obs[1] observation_family_extra_param 0.52 0.11 0.36 0.51 0.78
2 sigma_obs[2] observation_family_extra_param 0.47 0.066 0.35 0.47 0.59
3 sigma_obs[3] observation_family_extra_param 0.7 0.065 0.6 0.71 0.85
4 (Intercept) observation_beta 1.2 2.3 -3.9 1.7 4
5 Sigma[1,1] trend_model_param 0.065 0.042 0.0063 0.058 0.14
6 Sigma[2,1] trend_model_param -0.0032 0.0081 -0.017 -0.0021 0.011
7 Sigma[1,2] trend_model_param -0.0032 0.0081 -0.017 -0.0021 0.011
8 Sigma[2,2] trend_model_param 0.0044 0.0047 0.00053 0.002 0.015
9 (Intercept)_trend trend_beta -0.84 2.2 -3.5 -1.3 4.3
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["parameter", "type", "mean", "sd", "2.5%", "50%", "97.5%"]
},
"row.names": {
"type": "integer",
"attributes": {},
"value": [1, 2, 3, 4, 5, 6, 7]
},
"class": {
"type": "character",
"attributes": {},
"value": ["tbl_df", "tbl", "data.frame"]
}
},
"value": [
{
"type": "character",
"attributes": {},
"value": ["sigma_obs[1]", "sigma_obs[2]", "sigma_obs[3]", "(Intercept)", "sigma[1]", "sigma[2]", "sigma[3]"]
},
{
"type": "character",
"attributes": {},
"value": ["observation_family_extra_param", "observation_family_extra_param", "observation_family_extra_param", "observation_beta", "trend_model_param", "trend_model_param", "trend_model_param"]
},
{
"type": "double",
"attributes": {},
"value": [0.49, 0.47, 0.37, 0.48, 0.016, 0.097, 0.44]
},
{
"type": "double",
"attributes": {},
"value": [0.087, 0.1, 0.22, 0.099, 0.0068, 0.058, 0.27]
},
{
"type": "double",
"attributes": {},
"value": [0.34, 0.32, 0.097, 0.3, 0.0083, 0.039, 0.11]
},
{
"type": "double",
"attributes": {},
"value": [0.49, 0.48, 0.44, 0.48, 0.013, 0.071, 0.36]
},
{
"type": "double",
"attributes": {},
"value": [0.63, 0.69, 0.65, 0.63, 0.027, 0.21, 0.84]
}
]
}

# `tidy()` snapshot of `mvgam_example3`
# `tidy()` snapshot value of `mvgam_example2`

Code
tidy.mvgam(mvgam_example3)
Output
# A tibble: 22 × 7
parameter type mean sd `2.5%` `50%` `97.5%`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_obs[1] observation_family_extra_param 0.49 0.075 0.39 0.48 0.66
2 sigma_obs[2] observation_family_extra_param 0.52 0.087 0.38 0.53 0.69
3 sigma_obs[3] observation_family_extra_param 0.37 0.23 0.093 0.3 0.79
4 (Intercept) observation_beta 0.46 0.072 0.36 0.44 0.61
5 A[1,1] trend_model_param -0.14 0.51 -0.94 -0.32 0.63
6 A[2,1] trend_model_param -0.15 0.56 -1.3 -0.057 0.52
7 A[3,1] trend_model_param 0.59 1.2 -1.3 0.38 3.2
8 A[1,2] trend_model_param 0.063 0.42 -0.65 0.038 0.87
9 A[2,2] trend_model_param -0.18 0.49 -1.1 -0.085 0.6
10 A[3,2] trend_model_param 0.63 1.7 -2.7 0.32 4.2
# ℹ 12 more rows
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["parameter", "type", "mean", "sd", "2.5%", "50%", "97.5%"]
},
"row.names": {
"type": "integer",
"attributes": {},
"value": [1, 2, 3, 4, 5, 6, 7, 8, 9]
},
"class": {
"type": "character",
"attributes": {},
"value": ["tbl_df", "tbl", "data.frame"]
}
},
"value": [
{
"type": "character",
"attributes": {},
"value": ["sigma_obs[1]", "sigma_obs[2]", "sigma_obs[3]", "(Intercept)", "Sigma[1,1]", "Sigma[2,1]", "Sigma[1,2]", "Sigma[2,2]", "(Intercept)_trend"]
},
{
"type": "character",
"attributes": {},
"value": ["observation_family_extra_param", "observation_family_extra_param", "observation_family_extra_param", "observation_beta", "trend_model_param", "trend_model_param", "trend_model_param", "trend_model_param", "trend_beta"]
},
{
"type": "double",
"attributes": {},
"value": [0.52, 0.47, 0.7, 1.2, 0.065, -0.0032, -0.0032, 0.0044, -0.84]
},
{
"type": "double",
"attributes": {},
"value": [0.11, 0.066, 0.065, 2.3, 0.042, 0.0081, 0.0081, 0.0047, 2.2]
},
{
"type": "double",
"attributes": {},
"value": [0.36, 0.35, 0.6, -3.9, 0.0063, -0.017, -0.017, 0.00053, -3.5]
},
{
"type": "double",
"attributes": {},
"value": [0.51, 0.47, 0.71, 1.7, 0.058, -0.0021, -0.0021, 0.002, -1.3]
},
{
"type": "double",
"attributes": {},
"value": [0.78, 0.59, 0.85, 4, 0.14, 0.011, 0.011, 0.015, 4.3]
}
]
}

# `tidy()` snapshot value of `mvgam_example3`

Expand Down Expand Up @@ -112,26 +178,6 @@
]
}

# `tidy()` snapshot of `mvgam_example4`

Code
tidy.mvgam(mvgam_example4)
Output
# A tibble: 34 × 7
parameter type mean sd `2.5%` `50%` `97.5%`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_obs[1] observation_family_extra_param 0.45 0.1 0.28 0.45 0.6
2 sigma_obs[2] observation_family_extra_param 0.39 0.11 0.17 0.42 0.55
3 sigma_obs[3] observation_family_extra_param 0.62 0.14 0.38 0.62 0.89
4 (Intercept) observation_beta 0.29 1.6 -4.1 0.4 2.6
5 seriesseries_2 observation_beta -0.13 0.16 -0.46 -0.16 0.21
6 seriesseries_3 observation_beta -0.13 0.13 -0.36 -0.13 0.073
7 A[1,1] trend_model_param 0.21 0.41 -0.6 0.31 0.77
8 A[2,1] trend_model_param 0.51 0.7 -0.3 0.38 2.1
9 A[3,1] trend_model_param 0.21 0.41 -0.46 0.19 1.1
10 A[1,2] trend_model_param 0.11 0.35 -0.56 0.062 0.93
# ℹ 24 more rows

# `tidy()` snapshot value of `mvgam_example4`

{
Expand Down Expand Up @@ -192,22 +238,63 @@
]
}

# `tidy()` snapshot of `mvgam_example5`
# `tidy()` snapshot value of `mvgam_example5`

Code
tidy.mvgam(mvgam_example5)
Output
# A tibble: 10 × 7
parameter type mean sd `2.5%` `50%` `97.5%`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 sigma_obs[1] observation_family_extra_param 0.53 0.07 0.41 0.53 0.64
2 sigma_obs[2] observation_family_extra_param 0.5 0.082 0.37 0.5 0.62
3 sigma_obs[3] observation_family_extra_param 0.63 0.092 0.48 0.64 0.76
4 (Intercept) observation_beta 0.53 0.13 0.32 0.5 0.78
5 seriesseries_2 observation_beta -0.15 0.29 -0.65 -0.15 0.43
6 seriesseries_3 observation_beta -0.061 0.41 -0.52 -0.15 1.2
7 rho_gp[1] trend_model_param 6.2 4.5 1.4 4.4 15
8 rho_gp[2] trend_model_param 6.8 5.6 1.4 5.3 21
9 alpha_gp[1] trend_model_param 0.25 0 0.25 0.25 0.25
10 alpha_gp[2] trend_model_param 0.25 0 0.25 0.25 0.25
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["parameter", "type", "mean", "sd", "2.5%", "50%", "97.5%"]
},
"row.names": {
"type": "integer",
"attributes": {},
"value": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
},
"class": {
"type": "character",
"attributes": {},
"value": ["tbl_df", "tbl", "data.frame"]
}
},
"value": [
{
"type": "character",
"attributes": {},
"value": ["sigma_obs[1]", "sigma_obs[2]", "sigma_obs[3]", "(Intercept)", "seriesseries_2", "seriesseries_3", "rho_gp[1]", "rho_gp[2]", "alpha_gp[1]", "alpha_gp[2]"]
},
{
"type": "character",
"attributes": {},
"value": ["observation_family_extra_param", "observation_family_extra_param", "observation_family_extra_param", "observation_beta", "observation_beta", "observation_beta", "trend_model_param", "trend_model_param", "trend_model_param", "trend_model_param"]
},
{
"type": "double",
"attributes": {},
"value": [0.53, 0.5, 0.63, 0.53, -0.15, -0.061, 6.2, 6.8, 0.25, 0.25]
},
{
"type": "double",
"attributes": {},
"value": [0.07, 0.082, 0.092, 0.13, 0.29, 0.41, 4.5, 5.6, 0, 0]
},
{
"type": "double",
"attributes": {},
"value": [0.41, 0.37, 0.48, 0.32, -0.65, -0.52, 1.4, 1.4, 0.25, 0.25]
},
{
"type": "double",
"attributes": {},
"value": [0.53, 0.5, 0.64, 0.5, -0.15, -0.15, 4.4, 5.3, 0.25, 0.25]
},
{
"type": "double",
"attributes": {},
"value": [0.64, 0.62, 0.76, 0.78, 0.43, 1.2, 15, 21, 0.25, 0.25]
}
]
}

22 changes: 6 additions & 16 deletions tests/testthat/test-tidier_methods.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
context("tidier methods")

# `tidy()` tests
test_that("`tidy()` snapshot of `mvgam_example1`", {
test_that("`tidy()` snapshot value of `mvgam_example1`", {
local_edition(3)
expect_snapshot(tidy.mvgam(mvgam_example1))
expect_snapshot_value(tidy.mvgam(mvgam_example1), style = "json2")
})

test_that("`tidy()` snapshot of `mvgam_example2`", {
test_that("`tidy()` snapshot value of `mvgam_example2`", {
local_edition(3)
expect_snapshot(tidy.mvgam(mvgam_example2))
})

test_that("`tidy()` snapshot of `mvgam_example3`", {
local_edition(3)
expect_snapshot(tidy.mvgam(mvgam_example3))
expect_snapshot_value(tidy.mvgam(mvgam_example2), style = "json2")
})

test_that("`tidy()` snapshot value of `mvgam_example3`", {
local_edition(3)
expect_snapshot_value(tidy.mvgam(mvgam_example3), style = "json2")
})

test_that("`tidy()` snapshot of `mvgam_example4`", {
local_edition(3)
expect_snapshot(tidy.mvgam(mvgam_example4))
})

test_that("`tidy()` snapshot value of `mvgam_example4`", {
local_edition(3)
expect_snapshot_value(tidy.mvgam(mvgam_example4), style = "json2")
})

test_that("`tidy()` snapshot of `mvgam_example5`", {
test_that("`tidy()` snapshot value of `mvgam_example5`", {
local_edition(3)
expect_snapshot(tidy.mvgam(mvgam_example5))
expect_snapshot_value(tidy.mvgam(mvgam_example5), style = "json2")
})


Expand Down

0 comments on commit 996c23e

Please sign in to comment.