tests/testthat/test_HSTexplorer_QC.R

context("QC checks for DRC curves in HST Explorer")
library(magrittr)
## LL4 QC Warnings --------------------------------------------------------
data("isobutyryl_curves")

error_code <- suppressWarnings(ll4_qc_warnings(isobutyryl_curves[[5]]))

test_that("ll4_qc_warnings_returns_correct_code", {
  expect_equal(error_code, "7,9")
})

# Detect Outliers ---------------------------------------------------------

data("detect_outliers_positive_cases")
data("detect_outliers_negative_cases")

test_that("test_detect_outliers_labels_cases_correctly", {
  expect_true(all(purrr::map_lgl(detect_outliers_positive_cases, ~detect_outliers(., threshold = 0.1))))
  expect_false(all(purrr::map_lgl(detect_outliers_negative_cases, ~detect_outliers(., threshold = 0.1))))
})

# LL4 Parameter Overlap ---------------------------------------------------

data("curves")

model <- curves$standard_model[[1]]

robust_model <- curves$standard_model[[1]] %>%
  robustify_drc(form = as.formula(log10_data ~ standard_conc))

test_that("ll4_robust_parameter_overlap returns a boolean vector", {
  expect_false(ll4_robust_parameter_overlap(model, robust_model))
})


test_that("ll4_robust_parameter_overlap handles missing robust fit", {
  expect_false(ll4_robust_parameter_overlap(model))
})

# Noisy Curve -------------------------------------------------------------

data("nrmsd_qc_negative_cases")
data("nrmsd_qc_positive_cases")

test_that("nrmsd_qc_negative_cases", {
  expect_true(all(purrr::map_lgl(nrmsd_qc_positive_cases, nrmsd_qc)))
})

test_that("acceptable_ic50_estimates_labeled_correctly", {
  expect_false(all(purrr::map_lgl(nrmsd_qc_negative_cases, nrmsd_qc)))
})

# Poor IC50 Estimate ------------------------------------------------------

data("poor_ic50_estimate_negative_cases")
data("poor_ic50_estimate_positive_cases")

test_that("poor_ic50_estimates_labeled_correctly", {
  expect_true(all(purrr::map_lgl(poor_ic50_estimate_positive_cases, ~poor_ic50_estimate(., "upper"))))
})

test_that("acceptable_ic50_estimates_labeled_correctly", {
  expect_false(all(purrr::map_lgl(poor_ic50_estimate_negative_cases, ~poor_ic50_estimate(., "upper"))))
})

# Unbounded Parameter -----------------------------------------------------

data("unbounded_parameter_ci_test_case")
unbounded_parameter_ci_test_case <- unbounded_parameter_ci_test_case[[1]]

test_that("unbounded_parameter_labels_cases_correctly", {
  expect_true(unbounded_parameter_ci_test_case %>% unbounded_parameter_ci(parameter = "ic50"))
  expect_false(unbounded_parameter_ci_test_case %>% unbounded_parameter_ci(parameter = "upper"))
})

# Unsaturated Curve -------------------------------------------------------

data("unsaturated_curve_negative_cases")
data("unsaturated_curve_positive_cases")

test_that("unsaturated_curve_identifies_positive_case", {
  expect_true(all(purrr::map_lgl(unsaturated_curve_positive_cases, ~unsaturated_curve(.))))
})

test_that("unsaturated_curve_identifies_negative_case", {
  expect_false(all(purrr::map_lgl(unsaturated_curve_negative_cases, ~unsaturated_curve(.))))
})
detach("package:magrittr")
hemoshear/assayr2 documentation built on Nov. 8, 2019, 6:13 p.m.