Skip to content

Commit eefffe1

Browse files
committed
Test: Handle missing values in modifications
1 parent f676b77 commit eefffe1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/testthat/test-manip.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ codes_native <- encode_native(codes)
1414
codes_native_alpha <- encode_native(codes_alpha)
1515

1616

17+
test_that("setting channel sets colour to NA if modification value is NA", {
18+
cols_mod[, 'g'] <- 1:10
19+
expected <- encode_colour(cols_mod)
20+
expected[2] <- NA
21+
expect_equal(set_channel(codes, 'g', c(1L, NA, 3:10)), expected)
22+
})
23+
24+
test_that("setting channel leaves colour as it was if modification value is NA and skip_na_values is TRUE", {
25+
cols_mod[, 'g'] <- 1:10
26+
expected <- encode_colour(cols_mod)
27+
expected[2] <- codes[2]
28+
expect_equal(set_channel(codes, 'g', c(1L, NA, 3:10), skip_na_values = TRUE), expected)
29+
})
30+
31+
1732
test_that("setting channel works", {
1833
cols_mod[, 'g'] <- 1:10
1934
expect_equal(set_channel(codes, 'g', 1:10), encode_colour(cols_mod))
@@ -77,6 +92,22 @@ test_that("setting channel native works", {
7792
expect_equal(set_channel_native(codes_native, 'alpha', (1:10)/10), encode_native(cols, alpha = (1:10)/10))
7893
})
7994

95+
96+
test_that("setting channel native sets colour to NA if modification value is NA", {
97+
cols_mod[, 'g'] <- 1:10
98+
expected <- encode_native(cols_mod)
99+
expected[2] <- NA
100+
expect_equal(set_channel_native(codes_native, 'g', c(1L, NA, 3:10)), expected)
101+
})
102+
103+
test_that("setting channel native leaves colour as it was if modification value is NA and skip_na_values is TRUE", {
104+
cols_mod[, 'g'] <- 1:10
105+
expected <- encode_native(cols_mod)
106+
expected[2] <- codes_native[2]
107+
expect_equal(set_channel_native(codes_native, 'g', c(1L, NA, 3:10), skip_na_values = TRUE), expected)
108+
})
109+
110+
80111
test_that("adding channel works", {
81112
cols_mod[, 'r'] <- cols_mod[, 'r'] + 1:10
82113
expect_equal(add_to_channel_native(codes_native, 'r', 1:10), encode_native(cols_mod))

0 commit comments

Comments
 (0)