Switch to unified view

a b/tests/testthat/test-plotLong.R
1
context("plotLong")
2
3
demo <- suppressWarnings(get_demo_cluster())
4
demo$block.pls2 <- suppressWarnings(mixOmics::block.pls(X=list(X=demo$X, 
5
                                                               Z=demo$Z), 
6
                                                        Y=demo$Y, ncomp = 5, 
7
                                                        mode = "canonical"))
8
9
10
pdf(NULL)
11
test_that("plotLong failed on invalid - object", {
12
    expect_error(plotLong(""), "invalid object, should be one of c(pca, spca, mixo_pls, mixo_spls, block.pls, block.spls)", fixed = TRUE)
13
    expect_error(plotLong(3), "invalid object, should be one of c(pca, spca, mixo_pls, mixo_spls, block.pls, block.spls)", fixed = TRUE)
14
    expect_error(plotLong(matrix()), "invalid object, should be one of c(pca, spca, mixo_pls, mixo_spls, block.pls, block.spls)", fixed = TRUE)    
15
    expect_error(plotLong(list()), "invalid object, should be one of c(pca, spca, mixo_pls, mixo_spls, block.pls, block.spls)", fixed = TRUE)
16
    expect_error(plotLong(data.frame()), "invalid object, should be one of c(pca, spca, mixo_pls, mixo_spls, block.pls, block.spls)", fixed = TRUE)
17
})
18
19
test_that("plotLong failed on invalid - time", {
20
    # pca / spca
21
    expect_error(plotLong(object = demo$pca, time = ""), "'time' should be a numeric vector")
22
    expect_error(plotLong(object = demo$pca, time = 1), "'time' should be a numeric vector")
23
    expect_error(plotLong(object = demo$pca, time = matrix()), "'time' should be a numeric vector")
24
    expect_error(plotLong(object = demo$pca, time = list(1:10)), "'time' should be a numeric vector")
25
    expect_error(plotLong(object = demo$pca, time = data.frame(1:10)), "'time' should be a numeric vector")
26
    expect_error(plotLong(object = demo$pca, time = NA), "'time' should be a numeric vector")
27
    expect_error(plotLong(object = demo$pca, time = 1:9), "'time' should be a numeric vector")
28
    expect_error(plotLong(object = demo$pca, time = 1:11), "'time' should be a numeric vector")
29
30
    # pls / spls
31
    expect_error(plotLong(object = demo$pls, time = ""), "'time' should be a numeric vector")
32
    expect_error(plotLong(object = demo$pls, time = 1), "'time' should be a numeric vector")
33
    expect_error(plotLong(object = demo$pls, time = matrix()), "'time' should be a numeric vector")
34
    expect_error(plotLong(object = demo$pls, time = list(1:10)), "'time' should be a numeric vector")
35
    expect_error(plotLong(object = demo$pls, time = data.frame(1:10)), "'time' should be a numeric vector")
36
    expect_error(plotLong(object = demo$pls, time = NA), "'time' should be a numeric vector")
37
    expect_error(plotLong(object = demo$pls, time = 1:9), "'time' should be a numeric vector")
38
    expect_error(plotLong(object = demo$pls, time = 1:11), "'time' should be a numeric vector")
39
    
40
    # block.pls / block.spls
41
    expect_error(plotLong(object = demo$block.pls, time = ""), "'time' should be a numeric vector")
42
    expect_error(plotLong(object = demo$block.pls, time = 1), "'time' should be a numeric vector")
43
    expect_error(plotLong(object = demo$block.pls, time = matrix()), "'time' should be a numeric vector")
44
    expect_error(plotLong(object = demo$block.pls, time = list(1:10)), "'time' should be a numeric vector")
45
    expect_error(plotLong(object = demo$block.pls, time = data.frame(1:10)), "'time' should be a numeric vector")
46
    expect_error(plotLong(object = demo$block.pls, time = NA), "'time' should be a numeric vector")
47
    expect_error(plotLong(object = demo$block.pls, time = 1:9), "'time' should be a numeric vector")
48
    expect_error(plotLong(object = demo$block.pls, time = 1:11), "'time' should be a numeric vector")
49
})
50
51
test_that("plotLong failed on invalid - legend.block.name", {
52
    expect_error(plotLong(object = demo$pca, legend.block.name = list()))
53
    expect_error(plotLong(object = demo$pca, legend.block.name = matrix()))
54
    expect_error(plotLong(object = demo$pca, legend.block.name = c(1,2)))
55
    expect_error(plotLong(object = demo$pca, legend.block.name = c("a", "b")))
56
  
57
    expect_error(plotLong(object = demo$pls, legend.block.name = c(1,2)))
58
    expect_error(plotLong(object = demo$pls, legend.block.name = c("a")))  
59
    
60
    expect_error(plotLong(object = demo$block.pls, legend.block.name = c(1,2)))
61
    expect_error(plotLong(object = demo$block.pls, legend.block.name = c("a")))
62
})
63
64
65
test_that("plotLong works", {
66
    expect_is(plotLong(object = demo$pca), "data.frame")
67
    expect_is(plotLong(object = demo$spca), "data.frame")
68
    expect_is(plotLong(object = demo$pls), "data.frame")
69
    expect_is(plotLong(object = demo$spls), "data.frame")
70
    expect_is(plotLong(object = demo$block.pls), "data.frame")
71
    expect_is(plotLong(object = demo$block.spls), "data.frame")
72
    expect_is(plotLong(object = demo$block.pls, time=1:10), "data.frame")
73
    
74
    # plot TRUE/FALSE
75
    expect_is(plotLong(object = demo$pca, plot=""), "data.frame")
76
    expect_is(plotLong(object = demo$pca, plot=FALSE), "data.frame")
77
    expect_is(plotLong(object = demo$pca, plot=1), "data.frame")
78
    expect_is(plotLong(object = demo$pca, plot=NULL), "data.frame")
79
    
80
    # scale TRUE/FALSE
81
    expect_is(plotLong(object = demo$pca, scale=""), "data.frame")
82
    expect_is(plotLong(object = demo$pca, scale=FALSE), "data.frame")
83
    expect_is(plotLong(object = demo$pca, scale=1), "data.frame")
84
    expect_is(plotLong(object = demo$pca, scale=NULL), "data.frame")
85
    
86
    # scale TRUE/FALSE
87
    expect_is(plotLong(object = demo$pca, center=""), "data.frame")
88
    expect_is(plotLong(object = demo$pca, center=FALSE), "data.frame")
89
    expect_is(plotLong(object = demo$pca, center=1), "data.frame")
90
    expect_is(plotLong(object = demo$pca, center=NULL), "data.frame")
91
    
92
    # legend TRUE/FALSE
93
    expect_is(plotLong(object = demo$pca, legend=""), "data.frame")
94
    expect_is(plotLong(object = demo$pca, legend=FALSE), "data.frame")
95
    expect_is(plotLong(object = demo$pca, legend=1), "data.frame")
96
    expect_is(plotLong(object = demo$pca, legend=NULL), "data.frame")
97
    
98
    # title string
99
    expect_is(plotLong(object = demo$pca, title=""), "data.frame")
100
    expect_is(plotLong(object = demo$pca, title=FALSE), "data.frame")
101
    expect_is(plotLong(object = demo$pca, title=1), "data.frame")
102
    expect_is(plotLong(object = demo$pca, title=list()), "data.frame")
103
    expect_is(plotLong(object = demo$pca, title=data.frame()), "data.frame")
104
    
105
    # X.label
106
    expect_is(plotLong(object = demo$pca, X.label=""), "data.frame")
107
    expect_is(plotLong(object = demo$pca, X.label=FALSE), "data.frame")
108
    expect_is(plotLong(object = demo$pca, X.label=1), "data.frame")
109
    expect_is(plotLong(object = demo$pca, X.label=list()), "data.frame")
110
    expect_is(plotLong(object = demo$pca, X.label=data.frame()), "data.frame")
111
    
112
    # Y.label
113
    expect_is(plotLong(object = demo$pca, Y.label=""), "data.frame")
114
    expect_is(plotLong(object = demo$pca, Y.label=FALSE), "data.frame")
115
    expect_is(plotLong(object = demo$pca, Y.label=1), "data.frame")
116
    expect_is(plotLong(object = demo$pca, Y.label=list()), "data.frame")
117
    expect_is(plotLong(object = demo$pca, Y.label=data.frame()), "data.frame")
118
    
119
    # legend.title
120
    expect_is(plotLong(object = demo$pca, legend.title=""), "data.frame")
121
    expect_is(plotLong(object = demo$pca, legend.title=FALSE), "data.frame")
122
    expect_is(plotLong(object = demo$pca, legend.title=1), "data.frame")
123
    expect_is(plotLong(object = demo$pca, legend.title=list()), "data.frame")
124
    expect_is(plotLong(object = demo$pca, legend.title=data.frame()), "data.frame")
125
    
126
    expect_is(plotLong(object = demo$pca, legend=TRUE, legend.title=""), "data.frame")
127
    expect_is(plotLong(object = demo$pca, legend=TRUE, legend.title=FALSE), "data.frame")
128
    expect_is(plotLong(object = demo$pca, legend=TRUE, legend.title=1), "data.frame")
129
    expect_is(plotLong(object = demo$pca, legend=TRUE, legend.title=list()), "data.frame")
130
    expect_is(plotLong(object = demo$pca, legend=TRUE, legend.title=data.frame()), "data.frame")
131
    
132
    # legend.block.name
133
    expect_is(plotLong(object = demo$pca, legend.block.name = "pca.X"), "data.frame")
134
    expect_is(plotLong(object = demo$pls, legend.block.name = c("pls.X", "pls.Y")), "data.frame")
135
    expect_is(plotLong(object = demo$block.pls, legend.block.name = c("pls.X", "pls.Y", "pls.Z")), "data.frame")
136
    
137
})
138
dev.off()