Skip to content

Commit

Permalink
test: add some qp_fit unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki committed Nov 4, 2023
1 parent 1ee1109 commit e8f90c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/qp_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-qp_fit.R
Original file line number Diff line number Diff line change
@@ -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)))
})

0 comments on commit e8f90c2

Please sign in to comment.