logical-expectations: Expectation: is the object true/false?

Description Usage Arguments Details See Also Examples

Description

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

1
2
3
expect_true(object, info = NULL, label = NULL)

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

Arguments

object

Object to test.

Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.

info

Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in quasi_label.

label

Used to customise failure messages. For expert use only.

Details

Attributes are ignored.

See Also

is_false() for complement

Other expectations: comparison-expectations, equality-expectations, expect_error, expect_length, expect_match, expect_message, expect_named, expect_null, expect_output, expect_silent, inheritance-expectations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
expect_true(2 == 2)
# Failed expectations will throw an error
## Not run: 
expect_true(2 != 2)

## End(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)

testthat documentation built on Dec. 1, 2019, 5:06 p.m.