logical-expectations

0th

Percentile

Expectation: is the object true/false?

These are fall-back expectations that you can use when none of the other more specific expectations apply. The disadvantage is that you may get a less informative error message.

Usage
expect_true(object, info = NULL, label = NULL)

expect_false(object, info = NULL, label = NULL)

Arguments
object

object to test

info

extra information to be included in the message (useful when writing tests in loops).

label

object label. When NULL, computed from deparsed object.

Details

Attributes are ignored.

See Also

is_false() for complement

Other expectations: comparison-expectations, equality-expectations, expect_length, expect_match, expect_named, inheritance-expectations, output-expectations

Aliases
  • logical-expectations
  • expect_true
  • expect_false
Examples
# NOT RUN {
expect_true(2 == 2)
# Failed expectations will throw an error
# }
# NOT RUN {
expect_true(2 != 2)
# }
# NOT RUN {
expect_true(!(2 != 2))
# or better:
expect_false(2 != 2)

a <- 1:3
expect_true(length(a) == 3)
# but better to use more specific expectation, if available
expect_equal(length(a), 3)
# }
Documentation reproduced from package testthat, version 2.0.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.