Skip to content

Commit

Permalink
begin testing clanc-fit
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki committed Jul 21, 2024
1 parent d630b57 commit d4e8224
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/clanc-fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ clanc.SummarizedExperiment <- function(x,
cd_names <- colnames(SummarizedExperiment::colData(x))

if (!spec_in_cd(classes, cd_names) &&
(spec_in_cd(priors, cd_names) || spec_in_cd(active, cd_names))) {
((!priors %in% c("equal", "class") && (spec_in_cd(priors, cd_names))) ||
spec_in_cd(active, cd_names))) {
cli::cli_abort(
"`classes` must be specified as a column name in colData if `active` or `priors` are." #nolint
)
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-clanc-fit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("catch unsupported types", {
expect_error(clanc(numeric()))
})

test_that("catch bad args", {
library(SummarizedExperiment)
assay <- matrix(1:4, nrow = 2)
cd <- DataFrame(a = c("one", "two"), active = c(3, 4), prior = c(0.5, 0.5))
rd <- DataFrame(gene = c("g1", "g2"))
se <- SummarizedExperiment(assay, rowData = rd, colData = cd)
expect_error(clanc(se, classes = "b"))
expect_error(clanc(se, active = "active", classes = c("one", "two")))
expect_error(clanc(se, priors = "prior", classes = c("one", "two")))
# Too many attributes per class:
assay <- matrix(1:6, nrow = 2)
cd <- DataFrame(a = c("one", "two", "one"), active = c(3, 4, 2), prior = c(0.5, 0.5, 0.5))
rd <- DataFrame(gene = c("g1", "g2"))
se <- SummarizedExperiment(assay, rowData = rd, colData = cd)
expect_error(
clanc(se, classes = "a", active = "active", priors = "prior"),
"More than one prior"
)
})

0 comments on commit d4e8224

Please sign in to comment.