Skip to content

Commit

Permalink
Added test for intersection utility,
Browse files Browse the repository at this point in the history
Also protect against differences in the number of rows between the
test and reference datasets when no intersection is performed.
  • Loading branch information
LTLA committed Oct 26, 2024
1 parent 1520a39 commit 67247e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/trainSingleR.R
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ trainSingleR <- function(
}

if (is.null(test.genes)) {
stopifnot(nrow(test) == nrow(ref))
test.genes <- ref.genes <- seq_len(nrow(ref))
} else {
intersection <- .create_intersection(test.genes, rownames(ref))
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# library(testthat); library(SingleR); source("test-utils.R")

test_that("intersection works as expected for edge cases", {
out <- SingleR:::.create_intersection(c("A", "B", "C", "a"), LETTERS)
expect_identical(out$test, 1:3)
expect_identical(out$reference, 1:3)

out <- SingleR:::.create_intersection(c("a", "Z", "b", "G", "c", "B", "d"), LETTERS)
expect_identical(out$test, c(2L, 4L, 6L))
expect_identical(out$reference, c(26L, 7L, 2L))

out <- SingleR:::.create_intersection(c("y", "y", "x", "z", NA, "z", "x"), letters)
expect_identical(out$test, c(1L, 3L, 4L))
expect_identical(out$reference, c(25L, 24L, 26L))
})

0 comments on commit 67247e7

Please sign in to comment.