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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
test_that(
"test is_false with a logical input returns true when false",
{
x <- c(TRUE, FALSE, NA)
expected <- c(FALSE, TRUE, FALSE)
actual <- assertive.base::is_false(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("true", "", "missing")))
}
)
test_that(
"test is_na with a logical input returns true when NA",
{
x <- c(TRUE, FALSE, NA)
expected <- c(FALSE, FALSE, TRUE)
actual <- is_na(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("true", "false", "")))
}
)
test_that(
"test is_na with a character input and no coercion returns true when not NA",
{
x <- c("T", "F", "0", "1", "a", "NA", NA)
expected <- rep.int(c(FALSE, TRUE), c(6, 1))
actual <- is_na(x, coerce_to_logical = FALSE)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(
cause(actual),
noquote(rep.int(c("not missing", ""), c(6, 1)))
)
}
)
test_that(
"test is_na with a character input and coercion returns true when not 'T' or 'F'",
{
x <- c("T", "F", "0", "1", "a", "NA", NA)
expected <- rep.int(c(FALSE, TRUE), c(2, 5))
expect_warning(
actual <- is_na(x, coerce_to_logical = TRUE),
"Coercing x to class ‘logical’."
)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(
cause(actual),
noquote(rep.int(c("true", "false", ""), c(1, 1, 5)))
)
}
)
test_that(
"test is_na with a complex input and no coercion returns true when not NA",
{
x <- c(0, 1, 1i, 1 + 1i, NA)
expected <- rep.int(c(FALSE, TRUE), c(4, 1))
actual <- is_na(x, coerce_to_logical = FALSE)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(
cause(actual),
noquote(rep.int(c("not missing", ""), c(4, 1)))
)
}
)
test_that(
"test is_na with a complex input and coercion returns true when not NA",
{
x <- c(0, 1, 1i, 1 + 1i, NA)
expected <- rep.int(c(FALSE, TRUE), c(4, 1))
expect_warning(
actual <- is_na(x, coerce_to_logical = TRUE),
"Coercing x to class ‘logical’."
)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(
cause(actual),
noquote(rep.int(c("false", "true", ""), c(1, 3, 1)))
)
}
)
test_that(
"test is_na with a list input and no coercion returns true when elements contain a single NA",
{
x <- list(NA, TRUE, FALSE, c(TRUE, FALSE, NA))
expected <- rep.int(c(TRUE, FALSE), c(1, 3))
actual <- is_na(x, coerce_to_logical = FALSE)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(
cause(actual),
noquote(rep.int(c("", "not missing"), c(1, 3)))
)
}
)
test_that(
"test is_na with a list input and coercion throw an error",
{
x <- list(NA, TRUE, FALSE, c(TRUE, FALSE, NA))
expect_error(
is_na(x, coerce_to_logical = TRUE),
"x cannot be coerced to any of these types: ‘logical’."
)
}
)
test_that(
"test is_not_false with a logical input returns true when not false",
{
x <- c(TRUE, FALSE, NA)
expected <- c(TRUE, FALSE, TRUE)
actual <- is_not_false(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("", "false", "")))
}
)
test_that(
"test is_not_na with a logical input returns true when not NA",
{
x <- c(TRUE, FALSE, NA)
expected <- c(TRUE, TRUE, FALSE)
actual <- is_not_na(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("", "", "missing")))
}
)
test_that(
"test is_not_true with a logical input returns true when not true",
{
x <- c(TRUE, FALSE, NA)
expected <- c(FALSE, TRUE, TRUE)
actual <- is_not_true(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("true", "", "")))
}
)
test_that(
"test is_true with a logical input returns true when true",
{
x <- c(TRUE, FALSE, NA)
expected <- c(TRUE, FALSE, FALSE)
actual <- assertive.base::is_true(x)
expect_equal(strip_attributes(actual), expected)
expect_named(actual)
expect_equal(cause(actual), noquote(c("", "false", "missing")))
}
)
|