|
a |
|
b/tests/testthat/test-tuneCluster.spls.R |
|
|
1 |
context("tuneCluster.spls") |
|
|
2 |
|
|
|
3 |
demo <- suppressWarnings(get_demo_cluster()) |
|
|
4 |
X <- demo$X |
|
|
5 |
Y <- demo$Y |
|
|
6 |
res <- spls(X, Y, ncomp = 10) |
|
|
7 |
#tune.spls <- tuneCluster.spls(X, Y, ncomp = 2, test.keepX = c(5,10,15,20), test.keepY <- c(2,4,6)) |
|
|
8 |
|
|
|
9 |
test_that("tuneCluster.spls failed on invalid input - X", { |
|
|
10 |
#-- X must be a numeric matrix/data.frame |
|
|
11 |
expect_error(tuneCluster.spls(X = ""), "X must be a numeric matrix/data.frame") |
|
|
12 |
expect_error(tuneCluster.spls(X = list()), "X must be a numeric matrix/data.frame") |
|
|
13 |
expect_error(tuneCluster.spls(X = NULL), "X must be a numeric matrix/data.frame") |
|
|
14 |
expect_error(tuneCluster.spls(X = NA), "X must be a numeric matrix/data.frame") |
|
|
15 |
expect_error(tuneCluster.spls(X = matrix(letters[1:9], ncol = 3)), "X must be a numeric matrix/data.frame") |
|
|
16 |
}) |
|
|
17 |
|
|
|
18 |
test_that("tuneCluster.spls failed on invalid input - X", { |
|
|
19 |
#-- X must be a numeric matrix/data.frame |
|
|
20 |
expect_error(tuneCluster.spls(X = demo$X, Y = ""), "Y must be a numeric matrix/data.frame") |
|
|
21 |
expect_error(tuneCluster.spls(X = demo$X, Y = list()), "Y must be a numeric matrix/data.frame") |
|
|
22 |
expect_error(tuneCluster.spls(X = demo$X, Y = NULL), "Y must be a numeric matrix/data.frame") |
|
|
23 |
expect_error(tuneCluster.spls(X = demo$X, Y = NA), "Y must be a numeric matrix/data.frame") |
|
|
24 |
expect_error(tuneCluster.spls(X = demo$X, Y = matrix(letters[1:9], ncol = 3)), "Y must be a numeric matrix/data.frame") |
|
|
25 |
}) |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
test_that("tuneCluster.spls failed on invalid input - ncomp", { |
|
|
29 |
#-- ncomp // integer |
|
|
30 |
expect_error(tuneCluster.spls(X = X, Y = Y, ncomp = NULL), "'ncomp' should be an integer between 1 and 10", fixed = TRUE) |
|
|
31 |
expect_error(tuneCluster.spls(X = X, Y = Y, ncomp = "abc"), "'ncomp' should be an integer between 1 and 10", fixed = TRUE) |
|
|
32 |
expect_error(tuneCluster.spls(X = X, Y = Y, ncomp = X), "'ncomp' should be an integer between 1 and 10", fixed = TRUE) |
|
|
33 |
expect_error(tuneCluster.spls(X = X, Y = Y, ncomp = 55), "'ncomp' should be an integer between 1 and 10", fixed = TRUE) |
|
|
34 |
}) |
|
|
35 |
|
|
|
36 |
test_that("tuneCluster.spls failed on invalid input - test.keepX", { |
|
|
37 |
#-- test.keepX // numeric vecter lower than ncol(X) |
|
|
38 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepX = "abc"), "'test.keepX' should be numeric") |
|
|
39 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepX = NA), "'test.keepX' should be numeric") |
|
|
40 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepX = matrix()), "'test.keepX' should be numeric") |
|
|
41 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepX = list()), "'test.keepX' should be numeric") |
|
|
42 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepX = c(1,2,101)), "'test.keepX' must be lower than 100, ncol(X)", fixed=TRUE) |
|
|
43 |
}) |
|
|
44 |
|
|
|
45 |
test_that("tuneCluster.spls failed on invalid input - test.keepY", { |
|
|
46 |
#-- test.keepX // numeric vecter lower than ncol(X) |
|
|
47 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepY = "abc"), "'test.keepY' should be numeric") |
|
|
48 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepY = NA), "'test.keepY' should be numeric") |
|
|
49 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepY = matrix()), "'test.keepY' should be numeric") |
|
|
50 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepY = list()), "'test.keepY' should be numeric") |
|
|
51 |
expect_error(tuneCluster.spls(X = X, Y = Y, test.keepY = c(1,2,101)), "'test.keepY' must be lower than 10, ncol(Y)", fixed=TRUE) |
|
|
52 |
}) |
|
|
53 |
|
|
|
54 |
test_that("tuneCluster.spls works", { |
|
|
55 |
#-- test.keepX // numeric vecter lower than ncol(X) |
|
|
56 |
expect_is(tuneCluster.spls(X = X, Y = Y), "spls.tune.silhouette") |
|
|
57 |
expect_is(tuneCluster.spls(X = X, Y = Y, ncomp = 1), "spls.tune.silhouette") |
|
|
58 |
expect_is(tuneCluster.spls(X = X, Y = Y, ncomp = 3), "spls.tune.silhouette") |
|
|
59 |
expect_is(tuneCluster.spls(X = X, Y = Y, ncomp = 3, test.keepX = NULL, test.keepY = NULL), "spls.tune.silhouette") |
|
|
60 |
expect_is(tuneCluster.spls(X = X, Y = Y, ncomp = 2, test.keepX = c(1,2)), "spls.tune.silhouette") |
|
|
61 |
}) |