diff --git a/tests/testthat/test-catColorPal.R b/tests/testthat/test-catColorPal.R index 73b4e8c..30df5f8 100644 --- a/tests/testthat/test-catColorPal.R +++ b/tests/testthat/test-catColorPal.R @@ -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"))) }) diff --git a/tests/testthat/test-continuousColorPal.R b/tests/testthat/test-continuousColorPal.R index b352f21..5e548ae 100644 --- a/tests/testthat/test-continuousColorPal.R +++ b/tests/testthat/test-continuousColorPal.R @@ -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)) }) diff --git a/tests/testthat/test-exchangesStack.R b/tests/testthat/test-exchangesStack.R index f87f1ec..6e2eac1 100644 --- a/tests/testthat/test-exchangesStack.R +++ b/tests/testthat/test-exchangesStack.R @@ -1,6 +1,6 @@ context("exchangesStack") -describe("no interactive", { +test_that("no interactive", { mydata <- readAntares(links = "all", timeStep = "daily", showProgress = FALSE) # default parameters @@ -13,7 +13,7 @@ describe("no interactive", { # - tester les retours d'erreurs }) -describe("exchangesStack, no interactive", { +test_that("exchangesStack, no interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) testClass <- function(obj){ class(obj)[1] == "combineWidgets" @@ -24,21 +24,18 @@ describe("exchangesStack, no interactive", { ylab = list(x = dta, interactive = FALSE, areas = "all", main = "Title", ylab = "Subt") ) lapply(listArgs, function(X){ - test_that (names(listArgs), { - re1 <- do.call(exchangesStack, X) - expect_true(testClass(re1)) - }) + re1 <- do.call(exchangesStack, X) + expect_true(testClass(re1)) }) }) -describe("exchangesStack, no interactive return error", { +test_that("exchangesStack, no interactive return error", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) expect_error(exchangesStack(dta, interactive = FALSE, compare = "areas")) - }) -describe("exchangesStack, no interactive, x and refStudy are antaresDataTable", { +test_that("exchangesStack, no interactive, x and refStudy are antaresDataTable", { myData1 <- readAntares(links = "all", showProgress = FALSE) myData2 <- readAntares(links = "all", showProgress = FALSE) myArea <- "a" @@ -66,7 +63,7 @@ describe("exchangesStack, no interactive, x and refStudy are antaresDataTable", expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) }) -describe("exchangesStack, no interactive, x and refStudy are antaresDataList", { +test_that("exchangesStack, no interactive, x and refStudy are antaresDataList", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myArea <- "a" @@ -120,7 +117,7 @@ describe("exchangesStack, no interactive, x and refStudy are antaresDataList", { expect_equal(dataExS21V3$ROW[indexHour], 500) }) -describe("exchangesStack, no interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { +test_that("exchangesStack, no interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { myData1 <- readAntares(links = "all", showProgress = FALSE) myData2 <- readAntares(links = "all", showProgress = FALSE) myData3 <- readAntares(links = "all", showProgress = FALSE) @@ -154,7 +151,7 @@ describe("exchangesStack, no interactive, x is a list of antaresDataTable and re expect_equal(dataExS21V1$a_offshore[indexHour], 2500) }) -describe("exchangesStack, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +test_that("exchangesStack, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -224,7 +221,7 @@ describe("exchangesStack, no interactive, x is a list of antaresDataList and ref expect_equal(dataExListV3g2$negROW[indexHour], 1000) }) -describe("exchangesStack, interactive, x and refStudy are antaresDataTable", { +test_that("exchangesStack, interactive, x and refStudy are antaresDataTable", { skip_if_not(.runExchangesStackTest) myData1 <- readAntares(links = "all", showProgress = FALSE) myData2 <- readAntares(links = "all", showProgress = FALSE) @@ -275,7 +272,7 @@ describe("exchangesStack, interactive, x and refStudy are antaresDataTable", { expect_equal(dataExS21V1$nega_offshore[indexHour], 2500) }) -describe("exchangesStack, interactive, x and refStudy are antaresDataList", { +test_that("exchangesStack, interactive, x and refStudy are antaresDataList", { skip_if_not(.runExchangesStackTest) myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -366,7 +363,7 @@ describe("exchangesStack, interactive, x and refStudy are antaresDataList", { expect_equal(dataExS21V3$ROW[indexHour], 500) }) -describe("exchangesStack, interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { +test_that("exchangesStack, interactive, x is a list of antaresDataTable and refStudy an antaresDataTable", { skip_if_not(.runExchangesStackTest) myData1 <- readAntares(links = "all", showProgress = FALSE) myData2 <- readAntares(links = "all", showProgress = FALSE) @@ -420,7 +417,7 @@ describe("exchangesStack, interactive, x is a list of antaresDataTable and refSt expect_equal(dataExS21V1$a_offshore[indexHour], 2500) }) -describe("exchangesStack, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +test_that("exchangesStack, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { skip_if_not(.runExchangesStackTest) myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -527,7 +524,7 @@ describe("exchangesStack, interactive, x is a list of antaresDataList and refStu expect_equal(dataExListV3g2$negROW[indexHour], 1000) }) -describe("exchangesStack, no interactive, x and refStudy are optsH5 ", { +test_that("exchangesStack, no interactive, x and refStudy are optsH5 ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runExchangesStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -580,7 +577,7 @@ describe("exchangesStack, no interactive, x and refStudy are optsH5 ", { } }) -describe("exchangesStack, no interactive, x is a list of optH5 and refStudy are optsH5 ", { +test_that("exchangesStack, no interactive, x is a list of optH5 and refStudy are optsH5 ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runExchangesStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -653,7 +650,7 @@ describe("exchangesStack, no interactive, x is a list of optH5 and refStudy are } }) -describe("exchangesStack, interactive, x and refStudy are optsH5 ", { +test_that("exchangesStack, interactive, x and refStudy are optsH5 ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runExchangesStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -788,7 +785,7 @@ describe("exchangesStack, interactive, x and refStudy are optsH5 ", { } }) -describe("exchangesStack, interactive, x is a list of optsH5 and refStudy optsH5 , ", { +test_that("exchangesStack, interactive, x is a list of optsH5 and refStudy optsH5 , ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runExchangesStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) diff --git a/tests/testthat/test-getTSData.R b/tests/testthat/test-getTSData.R index eb9f312..dc4a50e 100644 --- a/tests/testthat/test-getTSData.R +++ b/tests/testthat/test-getTSData.R @@ -1,59 +1,57 @@ context(".getTSData") -describe(".getTSData", { - # Helper function that checks the structure of object returned by .getTSData - # is ok - check_obj <- function(x, aggregated = FALSE) { - expect_is(x, "data.table") - expect_true(all(c("element", "timeId", "time", "value") %in% names(x))) - } - - mydata <- readAntares(timeStep = "daily", mcYears = "all", showProgress = FALSE) - tpl <- mydata[, .(mcYear, element = area, timeId, time, value = 0)] - - mydata_av <- readAntares(timeStep = "daily", mcYears = NULL, showProgress = FALSE) - tpl_av <- mydata_av[, .(element = area, timeId, time, value = 0)] +# Helper function that checks the structure of object returned by .getTSData +# is ok +check_obj <- function(x, aggregated = FALSE) { + expect_is(x, "data.table") + expect_true(all(c("element", "timeId", "time", "value") %in% names(x))) +} + +mydata <- readAntares(timeStep = "daily", mcYears = "all", showProgress = FALSE) +tpl <- mydata[, .(mcYear, element = area, timeId, time, value = 0)] + +mydata_av <- readAntares(timeStep = "daily", mcYears = NULL, showProgress = FALSE) +tpl_av <- mydata_av[, .(element = area, timeId, time, value = 0)] + +test_that("returns a table with element, timeId, time and value columns", { + dt <- .getTSData(mydata, tpl, "LOAD", "all") + check_obj(dt) +}) + +test_that("can filter data by element, date, mcYear", { + # element + myarea <- getAreas()[1] + dt <- .getTSData(mydata_av, tpl_av, "LOAD", elements = myarea) + check_obj(dt) + expect_true(all(dt$element == myarea)) + expect_equal(dt$value, mydata_av[area == myarea, LOAD]) - it ("returns a table with element, timeId, time and value columns", { - dt <- .getTSData(mydata, tpl, "LOAD", "all") - check_obj(dt) - }) + # date + dateRange <- c(min(dt$time), min(dt$time)) + dt <- .getTSData(mydata, tpl, "LOAD", "all", dateRange = dateRange) + check_obj(dt) + expect_true(all(dt$time == dateRange[1])) + expect_equal(dt$value, mydata[time == dateRange[1], LOAD]) - it ("can filter data by element, date, mcYear", { - # element - myarea <- getAreas()[1] - dt <- .getTSData(mydata_av, tpl_av, "LOAD", elements = myarea) - check_obj(dt) - expect_true(all(dt$element == myarea)) - expect_equal(dt$value, mydata_av[area == myarea, LOAD]) - - # date - dateRange <- c(min(dt$time), min(dt$time)) - dt <- .getTSData(mydata, tpl, "LOAD", "all", dateRange = dateRange) - check_obj(dt) - expect_true(all(dt$time == dateRange[1])) - expect_equal(dt$value, mydata[time == dateRange[1], LOAD]) - - # mcYear - dt <- .getTSData(mydata, tpl, "LOAD", "all", mcYear = 1) - check_obj(dt) - expect_true(all(dt$mcYear == 1)) - expect_equal(dt$value, mydata[mcYear == 1, LOAD]) - }) + # mcYear + dt <- .getTSData(mydata, tpl, "LOAD", "all", mcYear = 1) + check_obj(dt) + expect_true(all(dt$mcYear == 1)) + expect_equal(dt$value, mydata[mcYear == 1, LOAD]) +}) + +test_that("can aggregate data", { + # sum + dt <- .getTSData(mydata_av, tpl_av, "LOAD", "all", aggregate = "sum") + check_obj(dt) + expect_true(all(dt$element == "LOAD")) + expectValue <- mydata_av[, .(LOAD = sum(LOAD)), by = .(timeId)] + expect_equal(dt$value, expectValue$LOAD) - it ("can aggregate data", { - # sum - dt <- .getTSData(mydata_av, tpl_av, "LOAD", "all", aggregate = "sum") - check_obj(dt) - expect_true(all(dt$element == "LOAD")) - expectValue <- mydata_av[, .(LOAD = sum(LOAD)), by = .(timeId)] - expect_equal(dt$value, expectValue$LOAD) - - # mean - dt <- .getTSData(mydata_av, tpl_av, "LOAD", "all", aggregate = "mean") - check_obj(dt) - expect_true(all(dt$element == "LOAD")) - expectValue <- mydata_av[, .(LOAD = mean(LOAD)), by = .(timeId)] - expect_equal(dt$value, expectValue$LOAD) - }) -}) \ No newline at end of file + # mean + dt <- .getTSData(mydata_av, tpl_av, "LOAD", "all", aggregate = "mean") + check_obj(dt) + expect_true(all(dt$element == "LOAD")) + expectValue <- mydata_av[, .(LOAD = mean(LOAD)), by = .(timeId)] + expect_equal(dt$value, expectValue$LOAD) +}) diff --git a/tests/testthat/test-get_data_for_comp.R b/tests/testthat/test-get_data_for_comp.R index c97bc00..98ad740 100644 --- a/tests/testthat/test-get_data_for_comp.R +++ b/tests/testthat/test-get_data_for_comp.R @@ -19,17 +19,15 @@ check_structure <- function(x, y = NULL, compare = NULL, compareOpts = NULL) { adt <- readAntares(showProgress = FALSE) adl <- readAntares("all", "all", showProgress = FALSE) -describe(".getDataForComp", { - it("always returns the same structure whatever the input data", { - check_structure(adt) - check_structure(adt, compare = "test") - check_structure(adt, compareOpts = list(ncharts = 3)) - check_structure(adt, adt) - check_structure(list(adt, adt, adt)) - check_structure(adl) - check_structure(adl, compare = "test") - check_structure(adl, compareOpts = list(ncharts = 3)) - check_structure(adl, adl) - check_structure(list(adl, adl, adl)) - }) +test_that(".getDataForComp", { + check_structure(adt) + check_structure(adt, compare = "test") + check_structure(adt, compareOpts = list(ncharts = 3)) + check_structure(adt, adt) + check_structure(list(adt, adt, adt)) + check_structure(adl) + check_structure(adl, compare = "test") + check_structure(adl, compareOpts = list(ncharts = 3)) + check_structure(adl, adl) + check_structure(list(adl, adl, adl)) }) diff --git a/tests/testthat/test-graphUtils.R b/tests/testthat/test-graphUtils.R index 953b5c2..b8305e6 100644 --- a/tests/testthat/test-graphUtils.R +++ b/tests/testthat/test-graphUtils.R @@ -1,7 +1,7 @@ context(".compOpts") -describe(".compOpts", { +test_that(".compOpts", { expect_true(.compOpts("", "cp")$ncharts == 2) expect_true(.compOpts("", NULL)$ncharts == 1) @@ -10,7 +10,7 @@ describe(".compOpts", { if(.requireRhdf5_Antares(stopP = FALSE)){ context(".dateRangeJoin") - describe(".dateRangeJoin", { + test_that(".dateRangeJoin", { dt <- list() dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) @@ -35,7 +35,7 @@ if(.requireRhdf5_Antares(stopP = FALSE)){ }) context(".loadH5Data") - describe(".loadH5Data", { + test_that(".loadH5Data", { opts <- setSimulationPath(studyPath) sharerequest <- list() sharerequest$mcYearh_l <- "all" diff --git a/tests/testthat/test-h5Request.R b/tests/testthat/test-h5Request.R index 110561d..cedce08 100644 --- a/tests/testthat/test-h5Request.R +++ b/tests/testthat/test-h5Request.R @@ -1,6 +1,6 @@ # context("H5 utils") # -# describe("h5", { +# test_that("h5", { # if(.requireRhdf5_Antares(stopP = FALSE)){ # suppressMessages(writeAntaresH5(pathtemp, overwrite = TRUE)) # optsH5 <- setSimulationPath(pathtemp) @@ -29,4 +29,4 @@ # # # }) - \ No newline at end of file + diff --git a/tests/testthat/test-plotMap.R b/tests/testthat/test-plotMap.R index 7e4548a..2cb6229 100644 --- a/tests/testthat/test-plotMap.R +++ b/tests/testthat/test-plotMap.R @@ -1,6 +1,6 @@ context("plotMap") -describe("plotMap, no interactive", { +test_that("plotMap, no interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) testClass <- function(obj){ @@ -15,15 +15,13 @@ describe("plotMap, no interactive", { ) lapply(listArgs, function(X){ - test_that (names(listArgs), { - re1 <- do.call(plotMap, X) - expect_true(testClass(re1)) - }) + re1 <- do.call(plotMap, X) + expect_true(testClass(re1)) }) }) -describe("plotMap, no interactive return error", { +test_that("plotMap, no interactive return error", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) load(system.file("mapLayout/ml.rda", package = "antaresViz")) @@ -33,7 +31,7 @@ describe("plotMap, no interactive return error", { }) -describe("plotMap, interactive", { +test_that("plotMap, interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) load(system.file("mapLayout/ml.rda", package = "antaresViz")) VV <- plotMap(x = dta, mapLayout = ml, .runApp = FALSE, interactive = TRUE) @@ -41,7 +39,7 @@ describe("plotMap, interactive", { expect_true("MWController" %in% class(VV)) }) -describe("plotMap, no interactive, x and refStudy are antaresDataList", { +test_that("plotMap, no interactive, x and refStudy are antaresDataList", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) load(system.file("mapLayout/ml.rda", package = "antaresViz")) resPlotMap <- plotMap(x = dta, @@ -85,7 +83,7 @@ describe("plotMap, no interactive, x and refStudy are antaresDataList", { expect_equal(valToValid, 2500) }) -describe("plotMap, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +test_that("plotMap, no interactive, x is a list of antaresDataList and refStudy an antaresDataList", { data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) dataList <- list(data1, data1, data1) load(system.file("mapLayout/ml.rda", package = "antaresViz")) @@ -136,7 +134,7 @@ describe("plotMap, no interactive, x is a list of antaresDataList and refStudy a expect_equal(valToValid, 2500) }) -describe("plotMap, interactive, x and refStudy are antaresDataList", { +test_that("plotMap, interactive, x and refStudy are antaresDataList", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) load(system.file("mapLayout/ml.rda", package = "antaresViz")) #interactive @@ -187,7 +185,7 @@ describe("plotMap, interactive, x and refStudy are antaresDataList", { expect_equal(valToValid, 2500) }) -describe("plotMap, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { +test_that("plotMap, interactive, x is a list of antaresDataList and refStudy an antaresDataList", { data1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) dataList <- list(data1, data1, data1) load(system.file("mapLayout/ml.rda", package = "antaresViz")) @@ -243,7 +241,7 @@ describe("plotMap, interactive, x is a list of antaresDataList and refStudy an a expect_equal(valToValid, 2500) }) -describe("plotMap, interactive, x and refStudy are optsH5", { +test_that("plotMap, interactive, x and refStudy are optsH5", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runPlotMapTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) diff --git a/tests/testthat/test-plotThermalGroupCapacities.R b/tests/testthat/test-plotThermalGroupCapacities.R index 41d355f..73a7fdf 100644 --- a/tests/testthat/test-plotThermalGroupCapacities.R +++ b/tests/testthat/test-plotThermalGroupCapacities.R @@ -1,6 +1,6 @@ context("plotThermalGroupCapacities") -describe("plotThermalGroupCapacities", { +test_that("plotThermalGroupCapacities", { opts <- setSimulationPath(studyPath) GG <- plotThermalGroupCapacities( data = thermalGroupCapacities(opts)) diff --git a/tests/testthat/test-plotXY.R b/tests/testthat/test-plotXY.R index a91f0d5..eb91c6f 100644 --- a/tests/testthat/test-plotXY.R +++ b/tests/testthat/test-plotXY.R @@ -1,6 +1,6 @@ context("prodStack no interactive") -describe("prodStack, no interactive", { +test_that("prodStack, no interactive", { if(.requireRhdf5_Antares(stopP = FALSE)){ dta <- readAntares(areas = "all", showProgress = FALSE) g <- plotXY(dta, "NODU", "LOAD", precision = 50, sizeOnCount = FALSE) diff --git a/tests/testthat/test-prodStack.R b/tests/testthat/test-prodStack.R index f64e4b3..bb598b4 100644 --- a/tests/testthat/test-prodStack.R +++ b/tests/testthat/test-prodStack.R @@ -1,6 +1,6 @@ context("prodStack") -describe("prodStack, no interactive", { +test_that("prodStack, no interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) testClass <- function(obj){ class(obj)[1] == "combineWidgets" @@ -10,28 +10,26 @@ describe("prodStack, no interactive", { ) lapply(listArgs, function(X){ - test_that (names(listArgs), { - re1 <- do.call(prodStack, X) - expect_true(testClass(re1)) - }) + re1 <- do.call(prodStack, X) + expect_true(testClass(re1)) }) }) -describe("prodStack, no interactive return error", { +test_that("prodStack, no interactive return error", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) expect_error(prodStack(dta, interactive = FALSE, compare = "areas")) }) -describe("prodStack, interactive", { +test_that("prodStack, interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) VV <- prodStack(dta, interactive = FALSE) expect_true("htmlwidget" %in% class(VV)) }) -describe("prodStack must work with refStudy, if x and refStudy are antaresDataList, ", { +test_that("prodStack must work with refStudy, if x and refStudy are antaresDataList, ", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -66,7 +64,7 @@ describe("prodStack must work with refStudy, if x and refStudy are antaresDataLi expect_true(all.equal(0, dataHtmlWidgetPS$neggas[[20]])) }) -describe("prodStack must work with refStudy, if x is a list of antaresDataList and refStudy an antaresDataList, ", { +test_that("prodStack must work with refStudy, if x is a list of antaresDataList and refStudy an antaresDataList, ", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData3 <- readAntares(areas = c("a", "b", "c"), links = "all", showProgress = FALSE) @@ -109,7 +107,7 @@ describe("prodStack must work with refStudy, if x is a list of antaresDataList a }) -describe("prodStack must work with refStudy, if x and refStudy are optsH5, ", { +test_that("prodStack must work with refStudy, if x and refStudy are optsH5, ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runProdStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -169,7 +167,7 @@ describe("prodStack must work with refStudy, if x and refStudy are optsH5, ", { }) -describe("prodStack must work with refStudy, if x is a list of optsH5 and refStudy an optsH5, ", { +test_that("prodStack must work with refStudy, if x is a list of optsH5 and refStudy an optsH5, ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runProdStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -240,7 +238,7 @@ describe("prodStack must work with refStudy, if x is a list of optsH5 and refStu } }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x and refStudy are antaresData, ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x and refStudy are antaresData, ", { myData1 <- readAntares(areas = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", showProgress = FALSE) @@ -315,7 +313,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x a list of antaresData and refStudy an antaresData, ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x a list of antaresData and refStudy an antaresData, ", { myData1 <- readAntares(areas = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", showProgress = FALSE) myData3 <- readAntares(areas = "all", showProgress = FALSE) @@ -370,7 +368,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x is an antaresDataList and refStudy an antaresDataList, ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is an antaresDataList and refStudy an antaresDataList, ", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -420,7 +418,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of antaresDataList and refStudy an antaresDataList , ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of antaresDataList and refStudy an antaresDataList , ", { myData1 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData2 <- readAntares(areas = "all", links = "all", showProgress = FALSE) myData3 <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -478,7 +476,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x, refStudy are optsH5 , ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x, refStudy are optsH5 , ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runProdStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -576,7 +574,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of optsH5 and refStudy optsH5 , ", { +test_that("prodStack must work with refStudy, if interactive is set to TRUE and if x is a list of optsH5 and refStudy optsH5 , ", { if (.requireRhdf5_Antares(stopP = FALSE)){ skip_if_not(.runProdStackTest) suppressMessages(writeAntaresH5(pathtemp, opts = opts, overwrite = TRUE)) @@ -722,7 +720,7 @@ describe("prodStack must work with refStudy, if interactive is set to TRUE and i }) -describe("prodStack, no interactive, ne error with compare main", { +test_that("prodStack, no interactive, ne error with compare main", { myData <- readAntares(areas = "all", links = "all", showProgress = FALSE) myApplica <- prodStack(x = myData, interactive = TRUE, diff --git a/tests/testthat/test-ts_plot.R b/tests/testthat/test-ts_plot.R index a620c87..471532a 100644 --- a/tests/testthat/test-ts_plot.R +++ b/tests/testthat/test-ts_plot.R @@ -1,6 +1,6 @@ context("tsPlot") -describe("tsPlot, no interactive", { +test_that("tsPlot, no interactive", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) testClass <- function(obj){ class(obj)[1] == 'combineWidgets' @@ -19,17 +19,15 @@ describe("tsPlot, no interactive", { ) lapply(listArgs, function(X){ - test_that (names(listArgs), { - re1 <- do.call(tsPlot, X) - expect_true(testClass(re1)) - }) + re1 <- do.call(tsPlot, X) + expect_true(testClass(re1)) }) }) -describe("tsPlot, no interactive return error", { +test_that("tsPlot, no interactive return error", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE) @@ -37,7 +35,7 @@ describe("tsPlot, no interactive return error", { }) -describe("tsPlot, work with compare", { +test_that("tsPlot, work with compare", { dta <- readAntares(areas = "all", links = "all", showProgress = FALSE, mcYears = "all") exList <- tsPlot(x = dta, .runApp = FALSE, interactive = TRUE, compare = "mcYear") @@ -64,7 +62,7 @@ describe("tsPlot, work with compare", { }) -describe("tsPlot, no interactive, x and refStudy are antaresDataTable", { +test_that("tsPlot, no interactive, x and refStudy are antaresDataTable", { myData1 <- readAntares(links = "all", showProgress = FALSE) myData2 <- readAntares(links = "all", showProgress = FALSE) myLink <- "a - a_offshore" @@ -109,7 +107,7 @@ describe("tsPlot, no interactive, x and refStudy are antaresDataTable", { expect_equal(dataTsDa2[[myArea]][[indexHour]], 0) }) -describe("tsPlot, no interactive, x and refStudy are antaresDataList", { +test_that("tsPlot, no interactive, x and refStudy are antaresDataList", { myArea <- "b" myLink <- "a - a_offshore" myData1 <- readAntares(links = myLink, areas = myArea, showProgress = FALSE, mcYears = 1)