### make_c3c2() -----------------------------------------------------
context("Test make_c3c2()")
file <- system.file("extdata", "PureHoney_Carnitines.RDS", package = "assayr2")
samps <- readRDS(file)
test_that("inputs of NULL fail", {
expect_error(make_c3c2(NULL))
})
test_that("missing required columns will fail", {
bad <- samps
bad["plate_id"] <- NULL
expect_error(make_c3c2(bad))
})
test_that("NA sample IDs will fail", {
bad <- samps
bad$sample_id[1] <- NA
expect_error(make_c3c2(bad))
})
test_that("requred analytes are present", {
bad <- samps
bad$target <- "12C-Acetyl-Car"
expect_error(make_c3c2(bad))
})
test_that("samples are uniquely identified", {
bad <- samps
bad$row <- "A"
bad$sample_id <- 1
expect_error(make_c3c2(bad))
})
test_that("it works", {
result <- make_c3c2(samps)
expect_true(is.data.frame(result))
expect_true("12C-C3-C2-ratio-Car" %in% unique(result$target))
expect_true("C3-C2-ratio-Car" %in% unique(result$curve_plot))
})
test_that("it works with 13C-Propionyl", {
result <- make_c3c2(samps, propionyl_species = "13C")
expect_true(is.data.frame(result))
expect_true("13C-C3-C2-ratio-Car" %in% unique(result$target))
expect_true("C3-C2-ratio-Car" %in% unique(result$curve_plot))
})
# apply_curve_pairs -------------------------------------------------------
samps$curve_id <- NULL
samps$plate_run <- NULL
curve_pairs <- c("12C-Acetyl-Car" = "13C-Acetyl-Car",
"12C-Propionyl-Car" = "13C-Propionyl-Car")
test_that("inputs of NULL to 'data' fail", {
expect_error(apply_curve_matches(NULL, curve_pairs))
})
test_that("inputs of NULL to 'curve_pairs' work", {
expect_silent(apply_curve_matches(samps, NULL))
})
result <- apply_curve_matches(samps, curve_pairs)
test_that("New columns are added", {
expect_true(all(c("curve_id", "plate_run") %in% names(result)))
})
test_that("New values are correct", {
expect_true(all(c("2042_ONE_13C-Acetyl-Car", "2042_ONE_13C-Propionyl-Car") %in% unique(result$curve_id)))
expect_true(all(c("2042_ONE", "2042_ONE") %in% unique(result$plate_run)))
})
test_that("Specifying 'plate_id' works", {
result <- apply_curve_matches(samps, curve_pairs, plate_id = 1)
expect_true(all(c("1_ONE_13C-Acetyl-Car", "1_ONE_13C-Propionyl-Car") %in% unique(result$curve_id)))
expect_true(all(c("1_ONE") %in% unique(result$plate_run)))
})
test_that("Specifying 'prun' works", {
result <- apply_curve_matches(samps, curve_pairs, prun = "FOO")
expect_true(all(c("2042_FOO_13C-Acetyl-Car", "2042_FOO_13C-Propionyl-Car") %in% unique(result$curve_id)))
expect_true(all(c("2042_FOO") %in% unique(result$plate_run)))
})
rm(samps, file)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.