File: test_checkInt.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 (43 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (4)
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
39
40
41
42
43
context("checkInt")

test_that("checkInt", {
  myobj = 1L
  expect_succ_all(Int, myobj)
  myobj = 1.1
  expect_fail_all(Int, myobj)

  expect_false(testInt(integer(0)))
  expect_false(testInt(NULL))
  expect_false(testInt(FALSE))
  expect_false(testInt(TRUE))

  expect_true(testInt(1L))
  expect_true(testInt(1.))
  expect_false(testInt(NA))
  expect_true(testInt(NA_real_, na.ok = TRUE))
  expect_false(testInt(1:2))
  expect_false(testInt(""))

  expect_false(is.integer(assertInt(5)))
  expect_true(is.integer(assertInt(5, coerce = TRUE)))

  expect_error(assertInt(2+3i), "integerish")
})


test_that("bounds of vectors with only missings are not checked", {
  expect_true(checkInt(NA, na.ok = TRUE, lower = 1))
  expect_true(checkInt(NA_character_, na.ok = TRUE, upper = 10))
  expect_fail_all(Int, 0L, lower = 1L)
  expect_fail_all(Int, 100L, upper = 10L)
})

test_that("Coercion works", {
  expect_identical(assertInt(2, coerce = TRUE), 2L)
  expect_error(assertInt("lkajsd"), "single integerish")
  expect_error(assertInt("lkajsd"), "not 'character'")

  # check that names are not dropped (#157)
  x = c("a" = 1)
  expect_identical(assertInt(x, coerce = TRUE), setNames(1L, "a"))
})