Skip to content

Commit

Permalink
Fix issue Bioconductor#20
Browse files Browse the repository at this point in the history
Use `center` argument correctly in tests
  • Loading branch information
const-ae committed Dec 6, 2020
1 parent f997066 commit 4ddd9f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
10 changes: 6 additions & 4 deletions tests/testthat/generate_tests_helper_script.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function_args <- list(x = list("mat"),
diff = list(1, 2),
trim = list(0, 1/3, 0.5),
lx = list("mat"),
col_center = list("NULL", "rep(0.3, ncol(mat))"),
row_center = list("NULL", "rep(0.3, nrow(mat))"),
col_center = list("NULL", "colMeans2(mat, rows = 1:3)"),
row_center = list("NULL", "rowMeans2(mat, cols = 2)"),
constant = list(1.4826, 5),
which = list(2, 1),
method = list("'direct'", "'expSumLog'"),
Expand Down Expand Up @@ -127,8 +127,10 @@ res <- paste0(sapply(testable_functions, function(fnc_name){
} else if (fnc_name == "rowAvgsPerColSet") {
filled_in_args[["FUN"]] <- filled_in_args[["FUN"]][
sapply(filled_in_args[["FUN"]], function(x) grepl("^row", x))]
} else if(fnc_name == "colWeightedMads" || fnc_name == "rowWeightedMads") {
filled_in_args[[paste0(substr(fnc_name, 1, 3), "_center")]][[2]] <- 6
} else if(fnc_name == "colWeightedMads") {
filled_in_args[[paste0(substr(fnc_name, 1, 3), "_center")]][[2]] <- "rep(6, ncol(mat))"
} else if(fnc_name == "rowWeightedMads") {
filled_in_args[[paste0(substr(fnc_name, 1, 3), "_center")]][[2]] <- "rep(6, nrow(mat))"
}
filled_in_args_str <- lapply(seq_along(arg_names), function(idx) paste0(arg_names[idx], " = ", filled_in_args[[idx]]))
param_tests <- paste0(sapply(seq_len(max(lengths(filled_in_args_str))), function(idx){
Expand Down
32 changes: 16 additions & 16 deletions tests/testthat/test-api_compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ test_that("colMads works ", {
ms_res_1 <- matrixStats::colMads(x = mat, rows = NULL, cols = NULL, center = NULL, constant = 1.4826, na.rm = TRUE, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- colMads(x = mat, rows = 1:3, cols = 2, center = rep(0.3, ncol(mat)), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colMads(x = mat, rows = 1:3, cols = 2, center = rep(0.3, ncol(mat)), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
mg_res_2 <- colMads(x = mat, rows = 1:3, cols = 2, center = colMeans2(mat, rows = 1:3), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colMads(x = mat, rows = 1:3, cols = 2, center = colMeans2(mat, rows = 1:3), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down Expand Up @@ -590,8 +590,8 @@ test_that("colSds works ", {
ms_res_1 <- matrixStats::colSds(x = mat, rows = NULL, cols = NULL, na.rm = TRUE, center = NULL, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- colSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, ncol(mat)), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, ncol(mat)), dim. = c(12L, 8L))
mg_res_2 <- colSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = colMeans2(mat, rows = 1:3), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = colMeans2(mat, rows = 1:3), dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down Expand Up @@ -675,8 +675,8 @@ test_that("colVars works ", {
ms_res_1 <- matrixStats::colVars(x = mat, rows = NULL, cols = NULL, na.rm = TRUE, center = NULL, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- colVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, ncol(mat)), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, ncol(mat)), dim. = c(12L, 8L))
mg_res_2 <- colVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = colMeans2(mat, rows = 1:3), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::colVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = colMeans2(mat, rows = 1:3), dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand All @@ -695,8 +695,8 @@ test_that("colWeightedMads works ", {
ms_res_1 <- matrixStats::colWeightedMads(x = mat, w = 1:16, rows = NULL, cols = NULL, na.rm = TRUE, constant = 1.4826, center = NULL)
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- colWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = 6)
ms_res_2 <- matrixStats::colWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = 6)
mg_res_2 <- colWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = rep(6, ncol(mat)))
ms_res_2 <- matrixStats::colWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = rep(6, ncol(mat)))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down Expand Up @@ -1124,8 +1124,8 @@ test_that("rowMads works ", {
ms_res_1 <- matrixStats::rowMads(x = mat, rows = NULL, cols = NULL, center = NULL, constant = 1.4826, na.rm = TRUE, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- rowMads(x = mat, rows = 1:3, cols = 2, center = rep(0.3, nrow(mat)), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowMads(x = mat, rows = 1:3, cols = 2, center = rep(0.3, nrow(mat)), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
mg_res_2 <- rowMads(x = mat, rows = 1:3, cols = 2, center = rowMeans2(mat, cols = 2), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowMads(x = mat, rows = 1:3, cols = 2, center = rowMeans2(mat, cols = 2), constant = 5, na.rm = FALSE, dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down Expand Up @@ -1357,8 +1357,8 @@ test_that("rowSds works ", {
ms_res_1 <- matrixStats::rowSds(x = mat, rows = NULL, cols = NULL, na.rm = TRUE, center = NULL, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- rowSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, nrow(mat)), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, nrow(mat)), dim. = c(12L, 8L))
mg_res_2 <- rowSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rowMeans2(mat, cols = 2), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowSds(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rowMeans2(mat, cols = 2), dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down Expand Up @@ -1442,8 +1442,8 @@ test_that("rowVars works ", {
ms_res_1 <- matrixStats::rowVars(x = mat, rows = NULL, cols = NULL, na.rm = TRUE, center = NULL, dim. = dim(mat))
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- rowVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, nrow(mat)), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rep(0.3, nrow(mat)), dim. = c(12L, 8L))
mg_res_2 <- rowVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rowMeans2(mat, cols = 2), dim. = c(12L, 8L))
ms_res_2 <- matrixStats::rowVars(x = mat, rows = 1:3, cols = 2, na.rm = FALSE, center = rowMeans2(mat, cols = 2), dim. = c(12L, 8L))
expect_equal(mg_res_2, ms_res_2)
})

Expand All @@ -1463,8 +1463,8 @@ test_that("rowWeightedMads works ", {
ms_res_1 <- matrixStats::rowWeightedMads(x = mat, w = 1:16, rows = NULL, cols = NULL, na.rm = TRUE, constant = 1.4826, center = NULL)
expect_equal(mg_res_1, ms_res_1)

mg_res_2 <- rowWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = 6)
ms_res_2 <- matrixStats::rowWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = 6)
mg_res_2 <- rowWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = rep(6, nrow(mat)))
ms_res_2 <- matrixStats::rowWeightedMads(x = mat, w = NULL, rows = 1:3, cols = 2, na.rm = FALSE, constant = 5, center = rep(6, nrow(mat)))
expect_equal(mg_res_2, ms_res_2)
})

Expand Down

0 comments on commit 4ddd9f7

Please sign in to comment.