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)
)

Arguments

current

[R vector] A vector to be tested

target

[R vector] A vector to be compared against

...

Ignored

info

[character(1L)] Optional user-defined message; must be a single string value

tolerance

[numeric] Test equality to machine rounding; passed to all.equal()

Value

A tinytest object. A tinytest object is a logical with attributes holding information about the test that was run

See also

testthat equivalent: testthat::expect_mapequal()

Other in-condition expectation predicates: expect_contains(), expect_in(), expect_setequal()

Examples

(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'