Switch to unified view

a b/tests/testthat/test-tuneCluster.spca.R
1
context("tuneCluster.spca")
2
3
demo <- suppressWarnings(get_demo_cluster())
4
X <- demo$X
5
tune.spca.res <- tuneCluster.spca(X = X, ncomp = 2, test.keepX = c(2:9))
6
# plot(tune.spca.res)
7
8
pdf(NULL)
9
test_that("tuneCluster.spca failed on invalid input - X", {
10
    expect_error(tuneCluster.spca(X = ""), "X must be a numeric matrix/data.frame", fixed = TRUE)
11
    expect_error(tuneCluster.spca(X = 1), "X must be a numeric matrix/data.frame", fixed = TRUE)
12
    expect_error(tuneCluster.spca(X = NA), "X must be a numeric matrix/data.frame", fixed = TRUE)
13
    expect_error(tuneCluster.spca(X = list()), "X must be a numeric matrix/data.frame", fixed = TRUE)
14
})
15
16
test_that("tuneCluster.spca failed on invalid input - ncomp", {
17
    expect_error(tuneCluster.spca(X = demo$X, ncomp = ""), "'ncomp' should be an integer between 1 and 10", fixed = TRUE)
18
    expect_error(tuneCluster.spca(X = demo$X, ncomp = c(1,2)), "'ncomp' should be an integer between 1 and 10", fixed = TRUE)
19
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 0), "'ncomp' should be an integer between 1 and 10", fixed = TRUE)
20
    # ncomp < nrow(X)
21
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 11),"'ncomp' should be an integer between 1 and 10", fixed = TRUE)
22
})
23
24
test_that("tuneCluster.spca failed on invalid input - keepX", {
25
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 2, test.keepX = c("a",1)), "'test.keepX' should be numeric", fixed = TRUE)
26
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 2, test.keepX = list()), "'test.keepX' should be numeric", fixed = TRUE)
27
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 2, test.keepX = "abc"), "'test.keepX' should be numeric", fixed = TRUE)
28
    expect_error(tuneCluster.spca(X = demo$X, ncomp = 2, test.keepX = matrix(1:9)), "'test.keepX' should be numeric", fixed = TRUE)
29
})
30
31
test_that("tuneCluster.spca works", {
32
    expect_is(tuneCluster.spca(X = X, ncomp = 2, test.keepX = c(5:10)), "spca.tune.silhouette")
33
    expect_is(tuneCluster.spca(X = X, ncomp = 2, test.keepX = NULL), "spca.tune.silhouette")
34
    expect_is(tuneCluster.spca(X = as.data.frame(X), ncomp = 3, test.keepX = c(5:10)), "spca.tune.silhouette")
35
})
36
37
test_that("plot.spca.tune.silhouette works", {
38
    #-- comp
39
    expect_is(plot(tune.spca.res), "ggplot")
40
})
41
dev.off()