# Unit tests for calculating reference values testthat::test_that(".Get_reference_percentile works", { metric <- "CSMA" sex <- "Female" level <- "T5" age <- 40 measurement <- 157.75 testthat::expect_equal(.Get_reference_percentile(metric, sex, level, age, measurement), 50) testthat::expect_output(.Get_reference_percentile(metric, sex, level, age, measurement, verbose = TRUE), "For a 40-yo Female, a CSMA of 157.75 corresponds to percentile 50") }) testthat::test_that(".Get_reference_z_score works", { metric <- "CSMA" sex <- "Female" level <- "T5" age <- 40 measurement <- 157.75 testthat::expect_equal(.Get_reference_z_score(metric, sex, level, age, measurement, digits = 10), -0.0000277442) testthat::expect_output(.Get_reference_z_score(metric, sex, level, age, measurement, verbose = TRUE), "For a 40-yo Female, a CSMA of 157.75 corresponds to a z-score of 0") }) testthat::test_that(".Get_reference_value works", { metric <- "CSMA" sex <- "Female" level <- "T5" age <- 40 percentile <- 50 z_score <- 0 testthat::expect_equal(.Get_reference_value(metric, sex, level, age, percentile = percentile, digits = 2), 157.75) testthat::expect_equal(.Get_reference_value(metric, sex, level, age, z_score = z_score), 158) testthat::expect_output(.Get_reference_value(metric, sex, level, age, z_score = 0.1, verbose = TRUE), "For a 40-yo Female, a z-score of 0.1 corresponds to a CSMA of 159") }) testthat::test_that(".Get_percent_predicted works", { metric <- "CSMA" sex <- "Female" level <- "T5" age <- 40 measurement <- 79 testthat::expect_equal(.Get_percent_predicted(metric, sex, level, age, measurement), 50) testthat::expect_output(.Get_percent_predicted(metric, sex, level, age, measurement, verbose = TRUE), "For a 40-yo Female, a CSMA of 79 corresponds to 50% of the expected 158") }) testthat::test_that("reference_percentiles works", { metric <- c("CSMA", "CSMA") sex <- c("Female", "Male") level <- c("T5", "T8") age <- c(40, 60) measurement <- c(150, 100) testthat::expect_equal(reference_percentiles(metric, sex, level, age, measurement), c(33, 12)) }) testthat::test_that("reference_z_scores works", { metric <- c("CSMA", "CSMA") sex <- c("Female", "Male") level <- c("T5", "T8") age <- c(40, 60) measurement <- c(150, 100) testthat::expect_equal(reference_z_scores(metric, sex, level, age, measurement), c(-0.45, -1.18)) }) testthat::test_that("reference_values works", { metric <- c("CSMA", "CSMA") sex <- c("Female", "Male") level <- c("T5", "T8") age <- c(40, 60) percentile <- c(50, 50) testthat::expect_equal(reference_values(metric, sex, level, age, percentile), c(158, 119)) }) testthat::test_that("percent_predicted works", { metric <- c("CSMA", "CSMA") sex <- c("Female", "Male") level <- c("T5", "T8") age <- c(40, 60) measurement <- c(109, 220) testthat::expect_equal(percent_predicted(metric, sex, level, age, measurement), c(69, 185)) }) testthat::test_that(".Get_lambda works", { testthat::expect_equal(.Get_lambda("SMG", "Female", "T5"), NA) })