Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed Oct 30, 2024
1 parent 7aef504 commit e824414
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion R/clonalCompare.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ clonalCompare <- function(input.data,
}

compareColname <- ifelse(proportion, "Proportion", "Count")
normalizer <- ifelse(proportion, sum, length)

Con.df <- input.data %>%
purrr::imap(function(df, columnNames) {
tbl <- as.data.frame(table(df[, cloneCall]))
if (proportion) {
tbl[, 2] <- tbl[, 2] / sum(tbl[, 2])
tbl[, 2] <- tbl[, 2] / normalizer(tbl[, 2])
}
colnames(tbl) <- c("clones", compareColname)
tbl$Sample <- columnNames
Expand Down
26 changes: 21 additions & 5 deletions tests/testthat/test-clonalCompare.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,28 @@ test_that("clonalCompare works with exportTable and prop FALSE", {
)
}

clonalCompareCountConvertedToProp <- getClonalCompareRes(FALSE) %>%
dplyr::mutate(Count = Count / length(Count)) %>% #FIXME this is wrong
dplyr::rename(Proportion = Count)
countCompareRes <- getClonalCompareRes(prop = FALSE)
propCompareRes <- getClonalCompareRes(prop = TRUE)

expect_identical(
getClonalCompareRes(TRUE),
clonalCompareCountConvertedToProp
countCompareRes %>% dplyr::select(-Count),
propCompareRes %>% dplyr::select(-Proportion)
)

fullJoined <- getClonalCompareRes(FALSE) %>%
dplyr::full_join(
getClonalCompareRes(TRUE)
)

expect_setequal(
colnames(fullJoined),
c("clones", "Count", "original.clones", "Proportion", "Sample")
)

countPropFactor <- fullJoined$Count / fullJoined$Proportion

expect_identical(
as.integer(fullJoined$Count - fullJoined$Proportion * countPropFactor),
integer(nrow(fullJoined))
)
})

0 comments on commit e824414

Please sign in to comment.