File: test-scalar.R

package info (click to toggle)
r-cran-assertthat 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 220 kB
  • sloc: sh: 9; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
context("Scalar assertions")

test_that("is.scalar works correctly", {
  expect_true(is.scalar(1))
  expect_true(is.scalar(-1))
  expect_true(is.scalar(1.5))
  expect_false(is.scalar(1:5))
  expect_true(is.scalar('a'))
  expect_false(is.scalar(c('a', 'b')))
  expect_true(is.scalar(TRUE))
  expect_false(is.scalar(c(TRUE, FALSE)))
  expect_false(is.scalar(NULL))
  expect_true(is.scalar(NA))
  expect_true(is.scalar(Inf))
  expect_true(is.scalar(-Inf))
})

test_that("is.string works correctly", {
  expect_false(is.string(1))
  expect_true(is.string('a'))
  expect_false(is.string(c('a', 'b')))
  expect_false(is.string(TRUE))
  expect_false(is.string(NULL))
  expect_false(is.string(NA))
  expect_false(is.string(Inf))
  expect_false(is.string(-Inf))
})

test_that("is.number works correctly", {
  expect_true(is.number(1))
  expect_true(is.number(-1))
  expect_true(is.number(1.5))
  expect_false(is.number(1:5))
  expect_false(is.number('a'))
  expect_false(is.number(TRUE))
  expect_false(is.number(NULL))
  expect_false(is.number(NA))
  expect_true(is.number(Inf))
  expect_true(is.number(-Inf))
})

test_that("is.flag works correctly", {
  expect_false(is.flag(1))
  expect_false(is.flag('a'))
  expect_true(is.flag(TRUE))
  expect_true(is.flag(FALSE))
  expect_false(is.flag(c(TRUE, FALSE)))
  expect_false(is.flag(NULL))
  expect_equal(is.flag(NA), is.logical(NA)) # not obvious
  expect_false(is.flag(Inf))
  expect_false(is.flag(-Inf))
})

test_that("is.count works correctly", {
  expect_true(is.count(1))
  expect_false(is.count(-1))
  expect_false(is.count(1.5))
  expect_false(is.count(1:5))
  expect_false(is.count('a'))
  expect_false(is.count(TRUE))
  expect_false(is.count(NULL))
  expect_false(is.count(NA))
  expect_false(is.count(NA_real_))
  expect_false(is.count(NA_integer_))
  expect_false(is.count(NaN))
  expect_true(is.count(Inf))
  expect_false(is.count(-Inf))
  expect_false(is.count(1e10 + 0.0001))
  expect_false(is.count(1e10 - 0.1))
})