ae5e98f09d86dc99c31d6cb2955fe86459f02a13
1 #include "tests/helpers.h"
2 #include "sources/connexity.h"
4 //completely disconnected graph (no edges)
8 int* lengthNIix
= (int*)calloc(n
,sizeof(int));
9 int** NIix
= (int**)malloc(n
*sizeof(int*));
10 for (int i
=0; i
<n
; i
++) NIix
[i
] = NULL
;
11 int* cc
= getConnectedComponents_core(NIix
, lengthNIix
, n
);
12 //cc should contain all integers from 1 to n
13 ASSERT_TRUE(countDistinctValues(cc
,n
) == n
);
20 void test_connexity2()
23 int* lengthNIix
= (int*)malloc(n
*sizeof(int));
24 int** NIix
= (int**)malloc(n
*sizeof(int*));
25 for (int i
=0; i
<n
; i
++)
28 NIix
[i
] = (int*)malloc(sizeof(int));
30 // connect 0 with 1, 2 with 3 ...
31 for (int i
=0; i
<n
; i
+=2)
36 int* cc
= getConnectedComponents_core(NIix
, lengthNIix
, n
);
37 //cc should contain exactly n/2 integers
38 ASSERT_TRUE(countDistinctValues(cc
,n
) == n
/2);
40 for (int i
=0; i
<n
; i
++)
47 //~ void test_connexity3() {
49 //~ int* adjMat = (int*)calloc(n*n,sizeof(int));
50 //~ // connect 0 with 1, 1 with 2 ...
51 //~ for (int i=0; i<n; i++) {
52 //~ adjMat[i+n*((i+1)%n)] = TRUE;
53 //~ adjMat[(i+1)%n+n*i] = TRUE;
55 //~ int* cc = getConnectedComponents_core(adjMat, n);
56 //~ //cc should contain only one value (presumably '1')
57 //~ warnIfFails(countDistinctValues(cc,n) == 1, "c3", "");
62 //~ //custom graph with 3 connex components
63 //~ void test_connexity4() {
80 //~ 0,0,1,0,1,0,0,0,0,0,
81 //~ 0,0,1,0,1,0,0,0,0,0,
82 //~ 1,1,0,0,0,0,0,0,0,0,
83 //~ 0,0,0,0,0,1,0,0,1,1,
84 //~ 1,1,0,0,0,0,0,0,0,0,
85 //~ 0,0,0,1,0,0,0,1,0,0,
86 //~ 0,0,0,0,0,0,0,0,0,0,
87 //~ 0,0,0,0,0,1,0,0,0,1,
88 //~ 0,0,0,1,0,0,0,0,0,0,
89 //~ 0,0,0,1,0,0,0,1,0,0
91 //~ int* cc = getConnectedComponents_core(adjMat, n);
92 //~ //cc should contain exactly 3 values
93 //~ warnIfFails(countDistinctValues(cc,n) == 3, "c4", "");
97 //~ //custom graph, 1 connex component
98 //~ void test_connexity5() {
100 //~ int adjMat[100] =
102 //~ 0,0,1,1,0,0,0,1,0,0,
103 //~ 0,0,1,0,1,0,1,0,0,0,
104 //~ 1,1,0,0,0,0,0,0,0,0,
105 //~ 1,0,0,0,0,1,0,0,1,1,
106 //~ 0,1,0,0,0,0,0,0,0,0,
107 //~ 0,0,0,1,0,0,0,1,0,0,
108 //~ 0,1,0,0,0,0,0,0,0,0,
109 //~ 1,0,0,0,0,1,0,0,0,1,
110 //~ 0,0,0,1,0,0,0,0,0,0,
111 //~ 0,0,0,1,0,0,0,1,0,0
113 //~ int* cc = getConnectedComponents_core(adjMat, n);
114 //~ //cc should contain only one value (presumably '1')
115 //~ warnIfFails(countDistinctValues(cc,n) == 1, "c5", "");