Skip to content

Commit dbbcd43

Browse files
authored
Add unit tests for mapped_discrete vector class (#4010)
1 parent f802c5e commit dbbcd43

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/testthat/test-scale-discrete.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ test_that("discrete non-position scales can accept functional limits", {
8888
expect_identical(scale$get_limits(), c("c", "b", "a"))
8989
})
9090

91-
9291
test_that("discrete scale defaults can be set globally", {
9392
df <- data_frame(
9493
x = 1:4, y = 1:4,
@@ -127,5 +126,19 @@ test_that("discrete scale defaults can be set globally", {
127126
expect_equal(layer_data(four)$colour, c("#FF0000", "#00FF00", "#0000FF", "#FF00FF"))
128127
expect_equal(layer_data(four)$fill, c("#FF0000", "#00FF00", "#0000FF", "#FF00FF"))
129128
})
129+
})
130+
131+
# mapped_discrete ---------------------------------------------------------
132+
133+
test_that("mapped_discrete vectors behaves as predicted", {
134+
expect_null(new_mapped_discrete(NULL))
135+
expect_s3_class(new_mapped_discrete(c(0, 3.5)), "mapped_discrete")
136+
expect_s3_class(new_mapped_discrete(seq_len(4)), "mapped_discrete")
137+
expect_error(new_mapped_discrete(letters))
130138

139+
x <- new_mapped_discrete(1:10)
140+
expect_s3_class(x[2:4], "mapped_discrete")
141+
expect_s3_class(c(x, x), "mapped_discrete")
142+
x[5:7] <- new_mapped_discrete(seq_len(3))
143+
expect_s3_class(x, "mapped_discrete")
131144
})

0 commit comments

Comments
 (0)