-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve expect_setequal() feedback #1745
Conversation
R/expect-setequal.R
Outdated
if (any(exp_miss)) | ||
paste0("* Missing from expected: ", strings(act$val[act_miss]), "\n"), | ||
if (any(act_miss)) | ||
paste0("* Missing from actual: ", strings(exp$val[exp_miss]), "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you feel about framing this as Only in expected:
instead of Missing from expected:
?
I have trouble reading this example:
x <- c("a", "b")
y <- c("b", "c")
expect_snapshot_failure(expect_setequal(x, y))
#> `x` and `y` don't have the same values
#> * Missing from expected: "a"
#> * Missing from actual: "c"
and I think it is because my brain is juggling too many things. I have to realize that y
is "expected" but then look over at x
to see that it did indeed have "a"
which isn't in y
.
This makes more sense to me
x <- c("a", "b")
y <- c("b", "c")
expect_snapshot_failure(expect_setequal(x, y))
#> `x` (`actual`) and `y` (`expected`) don't have the same values
#> * Only in `actual`: "a"
#> * Only in `expected`: "c"
I also like seeing `x` (`actual`)
because I can't ever remember which is which. It is also what expect_equal()
and expect_identical()
seem to do
> testthat::expect_identical(1, 1.5)
Error: 1 (`actual`) not identical to 1.5 (`expected`).
`actual`: 1.0
`expected`: 1.5
> testthat::expect_equal(1, 1.5)
Error: 1 (`actual`) not equal to 1.5 (`expected`).
`actual`: 1.0
`expected`: 1.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
R/expect-setequal.R
Outdated
loc <- which(i) | ||
if (length(loc) == 1) { | ||
return(loc) | ||
strings <- function(x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use expect_setequal()
on more than strings though? How does this look on numeric values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yes.
Fixes #1657