Skip to content

Commit

Permalink
tests for log scale
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Nov 4, 2024
1 parent 53f7bc9 commit c73495a
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,47 @@ test_that("Highest value is used as default upper limit", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod <- biokinetics$new(data = dat, lower_detection_limit = 2)
stan_data <- mod$get_stan_data()
expect_equal(stan_data$upper_limit, log2(max(dat$value)/2))
expect_equal(stan_data$upper_limit, log2(max(dat$value) / 2))
expect_equal(stan_data$lower_limit, 0)
})

test_that("Warns if data contains values above the upper limit", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
expect_warning({mod <- biokinetics$new(data = dat, upper_detection_limit = 10)},
expect_warning({ mod <- biokinetics$new(data = dat, upper_detection_limit = 10) },
"Data contains a value of 2560 which is greater than the upper detection limit 10")
stan_data <- mod$get_stan_data()
expect_equal(stan_data$upper_limit, log2(10/5))
expect_equal(stan_data$upper_limit, log2(10 / 5))
expect_equal(stan_data$lower_limit, 0)
})

test_that("Smallest value is used as default lower limit", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod <- biokinetics$new(data = dat, upper_detection_limit = 3000)
stan_data <- mod$get_stan_data()
expect_equal(stan_data$upper_limit, log2(3000/min(dat$value)))
expect_equal(stan_data$upper_limit, log2(3000 / min(dat$value)))
expect_equal(stan_data$lower_limit, 0)
})

test_that("Warns if data contains values below the lower limit", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
expect_warning({mod <- biokinetics$new(data = dat,
upper_detection_limit = 2560,
lower_detection_limit = 10)},
"Data contains a value of 5 which is smaller than the lower detection limit 10")
expect_warning({ mod <- biokinetics$new(data = dat,
upper_detection_limit = 2560,
lower_detection_limit = 10) },
"Data contains a value of 5 which is smaller than the lower detection limit 10")
stan_data <- mod$get_stan_data()
expect_equal(stan_data$upper_limit, log2(2560/10))
expect_equal(stan_data$upper_limit, log2(2560 / 10))
expect_equal(stan_data$lower_limit, 0)
})

test_that("Detection limits are passed to stan without transformation if using log data", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod <- biokinetics$new(data = convert_log2_scale(dat,
lower_limit = 2,
vars_to_transform = "value"),
scale = "log",
lower_detection_limit = 1,
upper_detection_limit = 15)
stan_data <- mod$get_stan_data()
expect_equal(stan_data$upper_limit, 15)
expect_equal(stan_data$lower_limit, 1)
})

0 comments on commit c73495a

Please sign in to comment.