Skip to content

Commit 8efc700

Browse files
authored
Use snapshot expectations for breaks (#6171)
1 parent ccda105 commit 8efc700

File tree

2 files changed

+136
-52
lines changed

2 files changed

+136
-52
lines changed

tests/testthat/_snaps/scales.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,130 @@
7272

7373
# numeric scale transforms can produce breaks
7474

75+
Code
76+
test_breaks("asn", limits = c(0, 1))
77+
Output
78+
[1] 0.00 0.25 0.50 0.75 1.00
79+
80+
---
81+
82+
Code
83+
test_breaks("sqrt", limits = c(0, 10))
84+
Output
85+
[1] 0.0 2.5 5.0 7.5 10.0
86+
87+
---
88+
89+
Code
90+
test_breaks("atanh", limits = c(-0.9, 0.9))
91+
Output
92+
[1] NA -0.5 0.0 0.5 NA
93+
94+
---
95+
96+
Code
97+
test_breaks(transform_boxcox(0), limits = c(1, 10))
98+
Output
99+
[1] NA 2.5 5.0 7.5 10.0
100+
101+
---
102+
103+
Code
104+
test_breaks(transform_modulus(0), c(-10, 10))
105+
Output
106+
[1] -10 -5 0 5 10
107+
108+
---
109+
110+
Code
111+
test_breaks(transform_yj(0), c(-10, 10))
112+
Output
113+
[1] -10 -5 0 5 10
114+
115+
---
116+
117+
Code
118+
test_breaks("exp", c(-10, 10))
119+
Output
120+
[1] -10 -5 0 5 10
121+
122+
---
123+
124+
Code
125+
test_breaks("identity", limits = c(-10, 10))
126+
Output
127+
[1] -10 -5 0 5 10
128+
129+
---
130+
75131
Code
76132
test_breaks("log", limits = c(0.1, 1000))
77133
Output
78134
[1] NA 1.00000 20.08554 403.42879
79135

136+
---
137+
138+
Code
139+
test_breaks("log10", limits = c(0.1, 1000))
140+
Output
141+
[1] 1e-01 1e+00 1e+01 1e+02 1e+03
142+
143+
---
144+
145+
Code
146+
test_breaks("log2", limits = c(0.5, 32))
147+
Output
148+
[1] 0.5 2.0 8.0 32.0
149+
150+
---
151+
152+
Code
153+
test_breaks("log1p", limits = c(0, 10))
154+
Output
155+
[1] 0.0 2.5 5.0 7.5 10.0
156+
157+
---
158+
159+
Code
160+
test_breaks("pseudo_log", limits = c(-10, 10))
161+
Output
162+
[1] -10 -5 0 5 10
163+
164+
---
165+
166+
Code
167+
test_breaks("logit", limits = c(0.001, 0.999))
168+
Output
169+
[1] NA 0.25 0.50 0.75 NA
170+
171+
---
172+
173+
Code
174+
test_breaks("probit", limits = c(0.001, 0.999))
175+
Output
176+
[1] NA 0.25 0.50 0.75 NA
177+
178+
---
179+
180+
Code
181+
test_breaks("reciprocal", limits = c(1, 10))
182+
Output
183+
[1] NA 2.5 5.0 7.5 10.0
184+
185+
---
186+
187+
Code
188+
test_breaks("reverse", limits = c(-10, 10))
189+
Output
190+
[1] -10 -5 0 5 10
191+
192+
---
193+
194+
Code
195+
test_breaks("sqrt", limits = c(0, 10))
196+
Output
197+
[1] 0.0 2.5 5.0 7.5 10.0
198+
80199
# training incorrectly appropriately communicates the offenders
81200

82201
Continuous values supplied to discrete scale.

tests/testthat/test-scales.R

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -469,59 +469,24 @@ test_that("numeric scale transforms can produce breaks", {
469469
scale$get_transformation()$inverse(view$get_breaks())
470470
}
471471

472-
expect_equal(test_breaks("asn", limits = c(0, 1)),
473-
seq(0, 1, by = 0.25))
474-
475-
expect_equal(test_breaks("sqrt", limits = c(0, 10)),
476-
seq(0, 10, by = 2.5))
477-
478-
expect_equal(test_breaks("atanh", limits = c(-0.9, 0.9)),
479-
c(NA, -0.5, 0, 0.5, NA))
480-
481-
expect_equal(test_breaks(transform_boxcox(0), limits = c(1, 10)),
482-
c(NA, 2.5, 5.0, 7.5, 10))
483-
484-
expect_equal(test_breaks(transform_modulus(0), c(-10, 10)),
485-
seq(-10, 10, by = 5))
486-
487-
expect_equal(test_breaks(transform_yj(0), c(-10, 10)),
488-
seq(-10, 10, by = 5))
489-
490-
expect_equal(test_breaks("exp", c(-10, 10)),
491-
seq(-10, 10, by = 5))
492-
493-
expect_equal(test_breaks("identity", limits = c(-10, 10)),
494-
seq(-10, 10, by = 5))
495-
496-
# irrational numbers, so snapshot values
472+
expect_snapshot(test_breaks("asn", limits = c(0, 1)))
473+
expect_snapshot(test_breaks("sqrt", limits = c(0, 10)))
474+
expect_snapshot(test_breaks("atanh", limits = c(-0.9, 0.9)))
475+
expect_snapshot(test_breaks(transform_boxcox(0), limits = c(1, 10)))
476+
expect_snapshot(test_breaks(transform_modulus(0), c(-10, 10)))
477+
expect_snapshot(test_breaks(transform_yj(0), c(-10, 10)))
478+
expect_snapshot(test_breaks("exp", c(-10, 10)))
479+
expect_snapshot(test_breaks("identity", limits = c(-10, 10)))
497480
expect_snapshot(test_breaks("log", limits = c(0.1, 1000)))
498-
499-
expect_equal(test_breaks("log10", limits = c(0.1, 1000)),
500-
10 ^ seq(-1, 3))
501-
502-
expect_equal(test_breaks("log2", limits = c(0.5, 32)),
503-
c(0.5, 2, 8, 32))
504-
505-
expect_equal(test_breaks("log1p", limits = c(0, 10)),
506-
seq(0, 10, by = 2.5))
507-
508-
expect_equal(test_breaks("pseudo_log", limits = c(-10, 10)),
509-
seq(-10, 10, by = 5))
510-
511-
expect_equal(test_breaks("logit", limits = c(0.001, 0.999)),
512-
c(NA, 0.25, 0.5, 0.75, NA))
513-
514-
expect_equal(test_breaks("probit", limits = c(0.001, 0.999)),
515-
c(NA, 0.25, 0.5, 0.75, NA))
516-
517-
expect_equal(test_breaks("reciprocal", limits = c(1, 10)),
518-
c(NA, 2.5, 5, 7.5, 10))
519-
520-
expect_equal(test_breaks("reverse", limits = c(-10, 10)),
521-
seq(-10, 10, by = 5))
522-
523-
expect_equal(test_breaks("sqrt", limits = c(0, 10)),
524-
seq(0, 10, by = 2.5))
481+
expect_snapshot(test_breaks("log10", limits = c(0.1, 1000)))
482+
expect_snapshot(test_breaks("log2", limits = c(0.5, 32)))
483+
expect_snapshot(test_breaks("log1p", limits = c(0, 10)))
484+
expect_snapshot(test_breaks("pseudo_log", limits = c(-10, 10)))
485+
expect_snapshot(test_breaks("logit", limits = c(0.001, 0.999)))
486+
expect_snapshot(test_breaks("probit", limits = c(0.001, 0.999)))
487+
expect_snapshot(test_breaks("reciprocal", limits = c(1, 10)))
488+
expect_snapshot(test_breaks("reverse", limits = c(-10, 10)))
489+
expect_snapshot(test_breaks("sqrt", limits = c(0, 10)))
525490
})
526491

527492
test_that("scale functions accurately report their calls", {

0 commit comments

Comments
 (0)