diff --git a/tests/testthat/test-expand.R b/tests/testthat/test-expand.R new file mode 100644 index 00000000..1bfd8991 --- /dev/null +++ b/tests/testthat/test-expand.R @@ -0,0 +1,45 @@ +context("Default values for plot configuration expand and scales") + +# To prevent copy/paste, expressions are used in the sequel +plotNames <- c("DDIRatio", "", "TimeProfile", "ObsVsPred", "ResVsPred", "Histogram", "PKRatio", "BoxWhisker", "Tornado") + +# Epression is "plotConfiguration <- PlotConfiguration$new()" +createPlotConfigurations <- parse(text = paste0(tolower(plotNames), "plotConfiguration <- ", plotNames, "PlotConfiguration$new()")) +eval(createPlotConfigurations) + +# Epression is "expect_false(plotConfiguration$defaultExpand)" +# Use -1 to remove first element ie DDI Ratio from the evaluation +checkExpandIsFalse <- parse(text = paste0("expect_false(", tolower(plotNames[-1]), "plotConfiguration$defaultExpand)")) + +test_that("Default expand is true for DDI ratio only", { + eval(checkExpandIsFalse) + expect_true(ddiratioplotConfiguration$defaultExpand) +}) + + +test_that("Default x and y scales is log for ddi ratio", { + expect_equal(ddiratioplotConfiguration$defaultXScale, Scaling$log) + expect_equal(ddiratioplotConfiguration$defaultYScale, Scaling$log) +}) + +test_that("Default x scale is linear and y scale is log for pk ratio", { + expect_equal(pkratioplotConfiguration$defaultXScale, Scaling$lin) + expect_equal(pkratioplotConfiguration$defaultYScale, Scaling$log) +}) + +test_that("Default x scale is linear and y scale is discrete for tornado plot", { + expect_equal(tornadoplotConfiguration$defaultXScale, Scaling$lin) + expect_equal(tornadoplotConfiguration$defaultYScale, Scaling$discrete) +}) + +test_that("Default x scale is discrete and y scale is linear for box-whisker plot", { + expect_equal(boxwhiskerplotConfiguration$defaultXScale, Scaling$discrete) + expect_equal(boxwhiskerplotConfiguration$defaultYScale, Scaling$lin) +}) + +checkXScaleIsLinear <- parse(text = paste0("expect_equal(", tolower(plotNames[2:6]), "plotConfiguration$defaultXScale, Scaling$lin)")) +checkYScaleIsLinear <- parse(text = paste0("expect_equal(", tolower(plotNames[2:6]), "plotConfiguration$defaultYScale, Scaling$lin)")) +test_that("Default scales are linear for other plots", { + eval(checkXScaleIsLinear) + eval(checkYScaleIsLinear) +})