Skip to content

Commit d305501

Browse files
committed
Check zero case and fix bug thus revealed
1 parent 3e9839c commit d305501

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

R/expect-comparison.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ expect_compare_ <- function(
4242
abort("Result of comparison must be a single logical value")
4343
}
4444
if (!isTRUE(cmp)) {
45-
digits <- min_digits(act$val, exp$val)
45+
digits <- max(
46+
digits(act$val),
47+
digits(exp$val),
48+
min_digits(act$val, exp$val)
49+
)
4650
msg <- sprintf(
4751
"%s is %s %s.\n%s - %s = %s %s 0",
4852
act$lab,

tests/testthat/_snaps/expect-comparison.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
`x` is not strictly greater than 1.1 * x.
99
0.0000100 - 0.0000110 = -0.0000010 <= 0
1010

11+
---
12+
13+
`x` is not strictly less than `x`.
14+
100.0 - 100.0 = 0.0 >= 0
15+

tests/testthat/test-expect-comparison.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ test_that("useful output when numbers are very small", {
1212
x <- 1e-5
1313
expect_snapshot_failure(expect_lte(1.1 * x, x))
1414
expect_snapshot_failure(expect_gt(x, 1.1 * x))
15+
16+
x <- 100
17+
expect_snapshot_failure(expect_lt(x, x))
1518
})
1619

1720
test_that("comparison result object invisibly", {

0 commit comments

Comments
 (0)