Skip to content

Commit

Permalink
add getWithColData unit tests with shuffled rows
Browse files Browse the repository at this point in the history
  • Loading branch information
LiNk-NY committed Apr 29, 2024
1 parent 162d9fa commit 52ed1e3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/testthat/test-MultiAssayExperiment-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test_that("getWithColData works", {
drop = FALSE]
expect_identical(cDataMatch, matchedData)

## Empty MAE colData return assay colData
## Empty MAE colData return assay colData for append
MAE0 <- MAE
colData(MAE0) <- DataFrame(row.names = rownames(colData(MAE0)))
cData <- colData(getWithColData(MAE0, 1L, "append"))
Expand All @@ -158,6 +158,7 @@ test_that("getWithColData works", {
colData(se1)
)

## Empty MAE colData return assay colData for replace
MAE0 <- MAE
colData(MAE0) <- DataFrame(row.names = rownames(colData(MAE0)))
cData <- colData(getWithColData(MAE0, 1L, "replace"))
Expand All @@ -168,6 +169,32 @@ test_that("getWithColData works", {
)
expect_true( isEmpty(cData) )


## Shuffled rows in MAE colData for append
MAE0 <- MAE
colData(MAE0) <- colData(MAE0)[sample(nrow(colData(MAE0))), ]
cData <- colData(getWithColData(MAE0, 1L, "append"))
cDataMatch <- cData[, names(colData(MAE0)), drop = FALSE]
matchedData <- colData(MAE0)[
match(
mapToList(sampleMap)[[1]][["primary"]], rownames(colData(MAE0))
), , drop = FALSE]
matchedData <- matchedData[order(rownames(matchedData)), ]
testres <- unlist(
Map(function(x, y) { identical(x, y) }, x = cDataMatch, y = matchedData)
)
expect_true( all(testres) )

## Shuffled rows in MAE colData for replace
MAE0 <- MAE
colData(MAE0) <- colData(MAE0)[sample(nrow(colData(MAE0))), ]
cData <- colData(getWithColData(MAE0, 1L, "replace"))
matchedData <- colData(MAE0)[
match(
mapToList(sampleMap)[[1]][["primary"]], rownames(colData(MAE0))
), , drop = FALSE]
expect_identical(cData, matchedData)

## Empty assay colData return MAE colData
MAE0 <- MAE
eCol <- DataFrame(row.names = rownames(colData(MAE0[["rnaseq"]])))
Expand Down

0 comments on commit 52ed1e3

Please sign in to comment.