-
Notifications
You must be signed in to change notification settings - Fork 55
/
test-DataLayer.R
64 lines (53 loc) · 1.66 KB
/
test-DataLayer.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
dl0 <- new('DataLayer', array(0, dim=c(0, 75, 1)))
dl1 <- new('DataLayer', array(1, c(1, 1, 1), dimnames=list('A'=1,'B'=2, 'C'=3)))
dl <- new('DataLayer', array(1:16, c(2, 4, 2)))
dl2 <- new('DataLayer', array(1:8, c(2, 4, 1)))
mat <- matrix(1:8, nrow=2)
test_that('size zero dl preserves dimensions',{
expect_equal(ncol(dl0), 75)
expect_equal(nlayer(dl0), 1)
expect_equal(nrow(dl0), 0)
})
context('nrow, ncol')
test_that('one by one dl works',{
expect_equal(nrow(dl1), 1)
expect_equal(ncol(dl1), 1)
expect_false(is.null(dimnames(exprs(dl1))))
expect_equal(dim(exprs(dl1)), c(1, 1))
})
test_that('singleton dl works', {
expect_equal(nrow(dl2), 2)
expect_equal(ncol(dl2), 4)
expect_equal(nlayer(dl2), 1)
})
test_that('doubleton dl works', {
expect_equal(exprs(dl), exprs(dl2))
layer(dl) <- 2
expect_false(all(exprs(dl)==exprs(dl2)))
layer(dl) <- 1
})
context('subset and replace')
test_that('subset works', {
expect_equal(dl[[,1]], mat[,1,drop=FALSE], check.names=FALSE)
expect_equal(dl[[1,]], mat[1,,drop=FALSE], check.names=FALSE)
matidx <- cbind(c(1, 1, 2), 1:3)
expect_equal(dl[[matidx]], mat[matidx])
mat[matidx] <- -999
dl[[matidx]] <- -999
expect_equal(exprs(dl), mat, check.attributes=FALSE)
})
test_that('[ subscripting works', {
expect_is(dl[1,], 'DataLayer')
expect_is(dl[,2:3], 'DataLayer')
expect_equal(exprs(dl[1,]), dl[[1,,drop=FALSE]], check.attributes=FALSE)
})
spl <- split(dl, 1:2)
test_that('splitting works', {
expect_is(spl, 'list')
expect_equivalent(exprs(spl[[1]]), dl[[1,,drop=FALSE]])
})
test_that('combine works', {
c <- combine(spl[[1]], spl[[2]])
expect_is(c, 'DataLayer')
expect_equivalent(c, dl)
})