Skip to content

Commit 3e9cfe4

Browse files
committed
Some work on moving to 3e
1 parent aa7d7d6 commit 3e9cfe4

13 files changed

+126
-65
lines changed

tests/testthat/_snaps/compare.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# loo_compare returns expected results (2 models)
2+
3+
WAoAAAACAAQFAAACAwAAAAMOAAAAEAAAAAAAAAAAwBA6U1+cRe4AAAAAAAAAAD+2ake0LxMB
4+
wFTh8N3JQljAVeWWE8MGuUARCD2zEXBfQBEalRIN2T9ACijAYdW5U0AmZ5XrANCKP/H9Zexy
5+
814/8ZtgnG1nx0Bk4fDdyUJYQGXllhPDBrlAIQg9sxFwX0AhGpUSDdk/AAAEAgAAAAEABAAJ
6+
AAAAA2RpbQAAAA0AAAACAAAAAgAAAAgAAAQCAAAAAQAEAAkAAAAIZGltbmFtZXMAAAATAAAA
7+
AgAAABAAAAACAAQACQAAAAZtb2RlbDEABAAJAAAABm1vZGVsMgAAABAAAAAIAAQACQAAAAll
8+
bHBkX2RpZmYABAAJAAAAB3NlX2RpZmYABAAJAAAACWVscGRfd2FpYwAEAAkAAAAMc2VfZWxw
9+
ZF93YWljAAQACQAAAAZwX3dhaWMABAAJAAAACXNlX3Bfd2FpYwAEAAkAAAAEd2FpYwAEAAkA
10+
AAAHc2Vfd2FpYwAABAIAAAABAAQACQAAAAVjbGFzcwAAABAAAAADAAQACQAAAAtjb21wYXJl
11+
LmxvbwAEAAkAAAAGbWF0cml4AAQACQAAAAVhcnJheQAAAP4=
12+
13+
# loo_compare returns expected result (3 models)
14+
15+
WAoAAAACAAQFAAACAwAAAAMOAAAAGAAAAAAAAAAAwBA6U1+cRe7AMA3KkbYEGAAAAAAAAAAA
16+
P7ZqR7QvEwE/y6/t4TTtXsBU4fDdyUJYwFXllhPDBrnAWOVjgjbDYkARCD2zEXBfQBEalRIN
17+
2T9AEPIF3GigE0AKKMBh1blTQCZnlesA0IpAQcjYUhrdCj/x/WXscvNeP/GbYJxtZ8c/8YDQ
18+
kmfJX0Bk4fDdyUJYQGXllhPDBrlAaOVjgjbDYkAhCD2zEXBfQCEalRIN2T9AIPIF3GigEwAA
19+
BAIAAAABAAQACQAAAANkaW0AAAANAAAAAgAAAAMAAAAIAAAEAgAAAAEABAAJAAAACGRpbW5h
20+
bWVzAAAAEwAAAAIAAAAQAAAAAwAEAAkAAAAGbW9kZWwxAAQACQAAAAZtb2RlbDIABAAJAAAA
21+
Bm1vZGVsMwAAABAAAAAIAAQACQAAAAllbHBkX2RpZmYABAAJAAAAB3NlX2RpZmYABAAJAAAA
22+
CWVscGRfd2FpYwAEAAkAAAAMc2VfZWxwZF93YWljAAQACQAAAAZwX3dhaWMABAAJAAAACXNl
23+
X3Bfd2FpYwAEAAkAAAAEd2FpYwAEAAkAAAAHc2Vfd2FpYwAABAIAAAABAAQACQAAAAVjbGFz
24+
cwAAABAAAAADAAQACQAAAAtjb21wYXJlLmxvbwAEAAkAAAAGbWF0cml4AAQACQAAAAVhcnJh
25+
eQAAAP4=
26+
27+
# compare returns expected result (2 models)
28+
29+
Code
30+
comp2
31+
Output
32+
<deprecatedWarning in loo::compare(w1, w2): 'loo::compare' is deprecated.
33+
Use 'loo_compare' instead.
34+
See help("Deprecated")>
35+

