Skip to content

Commit

Permalink
Fixes #253 default expand for ddi ratio and other plot configurations (
Browse files Browse the repository at this point in the history
…#265)

* Fixes #253 default expand for ddi ratio and other plot configurations

* Also test default scales (lin/log/discrete)
  • Loading branch information
pchelle authored May 12, 2022
1 parent c346b0c commit 30e8b25
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/testthat/test-expand.R
Original file line number Diff line number Diff line change
@@ -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 "<plotname>plotConfiguration <- <PlotName>PlotConfiguration$new()"
createPlotConfigurations <- parse(text = paste0(tolower(plotNames), "plotConfiguration <- ", plotNames, "PlotConfiguration$new()"))
eval(createPlotConfigurations)

# Epression is "expect_false(<plotname>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)
})

0 comments on commit 30e8b25

Please sign in to comment.