Skip to content

Commit a5e9767

Browse files
committed
Used new environment ignoring argument, tolerance instead of tol, and expect_equal() with ignore_attr = TRUE instead of equivalent
1 parent 42c2872 commit a5e9767

10 files changed

Lines changed: 38 additions & 38 deletions

tests/testthat/test-aesthetics.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ prepare_colors_for_test <- function(scheme) {
99

1010
test_that("getting and setting the color scheme works", {
1111
color_scheme_set("red")
12-
expect_equivalent(color_scheme_get(), prepare_colors_for_test("red"))
12+
expect_equal(color_scheme_get(), prepare_colors_for_test("red"), ignore_attr = TRUE)
1313
expect_named(prepare_colors_for_test("blue"), scheme_level_names())
1414
expect_named(color_scheme_get(), scheme_level_names())
1515
for (clr in names(master_color_list)) {
1616
color_scheme_set(clr)
17-
expect_equivalent(color_scheme_get(), prepare_colors_for_test(clr),
17+
expect_equal(color_scheme_get(), prepare_colors_for_test(clr, ignore_attr = TRUE),
1818
info = clr)
1919
expect_named(color_scheme_get(), scheme_level_names())
2020
}
@@ -24,7 +24,7 @@ test_that("getting and setting the color scheme works", {
2424
expect_gg(plot(color_scheme_get("mix-blue-green")))
2525

2626
color_scheme_set("blue")
27-
expect_equivalent(color_scheme_get("teal"), prepare_colors_for_test("teal"))
27+
expect_equal(color_scheme_get("teal"), prepare_colors_for_test("teal"), ignore_attr = TRUE)
2828

2929
# error if not character
3030
expect_error(color_scheme_set(7), "'scheme' should be a character vector of length 1 or 6")
@@ -56,10 +56,10 @@ test_that("color_scheme_get with i argument works", {
5656

5757
test_that("setting mixed scheme works", {
5858
color_scheme_set("mix-gray-blue")
59-
expect_equivalent(color_scheme_get(), mixed_scheme("gray", "blue"))
59+
expect_equal(color_scheme_get(), mixed_scheme("gray", "blue"), ignore_attr = TRUE)
6060

6161
color_scheme_set("mix-blue-gray")
62-
expect_equivalent(color_scheme_get(), mixed_scheme("blue", "gray"))
62+
expect_equal(color_scheme_get(), mixed_scheme("blue", "gray"), ignore_attr = TRUE)
6363

6464
expect_error(color_scheme_set("mix-green-reds"), "should be one of")
6565
expect_error(color_scheme_set("mix-greens-red"), "should be one of")
@@ -68,9 +68,9 @@ test_that("setting mixed scheme works", {
6868
test_that("setting brewer scheme works", {
6969
skip_if_not_installed("RColorBrewer")
7070
color_scheme_set("brewer-Blues")
71-
expect_equivalent(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Blues"))
71+
expect_equal(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Blues"), ignore_attr = TRUE)
7272
color_scheme_set("brewer-Spectral")
73-
expect_equivalent(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Spectral"))
73+
expect_equal(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Spectral"), ignore_attr = TRUE)
7474
expect_error(color_scheme_set("brewer-FAKE"), "FAKE is not a valid palette")
7575
})
7676

@@ -102,11 +102,11 @@ test_that("mixed_scheme internal function doesn't error", {
102102
test_that("custom color schemes work", {
103103
color_scheme_set(orange_scheme_ok)
104104
expect_named(color_scheme_get())
105-
expect_equivalent(unlist(color_scheme_get()), orange_scheme_ok)
105+
expect_equal(unlist(color_scheme_get()), orange_scheme_ok, ignore_attr = TRUE)
106106

107107
random_scheme <- colors()[sample(length(colors()), 6)]
108108
color_scheme_set(random_scheme)
109-
expect_equivalent(unlist(color_scheme_get()), random_scheme)
109+
expect_equal(unlist(color_scheme_get()), random_scheme, ignore_attr = TRUE)
110110
})
111111

112112
test_that("get_color returns correct color values", {

tests/testthat/test-convenience-functions.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ test_that("abline_01 returns the correct object", {
55
a <- abline_01(color = "green", linetype = 2)
66
b <- geom_abline(intercept = 0, slope = 1, color = "green", linetype = 2, na.rm = TRUE)
77
a$constructor <- b$constructor <- NULL
8-
expect_equal(a, b, check.environment = FALSE)
8+
expect_equal(a, b, ignore_function_env = TRUE)
99
})
1010
test_that("vline_* and hline_* return correct objects", {
1111
a <- vline_0(color = "red")
1212
b <- geom_vline(xintercept = 0, color = "red", na.rm = TRUE)
1313
a$constructor <- b$constructor <- NULL
14-
expect_equal(a, b, check.environment = FALSE)
14+
expect_equal(a, b, ignore_function_env = TRUE)
1515

1616
a <- hline_0(linewidth = 2, linetype = 3)
1717
b <- geom_hline(yintercept = 0, linewidth = 2, linetype = 3, na.rm = TRUE)
1818
a$constructor <- b$constructor <- NULL
19-
expect_equal(a, b, check.environment = FALSE)
19+
expect_equal(a, b, ignore_function_env = TRUE)
2020

2121
a <- vline_at(c(3,4), na.rm = FALSE)
2222
b <- geom_vline(xintercept = c(3,4))
2323
a$constructor <- b$constructor <- NULL
24-
expect_equal(a, b, check.environment = FALSE)
24+
expect_equal(a, b, ignore_function_env = TRUE)
2525

2626
a <- hline_at(c(3,4), na.rm = FALSE)
2727
b <- geom_hline(yintercept = c(3,4))
2828
a$constructor <- b$constructor <- NULL
29-
expect_equal(a, b, check.environment = FALSE)
29+
expect_equal(a, b, ignore_function_env = TRUE)
3030
})
3131
test_that("vline_at with 'fun' works", {
3232
x <- example_mcmc_draws(chains = 1)
3333
a <- vline_at(x, colMeans)
3434
b <- geom_vline(xintercept = colMeans(x), na.rm = TRUE)
3535
a$constructor <- b$constructor <- NULL
36-
expect_equal(a, b, check.environment = FALSE)
36+
expect_equal(a, b, ignore_function_env = TRUE)
3737
})
3838
test_that("calc_v (internal function) works", {
3939
a <- 1:4
@@ -96,13 +96,13 @@ test_that("facet_bg returns correct theme object", {
9696
test_that("legend_none returns correct theme object", {
9797
none <- legend_none()
9898
expect_s3_class(none, "theme")
99-
expect_equivalent(none, list(legend.position = "none"))
99+
expect_equal(none, list(legend.position = "none"), ignore_attr = TRUE)
100100
expect_false(attr(none, "complete"))
101101
})
102102
test_that("legend_move returns correct theme object", {
103103
left <- legend_move("left")
104104
expect_s3_class(left, "theme")
105-
expect_equivalent(left, list(legend.position = "left"))
105+
expect_equal(left, list(legend.position = "left"), ignore_attr = TRUE)
106106
expect_false(attr(left, "complete"))
107107

108108
pos <- legend_move(c(0.25, 0.5))
@@ -182,7 +182,7 @@ test_that("overlay_function returns the correct object", {
182182
a <- overlay_function(fun = "dnorm")
183183
b <- stat_function(fun = "dnorm", inherit.aes = FALSE)
184184
a$constructor <- b$constructor <- NULL
185-
expect_equal(a, b, check.environment = FALSE)
185+
expect_equal(a, b, ignore_function_env = TRUE)
186186
})
187187

188188

tests/testthat/test-example-draws.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_that("example ppc data works", {
2323

2424
yrep <- example_yrep_draws()
2525
expect_type(yrep, "double")
26-
expect_is(yrep, "matrix")
26+
expect_true(is.matrix(yrep))
2727
expect_equal(ncol(yrep), length(y))
2828

2929
group <- example_group_data()

tests/testthat/test-extractors.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test_that("neff_ratio.stanreg returns correct structure", {
8181
ratio <- neff_ratio(fit)
8282
expect_named(ratio)
8383
ans <- summary(fit)[1:length(ratio), "n_eff"] / (floor(ITER / 2) * CHAINS)
84-
expect_equal(ratio, ans, tol = 0.001)
84+
expect_equal(ratio, ans, tolerance = 0.001)
8585
})
8686

8787
test_that("rhat.stanfit returns correct structure", {
@@ -104,12 +104,12 @@ test_that("neff_ratio.stanreg returns correct structure", {
104104
ratio <- neff_ratio(fit$stanfit)
105105
expect_named(ratio)
106106
ans <- summary(fit)[, "n_eff"] / denom
107-
expect_equal(ratio, ans, tol = 0.001)
107+
expect_equal(ratio, ans, tolerance = 0.001)
108108

109109
ratio2 <- neff_ratio(fit$stanfit, pars = c("wt", "sigma"))
110110
expect_named(ratio2)
111111
ans2 <- summary(fit, pars = c("wt", "sigma"))[, "n_eff"] / denom
112-
expect_equal(ratio2, ans2, tol = 0.001)
112+
expect_equal(ratio2, ans2, tolerance = 0.001)
113113
})
114114

115115
test_that("cmdstanr methods work", {

tests/testthat/test-helpers-mcmc.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ test_that("diagnostic_factor.rhat works", {
298298
high = 1.2, high = 1.7))
299299

300300
r <- diagnostic_factor(unname(rhats))
301-
expect_equivalent(r, as.factor(names(rhats)))
301+
expect_equal(r, as.factor(names(rhats)), ignore_attr = TRUE)
302302
expect_identical(levels(r), c("low", "ok", "high"))
303303
})
304304
test_that("diagnostic_factor.neff_ratio works", {
@@ -307,7 +307,7 @@ test_that("diagnostic_factor.neff_ratio works", {
307307
high = 0.51, high = 0.99, high = 1))
308308

309309
r <- diagnostic_factor(unname(ratios))
310-
expect_equivalent(r, as.factor(names(ratios)))
310+
expect_equal(r, as.factor(names(ratios)), ignore_attr = TRUE)
311311
expect_identical(levels(r), c("low", "ok", "high"))
312312
})
313313

tests/testthat/test-mcmc-intervals.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test_that("mcmc_intervals_data computes quantiles", {
77

88
qs <- unlist(d[, c("ll", "l", "m", "h", "hh")])
99
by_hand <- quantile(xs$Value, c(.25, .35, .5, .65, .75))
10-
expect_equivalent(qs, by_hand)
10+
expect_equal(qs, by_hand, ignore_attr = TRUE)
1111

1212
expect_equal(d$parameter, factor("beta[1]"))
1313
expect_equal(d$outer_width, .5)
@@ -26,7 +26,7 @@ test_that("mcmc_intervals_data computes point estimates", {
2626
d <- mcmc_intervals_data(arr, pars = "beta[2]",
2727
prob = .3, prob_outer = .5, point_est = "mean")
2828

29-
expect_equivalent(d$m, mean(xs$Value))
29+
expect_equal(d$m, mean(xs$Value), ignore_attr = TRUE)
3030
expect_equal(d$parameter, factor("beta[2]"))
3131
expect_equal(d$point_est, "mean")
3232

tests/testthat/test-mcmc-scatter-and-parcoord.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,40 +210,40 @@ test_that("pairs_condition returns correct structure", {
210210
# default
211211
cond0 <- pairs_condition()
212212
expect_s3_class(cond0, "pairs_condition")
213-
expect_equivalent(unclass(cond0), list())
213+
expect_equal(unclass(cond0), list(), ignore_attr = TRUE)
214214
expect_equal(attr(cond0, "type"), "default")
215215

216216
# chains
217217
cond1 <- pairs_condition(chains = 1:4)
218218
expect_s3_class(cond1, "integer")
219219
expect_s3_class(cond1, "pairs_condition")
220-
expect_equivalent(unclass(cond1), 1:4)
220+
expect_equal(unclass(cond1), 1:4, ignore_attr = TRUE)
221221
expect_equal(attr(cond1, "type"), "chain_vector")
222222

223223
cond2 <- pairs_condition(chains = list(1:4, 5:6))
224224
expect_s3_class(cond2, "list")
225225
expect_s3_class(cond2, "pairs_condition")
226-
expect_equivalent(unclass(cond2), list(upper=1:4, lower=5:6))
226+
expect_equal(unclass(cond2), list(upper=1:4, lower=5:6), ignore_attr = TRUE)
227227
expect_equal(attr(cond2, "type"), "chain_list")
228228

229229
# draws
230230
cond3 <- pairs_condition(draws = 0.7)
231231
expect_s3_class(cond3, "numeric")
232232
expect_s3_class(cond3, "pairs_condition")
233-
expect_equivalent(unclass(cond3), 0.7)
233+
expect_equal(unclass(cond3), 0.7, ignore_attr = TRUE)
234234
expect_equal(attr(cond3, "type"), "draws_proportion")
235235

236236
cond4 <- pairs_condition(draws = c(T, F, T))
237237
expect_s3_class(cond4, "logical")
238238
expect_s3_class(cond4, "pairs_condition")
239-
expect_equivalent(unclass(cond4), c(T, F, T))
239+
expect_equal(unclass(cond4), c(T, F, T), ignore_attr = TRUE)
240240
expect_equal(attr(cond4, "type"), "draws_selection")
241241

242242
# nuts
243243
cond5 <- pairs_condition(nuts = "lp__")
244244
expect_s3_class(cond5, "character")
245245
expect_s3_class(cond5, "pairs_condition")
246-
expect_equivalent(unclass(cond5), "lp__")
246+
expect_equal(unclass(cond5), "lp__", ignore_attr = TRUE)
247247
expect_equal(attr(cond5, "type"), "nuts")
248248
})
249249

tests/testthat/test-pp_check.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ test_that("default pp_check method works", {
66
expect_equal(
77
pp_check(y, yrep[1:50, ], ppc_dens_overlay),
88
ppc_dens_overlay(y, yrep[1:50, ]),
9-
check.environment = FALSE
9+
ignore_function_env = TRUE
1010
)
1111
expect_equal(
1212
pp_check(y, yrep, fun = "stat_grouped", group = g, stat = "median"),
1313
ppc_stat_grouped(y, yrep, group = g, stat = "median"),
14-
check.environment = FALSE
14+
ignore_function_env = TRUE
1515
)
1616
})
1717

tests/testthat/test-ppc-discrete.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ test_that("ppc_bars_data includes all levels", {
7272
d3 <- ppc_bars_data(y_ord, yrep_ord2)
7373
expect_equal(d3$x, 1:4)
7474
expect_equal(d3$y_obs, tab)
75-
expect_equivalent(d3$l[2], 0)
76-
expect_equivalent(d3$m[2], 0)
77-
expect_equivalent(d3$h[2], 0)
75+
expect_equal(d3$l[2], 0, ignore_attr = TRUE)
76+
expect_equal(d3$m[2], 0, ignore_attr = TRUE)
77+
expect_equal(d3$h[2], 0, ignore_attr = TRUE)
7878
})
7979

8080

tests/testthat/test-ppc-input-validation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_that("validate_predictions works", {
2020
expect_equal(validate_predictions(yrep2, length(y2)), yrep2)
2121

2222
colnames(yrep) <- paste0("yrep", 1:ncol(yrep))
23-
expect_equivalent(validate_predictions(yrep, length(y)), unname(yrep))
23+
expect_equal(validate_predictions(yrep, length(y)), unname(yrep), ignore_attr = TRUE)
2424
})
2525
test_that("validate_predictions throws errors", {
2626
expect_error(validate_predictions(as.matrix(LETTERS), length(y)), "numeric")

0 commit comments

Comments
 (0)