tests/testthat/_snaps/crps.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# crps matches snapshots
2+
3+
WAoAAAACAAQFAAACAwAAAAITAAAAAgAAAg4AAAACv+IeiUeluMc/vSY1w5IjJgAABAIAAAAB
4+
AAQACQAAAAVuYW1lcwAAABAAAAACAAQACQAAAAhFc3RpbWF0ZQAEAAkAAAACU0UAAAD+AAAA
5+
DgAAAAq/zdHHAHZD6L/K3ky9mEk4v/B2uF/xc76/38/N1JUUkL/Z4VW5uFHUv/D3XaD33ZO/
6+
yPJtFZYXlL/RgM+YTul0v+9F9Rv30V+/6Q2h5ndyqgAABAIAAAH/AAAAEAAAAAIABAAJ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AIABAAJAAAA
31+
CWVzdGltYXRlcwAEAAkAAAAJcG9pbnR3aXNlAAAA/g==
32+

tests/testthat/test_E_loo.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,20 @@ test_that("E_loo return types correct for default/vector method", {
9696
expect_length(E_test_quant_vec2$pareto_k, 1)
9797
})
9898

99-
test_that("E_loo.default equal to reference", {
100-
expect_equal_to_reference(E_test_mean_vec, test_path("reference-results/E_loo_default_mean.rds"))
101-
expect_equal_to_reference(E_test_var_vec, test_path("reference-results/E_loo_default_var.rds"))
102-
expect_equal_to_reference(E_test_sd_vec, test_path("reference-results/E_loo_default_sd.rds"))
103-
expect_equal_to_reference(E_test_quant_vec, test_path("reference-results/E_loo_default_quantile_50.rds"))
104-
expect_equal_to_reference(E_test_quant_vec2, test_path("reference-results/E_loo_default_quantile_10_50_90.rds"))
99+
test_that("E_loo.default equal to snapshots", {
100+
expect_snapshot_value(E_test_mean_vec, style = "serialize")
101+
expect_snapshot_value(E_test_var_vec, style = "serialize")
102+
expect_snapshot_value(E_test_sd_vec, style = "serialize")
103+
expect_snapshot_value(E_test_quant_vec, style = "serialize")
104+
expect_snapshot_value(E_test_quant_vec2, style = "serialize")``
105105
})
106106

107-
test_that("E_loo.matrix equal to reference", {
108-
expect_equal_to_reference(E_test_mean, test_path("reference-results/E_loo_matrix_mean.rds"))
109-
expect_equal_to_reference(E_test_var, test_path("reference-results/E_loo_matrix_var.rds"))
110-
expect_equal_to_reference(E_test_sd, test_path("reference-results/E_loo_matrix_sd.rds"))
111-
expect_equal_to_reference(E_test_quant, test_path("reference-results/E_loo_matrix_quantile_50.rds"))
112-
expect_equal_to_reference(E_test_quant2, test_path("reference-results/E_loo_matrix_quantile_10_90.rds"))
107+
test_that("E_loo.matrix equal to snapshots", {
108+
expect_snapshot_value(E_test_mean, style = "serialize")
109+
expect_snapshot_value(E_test_var, style = "serialize")
110+
expect_snapshot_value(E_test_sd, style = "serialize")
111+
expect_snapshot_value(E_test_quant, style = "serialize")
112+
expect_snapshot_value(E_test_quant2, style = "serialize")
113113
})
114114

115115
test_that("E_loo throws correct errors and warnings", {

tests/testthat/test_compare.R

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ test_that("loo_compare returns expected results (2 models)", {
6767

6868
comp2 <- loo_compare(w1, w2)
6969
expect_s3_class(comp2, "compare.loo")
70-
71-
# expect_equal_to_reference(comp2, "reference-results/loo_compare_two_models.rds")
72-
comp2_ref <- readRDS(test_path("reference-results/loo_compare_two_models.rds"))
73-
expect_equivalent(comp2, comp2_ref)
7470
expect_equal(colnames(comp2), comp_colnames)
75-
71+
72+
expect_snapshot_value(comp2, style = "serialize")
73+
7674
# specifying objects via ... and via arg x gives equal results
7775
expect_equal(comp2, loo_compare(x = list(w1, w2)))
7876
})
@@ -88,9 +86,7 @@ test_that("loo_compare returns expected result (3 models)", {
8886
expect_s3_class(comp1, "compare.loo")
8987
expect_s3_class(comp1, "matrix")
9088

91-
# expect_equal_to_reference(comp1, "reference-results/loo_compare_three_models.rds")
92-
comp1_ref <- readRDS(test_path("reference-results/loo_compare_three_models.rds"))
93-
expect_equivalent(comp1, comp1_ref)
89+
expect_snapshot_value(comp1, style = "serialize")
9490

9591
# specifying objects via '...' gives equivalent results (equal
9692
# except rownames) to using 'x' argument
@@ -106,11 +102,12 @@ test_that("compare throws deprecation warnings", {
106102

107103
test_that("compare returns expected result (2 models)", {
108104
comp1 <- expect_warning(loo::compare(w1, w1), "Deprecated")
109-
expect_output(print(comp1), "elpd_diff")
105+
expect_snapshot(comp1)
106+
# expect_output(print(comp1), "elpd_diff")
110107
expect_equal(comp1[1:2], c(elpd_diff = 0, se = 0))
111108

112109
comp2 <- expect_warning(loo::compare(w1, w2), "Deprecated")
113-
# expect_equal_to_reference(comp2, "reference-results/compare_two_models.rds")
110+
expect_snapshot(comp2)
114111
expect_named(comp2, c("elpd_diff", "se"))
115112
expect_s3_class(comp2, "compare.loo")
116113

@@ -133,7 +130,7 @@ test_that("compare returns expected result (3 models)", {
133130
expect_equal(comp1[1,1], 0)
134131
expect_s3_class(comp1, "compare.loo")
135132
expect_s3_class(comp1, "matrix")
136-
# expect_equal_to_reference(comp1, "reference-results/compare_three_models.rds")
133+
expect_snapshot_value(comp1)
137134

138135
# specifying objects via '...' gives equivalent results (equal
139136
# except rownames) to using 'x' argument

tests/testthat/test_crps.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ test_that("crps computation is correct", {
2424
expect_equal(.crps_fun(pi, pi^2, scale = TRUE), -pi^2/pi - 0.5 * log(pi))
2525
})
2626

27-
test_that("crps matches references", {
28-
expect_equal_to_reference(with_seed(1, crps(x1, x2, y)), 'reference-results/crps.rds')
29-
expect_equal_to_reference(with_seed(1, scrps(x1, x2, y)), 'reference-results/scrps.rds')
30-
expect_equal_to_reference(with_seed(1, loo_crps(x1, x2, y, ll)), 'reference-results/loo_crps.rds')
31-
expect_equal_to_reference(with_seed(1, loo_scrps(x1, x2, y, ll)), 'reference-results/loo_scrps.rds')
27+
test_that("crps matches snapshots", {
28+
expect_snapshot_value(with_seed(1, crps(x1, x2, y)), style = "serialize")
29+
expect_snapshot_value(with_seed(1, scrps(x1, x2, y)), style = "serialize")
30+
expect_snapshot_value(with_seed(1, loo_crps(x1, x2, y, ll)), style = "serialize")
31+
expect_snapshot_value(with_seed(1, loo_scrps(x1, x2, y, ll)), style = "serialize")
3232
})
3333

3434
test_that("input validation throws correct errors", {

tests/testthat/test_gpdfit.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ test_that("gpdfit returns correct result", {
66
set.seed(123)
77
x <- rexp(100)
88
gpdfit_val_old <- unlist(gpdfit(x, wip=FALSE, min_grid_pts = 80))
9-
expect_equal_to_reference(gpdfit_val_old, "reference-results/gpdfit_old.rds")
9+
expect_snapshot_value(gpdfit_val_old, style = "serialize")
1010

1111
gpdfit_val_wip <- unlist(gpdfit(x, wip=TRUE, min_grid_pts = 80))
12-
expect_equal_to_reference(gpdfit_val_wip, "reference-results/gpdfit.rds")
12+
expect_snapshot_value(gpdfit_val_wip, style = "serialize")
1313

1414
gpdfit_val_wip_default_grid <- unlist(gpdfit(x, wip=TRUE))
15-
expect_equal_to_reference(gpdfit_val_wip_default_grid, "reference-results/gpdfit_default_grid.rds")
15+
expect_snapshot_value(gpdfit_val_wip_default_grid, style = "serialize")
1616
})
1717

1818
test_that("qgpd returns the correct result ", {

tests/testthat/test_loo_and_waic.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ test_that("using loo.cores is deprecated", {
2424
})
2525

2626
test_that("loo, waic and elpd results haven't changed", {
27-
expect_equal_to_reference(loo1, "reference-results/loo.rds")
28-
expect_equal_to_reference(waic1, "reference-results/waic.rds")
29-
expect_equal_to_reference(elpd1, "reference-results/elpd.rds")
27+
expect_snapshot_value(loo1, style = "serialize")
28+
expect_snapshot_value(waic1, style = "serialize")
29+
expect_snapshot_value(elpd1, style = "serialize")
3030
})
3131

3232
test_that("loo with cores=1 and cores=2 gives same results", {

tests/testthat/test_loo_moment_matching.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,23 @@ test_that("loo_moment_match.default works", {
196196
expect_equal(loo_moment_match_object$pointwise[,"influence_pareto_k"],loo_manual$pointwise[,"influence_pareto_k"])
197197
expect_equal(loo_moment_match_object$pointwise[,"influence_pareto_k"],loo_manual$diagnostics$pareto_k)
198198

199-
expect_equal_to_reference(loo_moment_match_object, "reference-results/moment_match_loo_1.rds")
199+
expect_snapshot_value(loo_moment_match_object, style = "serialize")
200200

201201
loo_moment_match_object2 <- suppressWarnings(loo_moment_match(x, loo_manual, post_draws_test, log_lik_i_test,
202202
unconstrain_pars_test, log_prob_upars_test,
203203
log_lik_i_upars_test, max_iters = 30L,
204204
k_thres = 0.5, split = FALSE,
205205
cov = TRUE, cores = 1))
206206

207-
expect_equal_to_reference(loo_moment_match_object2, "reference-results/moment_match_loo_2.rds")
207+
expect_snapshot_value(loo_moment_match_object2, style = "serialize")
208208

209209
loo_moment_match_object3 <- suppressWarnings(loo_moment_match(x, loo_manual, post_draws_test, log_lik_i_test,
210210
unconstrain_pars_test, log_prob_upars_test,
211211
log_lik_i_upars_test, max_iters = 30L,
212212
k_thres = 0.5, split = TRUE,
213213
cov = TRUE, cores = 1))
214214

215-
expect_equal_to_reference(loo_moment_match_object3, "reference-results/moment_match_loo_3.rds")
215+
expect_snapshot_value(loo_moment_match_object3, style = "serialize")
216216

217217
loo_moment_match_object4 <- suppressWarnings(loo_moment_match(x, loo_manual, post_draws_test, log_lik_i_test,
218218
unconstrain_pars_test, log_prob_upars_test,
@@ -262,7 +262,7 @@ test_that("variance and covariance transformations work", {
262262
k_thres = 0.0, split = FALSE,
263263
cov = TRUE, cores = 1))
264264

265-
expect_equal_to_reference(loo_moment_match_object, "reference-results/moment_match_var_and_cov.rds")
265+
expect_snapshot_value(loo_moment_match_object, style = "serialize")
266266

267267
})
268268

@@ -315,8 +315,7 @@ test_that("loo_moment_match_split works", {
315315
log_prob_upars = log_prob_upars_test, log_lik_i_upars = log_lik_i_upars_test,
316316
cores = 1, r_eff_i = 1, is_method = "psis")
317317

318-
expect_equal_to_reference(split2, "reference-results/moment_match_split.rds")
319-
318+
expect_snapshot_value(split2, style = "serialize")
320319
})
321320

322321
test_that("passing arguments works", {

tests/testthat/test_loo_predictive_metric.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ test_that('loo_predictive_metric return types are correct', {
7878
expect_named(bacc_quant, c('estimate', 'se'))
7979
})
8080

81-
test_that('loo_predictive_metric is equal to reference', {
82-
expect_equal_to_reference(mae_mean, 'reference-results/loo_predictive_metric_mae_mean.rds')
83-
expect_equal_to_reference(mae_quant, 'reference-results/loo_predictive_metric_mae_quant.rds')
84-
expect_equal_to_reference(rmse_mean, 'reference-results/loo_predictive_metric_rmse_mean.rds')
85-
expect_equal_to_reference(rmse_quant, 'reference-results/loo_predictive_metric_rmse_quant.rds')
86-
expect_equal_to_reference(mse_mean, 'reference-results/loo_predictive_metric_mse_mean.rds')
87-
expect_equal_to_reference(mse_quant, 'reference-results/loo_predictive_metric_mse_quant.rds')
88-
expect_equal_to_reference(acc_mean, 'reference-results/loo_predictive_metric_acc_mean.rds')
89-
expect_equal_to_reference(acc_quant, 'reference-results/loo_predictive_metric_acc_quant.rds')
90-
expect_equal_to_reference(bacc_mean, 'reference-results/loo_predictive_metric_bacc_mean.rds')
91-
expect_equal_to_reference(bacc_quant, 'reference-results/loo_predictive_metric_bacc_quant.rds')
81+
test_that('loo_predictive_metric is equal to snapshot', {
82+
expect_snapshot_value(mae_mean, style = "serialize")
83+
expect_snapshot_value(mae_quant, style = "serialize")
84+
expect_snapshot_value(rmse_mean, style = "serialize")
85+
expect_snapshot_value(rmse_quant, style = "serialize")
86+
expect_snapshot_value(mse_mean, style = "serialize")
87+
expect_snapshot_value(mse_quant, style = "serialize")
88+
expect_snapshot_value(acc_mean, style = "serialize")
89+
expect_snapshot_value(acc_quant, style = "serialize")
90+
expect_snapshot_value(bacc_mean, style = "serialize")
91+
expect_snapshot_value(bacc_quant, style = "serialize")
9292
})
9393

9494
test_that('MAE computation is correct', {

tests/testthat/test_model_weighting.R

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,19 @@ test_that("loo_model_weights (stacking and pseudo-BMA) gives expected result", {
5858
expect_s3_class(w1, "stacking_weights")
5959
expect_length(w1, 3)
6060
expect_named(w1, paste0("model" ,c(1:3)))
61-
expect_equal_to_reference(as.numeric(w1), "reference-results/model_weights_stacking.rds",
62-
tolerance = tol, scale=1)
61+
expect_snapshot_value(as.numeric(w1), style = "serialize")
6362
expect_output(print(w1), "Method: stacking")
64-
63+
6564
w1_b <- loo_model_weights(loo_list)
6665
expect_identical(w1, w1_b)
67-
66+
6867
w2 <- loo_model_weights(ll_list, r_eff_list=r_eff_list,
69-
method = "pseudobma", BB = TRUE)
70-
expect_type(w2, "double")
71-
expect_s3_class(w2, "pseudobma_bb_weights")
72-
expect_length(w2, 3)
73-
expect_named(w2, paste0("model", c(1:3)))
74-
expect_equal_to_reference(as.numeric(w2), "reference-results/model_weights_pseudobma.rds",
75-
tolerance = tol, scale=1)
68+
method = "pseudobma", BB = TRUE)
69+
expect_type(w2, "double")
70+
expect_s3_class(w2, "pseudobma_bb_weights")
71+
expect_length(w2, 3)
72+
expect_named(w2, paste0("model", c(1:3)))
73+
expect_snapshot_value(as.numeric(w2), style = "serialize")
7674
expect_output(print(w2), "Method: pseudo-BMA+")
7775

7876
w3 <- loo_model_weights(ll_list, r_eff_list=r_eff_list,

0 commit comments

Comments
 (0)