Expectation predicate for testing that the named sets of two vectors are equal
expect_mapequal(
current,
target,
...,
info = NA_character_,
tolerance = sqrt(x = .Machine$double.eps)
)[R vector] A vector to be tested
[R vector] A vector to be compared against
Ignored
[character(1L)] Optional user-defined message; must be a
single string value
[numeric] Test equality to machine rounding; passed
to all.equal()
A tinytest object. A tinytest object is a
logical with attributes holding information about the
test that was run
testthat equivalent:
testthat::expect_mapequal()
Other in-condition expectation predicates:
expect_contains(),
expect_in(),
expect_setequal()
(x <- `names<-`(letters, letters))
#> a b c d e f g h i j k l m n o p q r s t
#> "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t"
#> u v w x y z
#> "u" "v" "w" "x" "y" "z"
expect_mapequal(x, target = rev(x)) # Pass
#> ----- PASSED : <-->
#> call| expect_mapequal(x, target = rev(x))
expect_mapequal(letters, target = c(b = "b")) # Fail
#> ----- FAILED[xcpt]: <-->
#> call| expect_mapequal(letters, target = c(b = "b"))
#> diff| Both 'current' and 'target' must be named
expect_mapequal(c(b = "b"), target = x) # Fail
#> ----- FAILED[xcpt]: <-->
#> call| expect_mapequal(c(b = "b"), target = x)
#> diff| Expected names to be identical between 'current' and 'target', observed names in 'target' not present in 'current'