Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LiNk-NY committed Aug 8, 2023
1 parent 3d65695 commit 4fcaa2e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 4 additions & 5 deletions R/MultiAssayExperiment-class.R
Expand Up @@ -373,16 +373,15 @@ MultiAssayExperiment <-
sampMap <- sampleMap(object)
assayCols <- mapToList(sampMap[, c("assay", "colname")])
colNams <- Filter(function(x) !isEmpty(x), colnames(object))
msg <- NULL
if (length(colNams)) {
logicResult <- mapply(function(x, y) {
identical(sort(x), sort(y))
}, x = colNams, y = assayCols)
if (all(logicResult))
NULL
else
"not all samples in the ExperimentList are found in the sampleMap"
if (!all(logicResult))
msg <- "not all ExperimentList samples are found in the sampleMap"
}
NULL
msg
}

## COLDATA
Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-MultiAssayExperiment.R
Expand Up @@ -173,3 +173,45 @@ test_that("ExperimentList metadata and mcols are preserved", {
expect_identical(mcols(experiments(mae0)), mcoldf)
expect_identical(metadata(experiments(mae0)), metalist)
})

test_that("sampleMap inputs are checked in MultiAssayExperiment constructor", {
se <- matrix(runif(100), 10, 10)
## empty sampleMap
expect_error(
MultiAssayExperiment(list(foo=se))
)
se <- matrix(runif(12), 3, 4, dimnames = list(letters[1:3], NULL))
asamp <- DataFrame(a = "a", b = "b", c = "c")
expect_error(
MultiAssayExperiment(list(foo=se), sampleMap = asamp)
)
asamp <- DataFrame(assay = factor("foo"), primary = "p1", colname = "col1")
expect_error(
new(
"MultiAssayExperiment",
ExperimentList = ExperimentList(list(foo = se, bar = se)),
sampleMap = asamp
)
)
se <- matrix(runif(100), 10, 10)
expect_error(
new(
"MultiAssayExperiment",
ExperimentList = ExperimentList(list(foo = se)),
sampleMap = DataFrame(
assay = factor(character(), levels = "foo"),
primary = character(),
colname = character()
)
)
)
se <- matrix(runif(2), 1, 2, dimnames = list(letters[1], LETTERS[1:2]))
cd <- DataFrame(score = 1, row.names = "patA")
asamp <- DataFrame(assay = factor("foo"), primary = "patA", colname = "A")
new(
"MultiAssayExperiment",
ExperimentList = ExperimentList(list(foo = se)),
colData = cd,
sampleMap = asamp
)
})

0 comments on commit 4fcaa2e

Please sign in to comment.