-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve package testing. Fix a bug in rule_fill_discrete.
- Loading branch information
Showing
11 changed files
with
153 additions
and
42 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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Tests: | ||
library(condformat) | ||
library(dplyr) | ||
library(testthat) | ||
context("rendering") | ||
|
||
test_that("print.condformat_tbl returns its input", { | ||
data(iris) | ||
x <- condformat(head(iris)) | ||
out <- print(x) | ||
expect_that(out,is_identical_to(x)) | ||
}) | ||
|
||
test_that("knitr returns an HTML table", { | ||
data(iris) | ||
library(knitr) | ||
out <- knit_print(condformat(head(iris))) | ||
expect_that(out, matches("^<table.*</table>$")) | ||
}) | ||
|
||
|
||
test_that("merge_css_conditions returns the expected", { | ||
css_fields <- list("background" = matrix(c("red", "red", | ||
"blue", "green", | ||
"yellow", "orange"), | ||
nrow = 3, ncol = 2, byrow = TRUE), | ||
"text-align" = matrix(c("left", "right", | ||
"left", "center", | ||
"right", "left"), | ||
nrow = 3, ncol = 2, byrow = TRUE)) | ||
|
||
output <- merge_css_conditions(matrix("", nrow = 3, ncol = 2), css_fields) | ||
expected_output <- matrix(c("; background: red; text-align: left", "; background: red; text-align: right", | ||
"; background: blue; text-align: left", "; background: green; text-align: center", | ||
"; background: yellow; text-align: right", "; background: orange; text-align: left"), | ||
nrow = 3, ncol = 2, byrow = TRUE) | ||
expect_that(nrow(output), equals(3)) | ||
expect_that(ncol(output), equals(2)) | ||
expect_that(output, equals(expected_output)) | ||
}) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Tests: | ||
library(condformat) | ||
library(dplyr) | ||
library(testthat) | ||
context("show") | ||
|
||
test_that("rule_fill_discrete works", { | ||
data(iris) | ||
x <- condformat(iris[c(1:10, 51:60, 101:110),]) | ||
y <- x + rule_fill_discrete(Species, | ||
expression = Sepal.Length > max(Sepal.Length), | ||
colours = c("TRUE" = "red", "FALSE" = "blue")) | ||
out <- condformat2html(y) | ||
expect_that(out[1], not(matches("red"))) | ||
|
||
y <- x + rule_fill_discrete(Species, | ||
expression = Sepal.Length >= min(Sepal.Length), | ||
colours = c("TRUE" = "red", "FALSE" = "blue")) | ||
out <- condformat2html(y) | ||
expect_that(out[1], not(matches("blue"))) | ||
|
||
y <- x + rule_fill_discrete(Species) | ||
out <- condformat2html(y) | ||
expect_that(out[1], matches("^<table.*</table>$")) | ||
}) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Tests: | ||
library(condformat) | ||
library(dplyr) | ||
library(testthat) | ||
context("show") | ||
|
||
test_that("show_column works", { | ||
data(iris) | ||
x <- condformat(head(iris)) + show_columns(-Sepal.Length) | ||
expect_true("Sepal.Length" %in% colnames(x)) | ||
out <- condformat2html(x) | ||
expect_that(out[1], not(matches("Sepal.Length"))) | ||
expect_that(out[1], matches("Sepal.Width")) | ||
expect_that(out[1], matches("Petal.Length")) | ||
expect_that(out[1], matches("Petal.Width")) | ||
expect_that(out[1], matches("Species")) | ||
}) | ||
|
||
test_that("show_column works with custom names", { | ||
data(iris) | ||
x <- condformat(head(iris)) + show_columns(Sepal.Length, Petal.Width, Species, | ||
col_names = c("MySepLen", "MyPetWi", "MySpe")) | ||
expect_true("Sepal.Length" %in% colnames(x)) | ||
expect_true("Petal.Length" %in% colnames(x)) | ||
out <- condformat2html(x) | ||
expect_that(out[1], not(matches("Sepal.Length"))) | ||
expect_that(out[1], not(matches("Sepal.Width"))) | ||
expect_that(out[1], not(matches("Petal.Length"))) | ||
expect_that(out[1], not(matches("Petal.Width"))) | ||
expect_that(out[1], not(matches("Species"))) | ||
expect_that(out[1], matches("MySepLen")) | ||
expect_that(out[1], matches("MyPetWi")) | ||
expect_that(out[1], matches("MySpe")) | ||
}) | ||
|
||
|
||
test_that("show_row works", { | ||
data(iris) | ||
x <- condformat(head(iris, n = 10)) + | ||
show_rows(Sepal.Length == 5.1, Sepal.Width == 3.5, | ||
Petal.Length == 1.4, Petal.Width == 0.2) | ||
# in the data frame nothing is filtered | ||
expect_that(nrow(x), equals(10)) | ||
out <- condformat2html(x) | ||
# the html code only shows one row (that does not have any 8 digit) | ||
expect_that(out[1], not(matches("8"))) | ||
}) |
This file was deleted.
Oops, something went wrong.