Skip to content

Commit

Permalink
Failing test for YuLab-SMU#282
Browse files Browse the repository at this point in the history
Issue is that match.call doesn't capture default arguments. See https://stackoverflow.com/questions/14397364/match-call-with-default-arguments
  • Loading branch information
amcdavid committed Oct 28, 2021
1 parent d166b87 commit 29b764f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/testthat/test-compareCluster.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
context("Test compareCluster")

data(gcSample)
gc_small = gcSample[c("X1", "X2", 'X4')]
test_that("compareCluster + KEGG no formula", {
result = compareCluster(gc_small, fun="enrichKEGG",
organism="hsa", pvalueCutoff=0.05)
expect_is(result, 'compareClusterResult')
})


test_that("compareCluster + KEGG + formula", {
gc_small_dat = do.call(rbind,
lapply(names(gc_small),
function(x) data.frame(X = x, entrezID = gc_small[[x]], stringsAsFactors = FALSE)
))
result = compareCluster(entrezID ~ X, data = gc_small_dat, fun="enrichKEGG",
organism="hsa", pvalueCutoff=0.05)
expect_is(result, 'compareClusterResult')
})

test_that("compareCluster + GO no formula", {
result = compareCluster(gc_small, fun="enrichGO", OrgDb = "org.Hs.eg.db",
pvalueCutoff=0.05)
expect_is(result, 'compareClusterResult')
})

test_that("compareCluster + GO no formula, default value for function", {
result = compareCluster(gc_small, OrgDb = "org.Hs.eg.db",
pvalueCutoff=0.05)
expect_is(result, 'compareClusterResult')
})
22 changes: 22 additions & 0 deletions tests/testthat/test-extract_params.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
context("Test extract_params")

test_function = function(x, y, z = 'z'){
this_call = match.call(expand.dots = TRUE)
return(extract_params(this_call))
}

test_that("Can extract position parameters", {
params = test_function(1, 2, 3)
expect_equal(params, list(x = "1", y = "2", z = "3"))
# note these are coerced to character, might not be desirable..
})

test_that("Can extract keyword parameters", {
params = test_function(x = 1, z = 3, y = 2)
expect_equal(params, list(x = "1", y = "2", z = "3"))
})

test_that("Can extract default parameters", {
params = test_function(x = 1, y = 2)
expect_equal(params, list(x = "1", y = "2", z = "z"))
})

0 comments on commit 29b764f

Please sign in to comment.