From c5363d3d8beec220549a193f449fad2e71c3d81f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 31 Oct 2024 09:35:29 +0100 Subject: [PATCH] Use snapshot expectations for breaks --- tests/testthat/_snaps/scales.md | 119 ++++++++++++++++++++++++++++++++ tests/testthat/test-scales.R | 69 +++++------------- 2 files changed, 136 insertions(+), 52 deletions(-) diff --git a/tests/testthat/_snaps/scales.md b/tests/testthat/_snaps/scales.md index 549769419c..33b36a3cd8 100644 --- a/tests/testthat/_snaps/scales.md +++ b/tests/testthat/_snaps/scales.md @@ -72,11 +72,130 @@ # numeric scale transforms can produce breaks + Code + test_breaks("asn", limits = c(0, 1)) + Output + [1] 0.00 0.25 0.50 0.75 1.00 + +--- + + Code + test_breaks("sqrt", limits = c(0, 10)) + Output + [1] 0.0 2.5 5.0 7.5 10.0 + +--- + + Code + test_breaks("atanh", limits = c(-0.9, 0.9)) + Output + [1] NA -0.5 0.0 0.5 NA + +--- + + Code + test_breaks(transform_boxcox(0), limits = c(1, 10)) + Output + [1] NA 2.5 5.0 7.5 10.0 + +--- + + Code + test_breaks(transform_modulus(0), c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + + Code + test_breaks(transform_yj(0), c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + + Code + test_breaks("exp", c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + + Code + test_breaks("identity", limits = c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + Code test_breaks("log", limits = c(0.1, 1000)) Output [1] NA 1.00000 20.08554 403.42879 +--- + + Code + test_breaks("log10", limits = c(0.1, 1000)) + Output + [1] 1e-01 1e+00 1e+01 1e+02 1e+03 + +--- + + Code + test_breaks("log2", limits = c(0.5, 32)) + Output + [1] 0.5 2.0 8.0 32.0 + +--- + + Code + test_breaks("log1p", limits = c(0, 10)) + Output + [1] 0.0 2.5 5.0 7.5 10.0 + +--- + + Code + test_breaks("pseudo_log", limits = c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + + Code + test_breaks("logit", limits = c(0.001, 0.999)) + Output + [1] NA 0.25 0.50 0.75 NA + +--- + + Code + test_breaks("probit", limits = c(0.001, 0.999)) + Output + [1] NA 0.25 0.50 0.75 NA + +--- + + Code + test_breaks("reciprocal", limits = c(1, 10)) + Output + [1] NA 2.5 5.0 7.5 10.0 + +--- + + Code + test_breaks("reverse", limits = c(-10, 10)) + Output + [1] -10 -5 0 5 10 + +--- + + Code + test_breaks("sqrt", limits = c(0, 10)) + Output + [1] 0.0 2.5 5.0 7.5 10.0 + # training incorrectly appropriately communicates the offenders Continuous values supplied to discrete scale. diff --git a/tests/testthat/test-scales.R b/tests/testthat/test-scales.R index d9286b513f..82f456fb42 100644 --- a/tests/testthat/test-scales.R +++ b/tests/testthat/test-scales.R @@ -469,59 +469,24 @@ test_that("numeric scale transforms can produce breaks", { scale$get_transformation()$inverse(view$get_breaks()) } - expect_equal(test_breaks("asn", limits = c(0, 1)), - seq(0, 1, by = 0.25)) - - expect_equal(test_breaks("sqrt", limits = c(0, 10)), - seq(0, 10, by = 2.5)) - - expect_equal(test_breaks("atanh", limits = c(-0.9, 0.9)), - c(NA, -0.5, 0, 0.5, NA)) - - expect_equal(test_breaks(transform_boxcox(0), limits = c(1, 10)), - c(NA, 2.5, 5.0, 7.5, 10)) - - expect_equal(test_breaks(transform_modulus(0), c(-10, 10)), - seq(-10, 10, by = 5)) - - expect_equal(test_breaks(transform_yj(0), c(-10, 10)), - seq(-10, 10, by = 5)) - - expect_equal(test_breaks("exp", c(-10, 10)), - seq(-10, 10, by = 5)) - - expect_equal(test_breaks("identity", limits = c(-10, 10)), - seq(-10, 10, by = 5)) - - # irrational numbers, so snapshot values + expect_snapshot(test_breaks("asn", limits = c(0, 1))) + expect_snapshot(test_breaks("sqrt", limits = c(0, 10))) + expect_snapshot(test_breaks("atanh", limits = c(-0.9, 0.9))) + expect_snapshot(test_breaks(transform_boxcox(0), limits = c(1, 10))) + expect_snapshot(test_breaks(transform_modulus(0), c(-10, 10))) + expect_snapshot(test_breaks(transform_yj(0), c(-10, 10))) + expect_snapshot(test_breaks("exp", c(-10, 10))) + expect_snapshot(test_breaks("identity", limits = c(-10, 10))) expect_snapshot(test_breaks("log", limits = c(0.1, 1000))) - - expect_equal(test_breaks("log10", limits = c(0.1, 1000)), - 10 ^ seq(-1, 3)) - - expect_equal(test_breaks("log2", limits = c(0.5, 32)), - c(0.5, 2, 8, 32)) - - expect_equal(test_breaks("log1p", limits = c(0, 10)), - seq(0, 10, by = 2.5)) - - expect_equal(test_breaks("pseudo_log", limits = c(-10, 10)), - seq(-10, 10, by = 5)) - - expect_equal(test_breaks("logit", limits = c(0.001, 0.999)), - c(NA, 0.25, 0.5, 0.75, NA)) - - expect_equal(test_breaks("probit", limits = c(0.001, 0.999)), - c(NA, 0.25, 0.5, 0.75, NA)) - - expect_equal(test_breaks("reciprocal", limits = c(1, 10)), - c(NA, 2.5, 5, 7.5, 10)) - - expect_equal(test_breaks("reverse", limits = c(-10, 10)), - seq(-10, 10, by = 5)) - - expect_equal(test_breaks("sqrt", limits = c(0, 10)), - seq(0, 10, by = 2.5)) + expect_snapshot(test_breaks("log10", limits = c(0.1, 1000))) + expect_snapshot(test_breaks("log2", limits = c(0.5, 32))) + expect_snapshot(test_breaks("log1p", limits = c(0, 10))) + expect_snapshot(test_breaks("pseudo_log", limits = c(-10, 10))) + expect_snapshot(test_breaks("logit", limits = c(0.001, 0.999))) + expect_snapshot(test_breaks("probit", limits = c(0.001, 0.999))) + expect_snapshot(test_breaks("reciprocal", limits = c(1, 10))) + expect_snapshot(test_breaks("reverse", limits = c(-10, 10))) + expect_snapshot(test_breaks("sqrt", limits = c(0, 10))) }) test_that("scale functions accurately report their calls", {