ccabdbf78f4853d4e35f45cd0e3b68add911ad4c
[synclust.git] / R / tests / t.connexity.R
1 #bipartite graph
2 test.connexity1 = function()
3 {
4 n = 10
5 NIix = as.list(rep(NA,n))
6 #connect 0 with 1, 2 with 3 ...
7 for (i in 2*(0:(n/2-1)) + 1)
8 {
9 NIix[[i]] = i+1
10 NIix[[i+1]] = i
11 }
12 cc = synclust:::getConnectedComponents(NIix)
13 #cc should contain exactly n/2 integers
14 checkEquals(n/2, length(unique(cc)))
15 }
16
17 #cyclic graph
18 test.connexity2 = function()
19 {
20 n = 10
21 NIix = as.list(rep(NA,n))
22 #connect 0 with 1, 1 with 2 ...
23 for (i in 1:n)
24 NIix[[i]] = c(ifelse(i==1,n,i-1), i%%n+1)
25 cc = synclust:::getConnectedComponents(NIix)
26 #cc should contain only one integer (1)
27 checkEquals(1, length(unique(cc)))
28 }
29
30 #custom graph with 3 connex components
31 test.connexity3 = function()
32 {
33 n = 10
34 NIix = as.list(rep(0,n))
35 NIix[[1]] = c(3,5)
36 NIix[[2]] = c(3,5)
37 NIix[[3]] = c(1,2)
38 NIix[[4]] = c(6,9,10)
39 NIix[[5]] = c(1,2)
40 NIix[[6]] = c(4)
41 NIix[[7]] = c(8)
42 NIix[[8]] = c(7)
43 NIix[[9]] = c(4)
44 NIix[[10]] = c(4,9)
45 cc = synclust:::getConnectedComponents(NIix)
46 #cc should contain only three integers
47 checkEquals(3, length(unique(cc)))
48 }
49
50 #custom graph, 1 connex component
51 test.connexity4 = function()
52 {
53 n = 10
54 NIix = as.list(rep(0,n))
55 NIix[[1]] = c(3,4,8)
56 NIix[[2]] = c(3,5,7)
57 NIix[[3]] = c(1,2)
58 NIix[[4]] = c(1,6,9,10)
59 NIix[[5]] = c(2)
60 NIix[[6]] = c(4,8)
61 NIix[[7]] = c(2)
62 NIix[[8]] = c(1,6,10)
63 NIix[[9]] = c(4)
64 NIix[[10]] = c(4,8)
65 cc = synclust:::getConnectedComponents(NIix)
66 #cc should contain only one integer (1)
67 checkEquals(1, length(unique(cc)))
68 }