expect_setequal(x, y)tests that every element ofxoccurs iny, and that every element ofyoccurs inx.expect_contains(x, y)tests thatxcontains every element ofy(i.e.yis a subset ofx).expect_in(x, y)tests that every element ofxis iny(i.e.xis a subset ofy).expect_disjoint(x, y)tests that no element ofxis iny(i.e.xis disjoint fromy).expect_mapequal(x, y)treats lists as if they are mappings between names and values. Concretely, checks thatxandyhave the same names, then checks thatx[names(y)]equalsy.
Usage
expect_setequal(object, expected)
expect_mapequal(object, expected)
expect_contains(object, expected)
expect_in(object, expected)
expect_disjoint(object, expected)Arguments
- object, expected
Computation and value to compare it to.
Both arguments supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.
Details
Note that expect_setequal() ignores names, and you will be warned if both
object and expected have them.
Examples
expect_setequal(letters, rev(letters))
show_failure(expect_setequal(letters[-1], rev(letters)))
#> Failed expectation:
#> Expected `letters[-1]` to have the same values as `rev(letters)`.
#> Actual: "b", "c", "d", "e", "f", "g", "h", "i", "j", ...
#> Expected: "z", "y", "x", "w", "v", "u", "t", "s", "r", ...
#> Absent: "a"
x <- list(b = 2, a = 1)
expect_mapequal(x, list(a = 1, b = 2))
show_failure(expect_mapequal(x, list(a = 1)))
#> Failed expectation:
#> Expected `x` to have the same names as `list(a = 1)`.
#> Actual: "b", "a"
#> Expected: "a"
#> Needs: "b"
show_failure(expect_mapequal(x, list(a = 1, b = "x")))
#> Failed expectation:
#> Expected `x` to contain the same values as `list(a = 1, b = "x")`.
#> Differences:
#> `actual$b` is a double vector (2)
#> `expected$b` is a character vector ('x')
#>
show_failure(expect_mapequal(x, list(a = 1, b = 2, c = 3)))
#> Failed expectation:
#> Expected `x` to have the same names as `list(a = 1, b = 2, c = 3)`.
#> Actual: "b", "a"
#> Expected: "a", "b", "c"
#> Absent: "c"
