First commit
[epclust.git] / pkg / tests / testthat / test-utils.R
1 context("utils functions")
2
3 test_that("Helper function to split indices work properly",
4 {
5 indices <- 1:400
6
7 # bigger nb_per_set than length(indices)
8 expect_equal(epclust:::.splitIndices(indices,500), list(indices))
9
10 # nb_per_set == length(indices)
11 expect_equal(epclust:::.splitIndices(indices,400), list(indices))
12
13 # length(indices) %% nb_per_set == 0
14 expect_equal(epclust:::.splitIndices(indices,200),
15 c( list(indices[1:200]), list(indices[201:400]) ))
16 expect_equal(epclust:::.splitIndices(indices,100),
17 c( list(indices[1:100]), list(indices[101:200]),
18 list(indices[201:300]), list(indices[301:400]) ))
19
20 # length(indices) / nb_per_set == 1, length(indices) %% nb_per_set == 100
21 expect_equal(epclust:::.splitIndices(indices,300,min_size=1),
22 list(1:300, 301:400))
23 split_inds <- epclust:::.splitIndices(indices,300,min_size=200)
24 expect_equal(length(unique(unlist(split_inds))), 400)
25 expect_equal(length(split_inds), 2)
26 expect_equal(length(split_inds[[1]]), 200)
27 expect_equal(length(split_inds[[2]]), 200)
28 expect_error(epclust:::.splitIndices(indices,300,min_size=300), "Impossible to split*")
29
30 # length(indices) / nb_per_set == 2, length(indices) %% nb_per_set == 42
31 expect_equal(epclust:::.splitIndices(indices,179,min_size=1),
32 list(1:179, 180:358, 359:400))
33 split_inds <-epclust:::.splitIndices(indices,179,min_size=60)
34 expect_equal(length(unique(unlist(split_inds))), 400)
35 expect_equal(length(split_inds), 3)
36 expect_equal(length(split_inds[[1]]), 170)
37 expect_equal(length(split_inds[[2]]), 170)
38 expect_equal(length(split_inds[[3]]), 60)
39 expect_error(epclust:::.splitIndices(indices,179,min_size=150), "Impossible to split*")
40 })
41
42 test_that("curvesToContribs output correct results",
43 {
44 L <- 220 #extended to 256, log2(256) == 8
45
46 # Zero serie
47 expect_equal(curvesToContribs(rep(0,L), "d8", "absolute"), as.matrix(rep(0,8)))
48 expect_equal(curvesToContribs(rep(0,L), "haar", "absolute"), as.matrix(rep(0,8)))
49
50 # Constant serie
51 expect_equal(curvesToContribs(rep(5,L), "haar", "absolute"), as.matrix(rep(0,8)))
52 expect_equal(curvesToContribs(rep(10,L), "haar", "absolute"), as.matrix(rep(0,8)))
53 # expect_equal(curvesToContribs(rep(5,L), "d8", ctype), rep(0,8))
54 #TODO:
55 })