library(testthat)
# most common expectations:
# equality: expect_equal() and expect_identical()
# regexp: expect_match()
# catch-all: expect_true() and expect_false()
# console output: expect_output()
# messages: expect_message()
# warning: expect_warning()
# errors: expect_error()
escapeString <- function(s) {
t <- gsub("(\\\\)", "\\\\\\\\", s)
t <- gsub("(\n)", "\\\\n", t)
t <- gsub("(\r)", "\\\\r", t)
t <- gsub("(\")", "\\\\\"", t)
return(t)
}
prepStr <- function(s) {
t <- escapeString(s)
u <- eval(parse(text=paste0("\"", t, "\"")))
if(s!=u) stop("Unable to escape string!")
t <- paste0("\thtml <- \"", t, "\"")
utils::writeClipboard(t)
return(invisible())
}
evaluationMode <- "sequential"
processingLibrary <- "dplyr"
description <- "test: sequential dplyr"
countFunction <- "n()"
isDevelopmentVersion <- (length(strsplit(packageDescription("pivottabler")$Version, "\\.")[[1]]) > 3)
testScenarios <- function(description="test", releaseEvaluationMode="batch", releaseProcessingLibrary="dplyr", runAllForReleaseVersion=FALSE) {
isDevelopmentVersion <- (length(strsplit(packageDescription("pivottabler")$Version, "\\.")[[1]]) > 3)
if(isDevelopmentVersion||runAllForReleaseVersion) {
evaluationModes <- c("sequential", "batch")
processingLibraries <- c("dplyr", "data.table")
}
else {
evaluationModes <- releaseEvaluationMode
processingLibraries <- releaseProcessingLibrary
}
testCount <- length(evaluationModes)*length(processingLibraries)
c1 <- character(testCount)
c2 <- character(testCount)
c3 <- character(testCount)
c4 <- character(testCount)
testCount <- 0
for(evaluationMode in evaluationModes)
for(processingLibrary in processingLibraries) {
testCount <- testCount + 1
c1[testCount] <- evaluationMode
c2[testCount] <- processingLibrary
c3[testCount] <- paste0(description, ": ", evaluationMode, " ", processingLibrary)
c4[testCount] <- ifelse(processingLibrary=="data.table", ".N", "n()")
}
df <- data.frame(evaluationMode=c1, processingLibrary=c2, description=c3, countFunction=c4, stringsAsFactors=FALSE)
return(df)
}
context("MAP STYLING TESTS")
scenarios <- testScenarios("map styling: smoke tests")
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="range",
mappings=list(0, "green", 10000, "yellow", 35000, "red"))
pt$mapStyling(cells=pt$allCells, styleProperty="color", valueType="color", mapType="range",
mappings=list(from=c(0, 10000, 35000), to=c("white", "black", "white")))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "
\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=text, mapType=value")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="text", mapType="value",
mappings=list(3079, "bold", 14487, "bold", 33792, "bold", 63, 100, 83710, 900))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=text, mapType=logic")
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
skip_on_cran()
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="text", mapType="logic",
mappings=list("v==3079", "bold", "v<1000", 100, "5000<=v<25000", "bold", "v>50000", 900))
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="text", mapType="logic",
mappings=list("is.null(v)", "red"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=text, mapType=range")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="text", mapType="range",
mappings=list(0, 100, 5000, "normal", 30000, "bold", 80000, 900))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=number, mapType=value")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="number", mapType="value",
mappings=list(3079, 700, 14487, 700, 33792, 700, 63, 100, 83710, 900))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=number, mapType=logic")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="number", mapType="logic",
mappings=list("v==3079", 700, "v<1000", 100, "5000<=v<25000", 700, "v>50000", 900))
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="text", mapType="logic",
mappings=list("is.null(v)", "red"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=number, mapType=range")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="font-weight", valueType="number", mapType="range",
mappings=list(0, 100, 5000, 700, 30000, 700, 80000, 900))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=number, mapType=continuous")
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
skip_on_cran()
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$setStyling(cells=pt$allCells, declarations=list("color"="white", "background-color"="green"))
pt$mapStyling(cells=pt$allCells, styleProperty="opacity", valueType="number", mapType="continuous",
mappings=list(0, 0.35, 85000, 1))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=color, mapType=value")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="value",
mappings=list(3079, "red", 14487, "#00ff00", 33792, "rgb(64,64,255)", 63, "rgba(128,128,255,0.5)", 83710, "green"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=color, mapType=logic")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="logic",
mappings=list("v==3079", "pink", "v<1000", "red", "5000<=v<25000", "yellow", "v>50000", "green"))
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="text", mapType="logic",
mappings=list("is.null(v)", "red"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=color, mapType=range")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="range",
mappings=list(0, "red", 5000, "orange", 30000, "yellow", 80000, "green"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: valueType=color, mapType=continuous")
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
skip_on_cran()
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="continuous",
mappings=list(0, "red", 5000, "orange", 30000, "yellow", 80000, "green"))
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
# test color values
fc <- function(cell) {
if(is.null(cell$style)) return("-")
value <- cell$style$getPropertyValue("background-color")
if(is.null(value)) return("-")
if(is.na(value)) return("na")
value <- gsub("#", "", value)
return(value)
}
totalColour <- paste(sapply(pt$allCells, fc), collapse="|")
expect_identical(totalColour, "ff6600|ff1b00|ff8100|ffe500|ff0200|ffe600|ffc700|ecf500|a2d100|ffb200|-|ffb200|9ecf00|e7f300|008000")
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: mapping function")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
redclr <- function(x, cell) {
clr <- 255-floor(140*cell$columnNumber/3)
return(paste0("#",
format(as.hexmode(255), width=2),
format(as.hexmode(clr), width=2),
format(as.hexmode(clr), width=2)))
}
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", mappings=redclr)
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: mapping range (3 \"from\", 2 \"to\")")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# note below there are 3 "from" values and 2 "to" values, and styleHigherValues has been disabled
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="range",
mappings=list(0, "red", 1000, "orange", 15000), styleHigherValues=FALSE)
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}
scenarios <- testScenarios("map styling: mapping range (extended lower")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]
test_that(description, {
library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode)
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# note below there are 3 "from" values and 2 "to" values, and styleHigherValues has been disabled
pt$mapStyling(cells=pt$allCells, styleProperty="background-color", valueType="color", mapType="range",
mappings=list(500, "red", 1000, "orange", 15000), styleLowerValues=TRUE, styleHigherValues=FALSE)
# pt$renderPivot()
# sum(pt$cells$asMatrix(), na.rm=TRUE)
# prepStr(as.character(pt$getHtml()))
html <- "\n \n \n Express Passenger | \n Ordinary Passenger | \n Total | \n
\n \n \n 3079 | \n 830 | \n 3909 | \n
\n \n \n 22865 | \n 63 | \n 22928 | \n
\n \n \n 14487 | \n 33792 | \n 48279 | \n
\n \n \n 8594 | \n | \n 8594 | \n
\n \n \n 49025 | \n 34685 | \n 83710 | \n
\n
"
expect_equal(sum(pt$cells$asMatrix(), na.rm=TRUE), 334840)
expect_identical(as.character(pt$getHtml()), html)
})
}