File: test_AssertCollection.R

package info (click to toggle)
r-cran-checkmate 2.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: ansic: 2,211; sh: 9; makefile: 8
file content (38 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
context("AssertCollection")

test_that("Collection closure wors", {
  coll = makeAssertCollection()
  expect_is(coll, "AssertCollection")
  expect_output(print(coll), "Empty collection")
  expect_equal(coll$getMessages(), character(0L))
  expect_true(coll$isEmpty())
  coll$push("testing")
  expect_equal(coll$getMessages(), "testing")
  expect_false(coll$isEmpty())
  expect_output(print(coll), "Collection of 1 assertion")
  coll$push("foo")
  expect_output(print(coll), "Collection of 2 assertions")
  expect_equal(coll$getMessages(), c("testing", "foo"))
})

test_that("Reporter works", {
  coll = makeAssertCollection()
  expect_true(reportAssertions(coll))
  coll$push("foo")
  coll$push("bar")
  expect_error(reportAssertions(coll), "foo")
  expect_error(reportAssertions(coll), "bar")
})

test_that("asserts push to collection", {
  coll = makeAssertCollection()
  findme = "a"

  assertString(findme, add = coll)
  expect_true(coll$isEmpty())
  expect_true(reportAssertions(coll))

  assertNumeric(findme, add = coll)
  expect_false(coll$isEmpty())
  expect_error(reportAssertions(coll), "findme")
})