Skip to content

Commit 80cab65

Browse files
committed
fix failure messages for comparisons of negative numbers
1 parent eec4dc4 commit 80cab65

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

R/expect-comparison.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ digits <- function(x) {
194194
if (length(x) == 0) {
195195
return(0)
196196
}
197-
scale <- -log10(min(x))
197+
scale <- -log10(min(abs(x)))
198198
if (scale <= 0) {
199199
0L
200200
} else {

tests/testthat/_snaps/expect-comparison.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
! Expected `x` < 10.
7777
Actual comparison: NA >= 10.0
7878

79+
# comparisons with negative numbers work
80+
81+
Code
82+
expect_gt(-5, -2)
83+
Condition
84+
Error:
85+
! Expected `-5` > `-2`.
86+
Actual comparison: -5.0 <= -2.0
87+
Difference: -3.0 <= 0
88+
7989
# comparisons with POSIXct objects work
8090

8191
Code

tests/testthat/test-expect-comparison.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ test_that("comparisons with NA work", {
5858
expect_snapshot_failure(expect_lt(x, 10))
5959
})
6060

61+
62+
test_that("comparisons with negative numbers work", {
63+
expect_success(expect_lt(-5, -2))
64+
expect_snapshot_failure(expect_gt(-5, -2))
65+
})
66+
6167
test_that("comparisons with POSIXct objects work", {
6268
time <- as.POSIXct("2020-01-01 01:00:00")
6369
time2 <- time + 1.5

0 commit comments

Comments
 (0)