assertThat: Make a test assertion

Description Usage Arguments Details Examples

View source: R/hamcrest.R

Description

Use the assertThat() function to write your unit test. The first argument is the result you want to test and the second argument is the matcher that embodies the rule against which you want to test the result.

Usage

1
assertThat(actual, matcher)

Arguments

actual

object to be matched

matcher

one of the matcher functions, see Details

Details

The second argument matcher of assertThat should be a matcher function. Matcher function returns a function which references the expected value. The actual value is passed to the resulting matcher function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
assertThat(-0.50557992900139, closeTo(-0.50557, delta = 1e4))
assertThat(floor(-1.5), identicalTo(-2))
assertThat(qnorm(0, 0, 1,  TRUE,  FALSE), equalTo(-Inf))
assertThat(is.integer(1L), isTrue())
assertThat(is.character(seq(10)), isFalse())
assertThat(log("a"), throwsError())
assertThat(any(range(2.0,3.0)), emitsWarning())
assertThat(1, not(identicalTo(2)))

## End(Not run)

bedatadriven/hamcrest documentation built on Dec. 1, 2019, 1:49 p.m.