| expect_all_equal {testthat} | R Documentation |
Do you expect every value in a vector to have this value?
Description
These expectations are similar to expect_true(all(x == "x")),
expect_true(all(x)) and expect_true(all(!x)) but give more informative
failure messages if the expectations are not met.
Usage
expect_all_equal(object, expected)
expect_all_true(object)
expect_all_false(object)
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. |
Examples
x1 <- c(1, 1, 1, 1, 1, 1)
expect_all_equal(x1, 1)
x2 <- c(1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2)
show_failure(expect_all_equal(x2, 1))
# expect_all_true() and expect_all_false() are helpers for common cases
set.seed(1016)
show_failure(expect_all_true(rpois(100, 10) < 20))
show_failure(expect_all_false(rpois(100, 10) > 20))
[Package testthat version 3.3.2 Index]