From e8f90c2f58b05d488ed6d53975274c448d01970b Mon Sep 17 00:00:00 2001 From: Kai Aragaki Date: Sat, 4 Nov 2023 15:28:09 -0400 Subject: [PATCH] test: add some qp_fit unit tests --- R/qp_fit.R | 4 ++-- tests/testthat/test-qp_fit.R | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-qp_fit.R diff --git a/R/qp_fit.R b/R/qp_fit.R index 189be14..8eba25f 100644 --- a/R/qp_fit.R +++ b/R/qp_fit.R @@ -30,14 +30,14 @@ qp_fit <- function(x) { #' @export qp_fit.data.frame <- function(x) { - if (!".log2_abs" %in% colnames(x)) { + if (!has_cols(x, ".log2_abs")) { rlang::inform("Did not find column `.log2_abs`, calculating.") check_has_cols(x, ".abs") check_abs(x$.abs) x$.log2_abs <- log2(x$.abs) } - if (!".is_outlier" %in% colnames(x)) { + if (!has_cols(x, ".is_outlier")) { rlang::inform( c("Did not find column `.is_outlier`, fitting with all standards.", "i" = "To remove outliers, set `ignore_outliers` in `qp_calc_abs_mean`") diff --git a/tests/testthat/test-qp_fit.R b/tests/testthat/test-qp_fit.R new file mode 100644 index 0000000..3a191cc --- /dev/null +++ b/tests/testthat/test-qp_fit.R @@ -0,0 +1,19 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) + +test_that(".log2_abs is calculated if not present", { + x <- absorbances[1:40, ] |> + qp_mark_outliers("all") |> + qp_add_std_conc() + expect_message(qp_fit(x), "Did not find column `\\.log2_abs`") + expect_equal(log2(x$.abs), qp_fit(x)$qp$.log2_abs) +}) + +test_that(".is_outlier is produced if not present", { + x <- absorbances[1:40, ] + x$.log2_abs <- log2(x$.abs) + x <- qp_add_std_conc(x) + expect_message(qp_fit(x), "Did not find column `\\.is_outlier`") + expect_true(all(is.na(qp_fit(x)$qp$.is_outlier))) +})