-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
221 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
context("catColorPal") | ||
|
||
describe("catColorPal", { | ||
|
||
it("returns a vector of colors with attributes levels and pal", { | ||
x <- as.factor(c("a", "b", "c", "a")) | ||
res <- catColorPal(x) | ||
expect_true(all(res == DEFAULT_CAT_COLORS[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), levels(x)) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = levels(x))) | ||
}) | ||
|
||
it ("accepts character vectors", { | ||
x <- c("a", "b", "c", "a") | ||
res <- catColorPal(x) | ||
expect_true(all(res == DEFAULT_CAT_COLORS[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), unique(x)) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = unique(x))) | ||
}) | ||
|
||
it("accepts custom colors", { | ||
x <- as.factor(c("a", "b", "c", "a")) | ||
pal <- c("red", "green", "blue") | ||
res <- catColorPal(x, colors = pal) | ||
expect_true(all(res == pal[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), levels(x)) | ||
expect_equal(attr(res, "pal"), structure(pal, names = levels(x))) | ||
}) | ||
|
||
it("handles missing values", { | ||
x <- as.factor(c("a", "b", "c", "a", NA)) | ||
res <- catColorPal(x) | ||
expect_true(all(res == c(DEFAULT_CAT_COLORS[c(1,2,3,1)], "#EEEEEE"))) | ||
}) | ||
|
||
it("can reset levels", { | ||
x <- as.factor(c("a", "b", "a", "c")) | ||
res <- catColorPal(x, levels = c("a", "b", "d")) | ||
expect_true(all(res == c(DEFAULT_CAT_COLORS[c(1,2,1)], "#EEEEEE"))) | ||
expect_equal(attr(res, "levels"), c("a", "b", "d")) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = c("a", "b", "d"))) | ||
}) | ||
test_that("returns a vector of colors with attributes levels and pal", { | ||
x <- as.factor(c("a", "b", "c", "a")) | ||
res <- catColorPal(x) | ||
expect_true(all(res == DEFAULT_CAT_COLORS[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), levels(x)) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = levels(x))) | ||
}) | ||
|
||
test_that("accepts character vectors", { | ||
x <- c("a", "b", "c", "a") | ||
res <- catColorPal(x) | ||
expect_true(all(res == DEFAULT_CAT_COLORS[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), unique(x)) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = unique(x))) | ||
}) | ||
|
||
test_that("accepts custom colors", { | ||
x <- as.factor(c("a", "b", "c", "a")) | ||
pal <- c("red", "green", "blue") | ||
res <- catColorPal(x, colors = pal) | ||
expect_true(all(res == pal[c(1,2,3,1)])) | ||
expect_equal(attr(res, "levels"), levels(x)) | ||
expect_equal(attr(res, "pal"), structure(pal, names = levels(x))) | ||
}) | ||
|
||
test_that("handles missing values", { | ||
x <- as.factor(c("a", "b", "c", "a", NA)) | ||
res <- catColorPal(x) | ||
expect_true(all(res == c(DEFAULT_CAT_COLORS[c(1,2,3,1)], "#EEEEEE"))) | ||
}) | ||
|
||
test_that("can reset levels", { | ||
x <- as.factor(c("a", "b", "a", "c")) | ||
res <- catColorPal(x, levels = c("a", "b", "d")) | ||
expect_true(all(res == c(DEFAULT_CAT_COLORS[c(1,2,1)], "#EEEEEE"))) | ||
expect_equal(attr(res, "levels"), c("a", "b", "d")) | ||
expect_equal(attr(res, "pal"), structure(DEFAULT_CAT_COLORS[1:3], names = c("a", "b", "d"))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,67 @@ | ||
context("Continuous Color Scale") | ||
|
||
describe("continuousColorPal()", { | ||
# Default colors | ||
posCol <- "#0000FF" | ||
zeroCol <- "#FFFFFF" | ||
negCol <- "#FF0000" | ||
# Custom colors | ||
custZeroCol <- "#FF0000" | ||
custPosCol <- "#00FF00" | ||
|
||
it ("returns a vector of colors with break points and color palette", { | ||
cols <- continuousColorPal(1:100) | ||
expect_is(cols, "character") | ||
expect_true(all(grepl("^#[0-9A-F]{6}", cols))) | ||
expect_false(is.null(attr(cols, "breaks"))) | ||
expect_false(is.null(attr(cols, "pal"))) | ||
}) | ||
|
||
it ("works with positive values", { | ||
cols <- continuousColorPal(1:100) | ||
expect_equal(cols[1], zeroCol) | ||
expect_equal(cols[100], posCol) | ||
}) | ||
|
||
it ("works with negative values", { | ||
cols <- continuousColorPal(-1:-100) | ||
expect_equal(cols[1], zeroCol) | ||
expect_equal(cols[100], negCol) | ||
}) | ||
|
||
it ("works with positive and negative values", { | ||
cols <- continuousColorPal(-100:100) | ||
expect_equal(cols[1], negCol) | ||
expect_equal(cols[101], zeroCol) | ||
expect_equal(cols[201], posCol) | ||
}) | ||
|
||
it ("modifies the number of break points", { | ||
cols1 <- continuousColorPal(1:100, 3) | ||
cols2 <- continuousColorPal(1:100, 10) | ||
expect_gt(length(unique(cols2)), length(unique(cols1))) | ||
}) | ||
|
||
it ("accepts custom domains", { | ||
cols <- continuousColorPal(1:100, domain = c(0, 1000)) | ||
expect_equal(max(attr(cols, "breaks")), 1000) | ||
expect_false(cols[100] == posCol) | ||
}) | ||
|
||
it ("accepts custom break points", { | ||
cols <- continuousColorPal(1:100, breaks = c(0, 80, 100)) | ||
expect_true(all(cols[1:80] == zeroCol)) | ||
expect_true(all(cols[81:100] == posCol)) | ||
}) | ||
|
||
it ("accepts custom colors if custom break points", { | ||
cols <- continuousColorPal(1:100, breaks = c(0, 80, 100), | ||
colors = c(custZeroCol, custPosCol)) | ||
expect_true(all(cols[1:80] == custZeroCol)) | ||
expect_true(all(cols[81:100] == custPosCol)) | ||
}) | ||
|
||
it ("ignores custom colors if automatic break points", { | ||
cols <- continuousColorPal(1:100, colors = c(custZeroCol, custPosCol)) | ||
expect_true(all(cols[1] == zeroCol)) | ||
expect_true(all(cols[100] == posCol)) | ||
}) | ||
# Default colors | ||
posCol <- "#0000FF" | ||
zeroCol <- "#FFFFFF" | ||
negCol <- "#FF0000" | ||
# Custom colors | ||
custZeroCol <- "#FF0000" | ||
custPosCol <- "#00FF00" | ||
|
||
test_that("returns a vector of colors with break points and color palette", { | ||
cols <- continuousColorPal(1:100) | ||
expect_is(cols, "character") | ||
expect_true(all(grepl("^#[0-9A-F]{6}", cols))) | ||
expect_false(is.null(attr(cols, "breaks"))) | ||
expect_false(is.null(attr(cols, "pal"))) | ||
}) | ||
|
||
test_that("works with positive values", { | ||
cols <- continuousColorPal(1:100) | ||
expect_equal(cols[1], zeroCol) | ||
expect_equal(cols[100], posCol) | ||
}) | ||
|
||
test_that("works with negative values", { | ||
cols <- continuousColorPal(-1:-100) | ||
expect_equal(cols[1], zeroCol) | ||
expect_equal(cols[100], negCol) | ||
}) | ||
|
||
test_that("works with positive and negative values", { | ||
cols <- continuousColorPal(-100:100) | ||
expect_equal(cols[1], negCol) | ||
expect_equal(cols[101], zeroCol) | ||
expect_equal(cols[201], posCol) | ||
}) | ||
|
||
test_that("modifies the number of break points", { | ||
cols1 <- continuousColorPal(1:100, 3) | ||
cols2 <- continuousColorPal(1:100, 10) | ||
expect_gt(length(unique(cols2)), length(unique(cols1))) | ||
}) | ||
|
||
test_that("accepts custom domains", { | ||
cols <- continuousColorPal(1:100, domain = c(0, 1000)) | ||
expect_equal(max(attr(cols, "breaks")), 1000) | ||
expect_false(cols[100] == posCol) | ||
}) | ||
|
||
test_that("accepts custom break points", { | ||
cols <- continuousColorPal(1:100, breaks = c(0, 80, 100)) | ||
expect_true(all(cols[1:80] == zeroCol)) | ||
expect_true(all(cols[81:100] == posCol)) | ||
}) | ||
|
||
test_that("accepts custom colors if custom break points", { | ||
cols <- continuousColorPal(1:100, breaks = c(0, 80, 100), | ||
colors = c(custZeroCol, custPosCol)) | ||
expect_true(all(cols[1:80] == custZeroCol)) | ||
expect_true(all(cols[81:100] == custPosCol)) | ||
}) | ||
|
||
test_that("ignores custom colors if automatic break points", { | ||
cols <- continuousColorPal(1:100, colors = c(custZeroCol, custPosCol)) | ||
expect_true(all(cols[1] == zeroCol)) | ||
expect_true(all(cols[100] == posCol)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.