Description Usage Arguments Details Examples
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.
1 | assertThat(actual, matcher)
|
actual |
object to be matched |
matcher |
one of the matcher functions, see 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.
assertThat(actual, equalTo(expected))
checks that actual
is equal to (using the ==
comparison operator) expected
. The
equalTo()
matcher function can therefore also be used to compare
strings.
assertThat(actual, closeTo(expected, delta))
checks that
actual
is close to expected
with a maximum allowed
difference of delta
.
assertThat(actual, identicalTo(expected))
checks if
actual
is identical to (using the identical
function) expected
.
assertThat(actual, isTrue())
and its shorthand
assertTrue(value)
check that actual
or value
is
identical to TRUE
(i.e. the logical vector or length 1). This is the
same as assertThat(actual, identicalTo(TRUE))
. Use
assertThat(actual, isFalse())
or assertFalse(value)
to check if
actual
or value
are FALSE
.
assertThat(actual, instanceOf(expected))
checks if actual
has class (using the inherits
function) expected
.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.