Add booleanmatrix and simplicialcomplex
[libstick.git] / tests / simplicialcomplex.h
1 #ifndef simplicialcomplex_h_ooDeimaexieghaev
2 #define simplicialcomplex_h_ooDeimaexieghaev
3
4 #include <cpptest.h>
5 #include <cpptest-suite.h>
6
7 #include <libstick-0.1/simplicialcomplex.h>
8
9 using namespace libstick;
10
11
12 class SimplicialComplexTestSuite: public Test::Suite {
13
14 private:
15 typedef SimplicialComplex<2, uint32_t, double> scomplex;
16 typedef scomplex::SimplexOrder::BoundaryMatrix bm;
17
18 bool setupcalled;
19 scomplex c1, c2, c3;
20 scomplex::SimplexOrder o1, o2, o3, o3b;
21
22 public:
23 SimplicialComplexTestSuite() :
24 setupcalled(false),
25 o1(c1),
26 o2(c2),
27 o3(c3),
28 o3b(c3)
29 {
30 TEST_ADD(SimplicialComplexTestSuite::test_isComplex);
31 TEST_ADD(SimplicialComplexTestSuite::test_isMonotoneComplex);
32 TEST_ADD(SimplicialComplexTestSuite::test_isOrderFiltration);
33 TEST_ADD(SimplicialComplexTestSuite::test_isOrderMonotone);
34 TEST_ADD(SimplicialComplexTestSuite::test_boundaryMatrix);
35 }
36
37 protected:
38 virtual void setup() {
39 if (setupcalled)
40 return;
41 setupcalled = true;
42
43 const unsigned num = 11;
44 scomplex::Simplex ss[num] = {
45 // dimension, faces, value...
46 {0, {0, 0, 0}, 0},
47 {0, {0, 0, 0}, 1},
48 {0, {0, 0, 0}, 2},
49 {0, {0, 0, 0}, 3},
50 {1, {0, 1, 0}, 4},
51 {1, {1, 2, 0}, 5},
52 {1, {2, 3, 0}, 6},
53 {1, {3, 0, 0}, 7},
54 {1, {0, 2, 0}, 8},
55 {2, {6, 7, 8}, 9},
56 {2, {4, 5, 8}, 10}
57 };
58
59 // This is o1 This is o2 This is o3(b)
60 // (value = index) (values) (values)
61 //
62 // 0 ----4---- 1 0 ----4---- 1 0 ----4---- 1
63 // |\ | |\ | |\ |
64 // | \ 10 | | \ 10 | | \ 12 |
65 // | \ | | \ | | \ |
66 // | \ | | \ | | \ |
67 // 7 8 5 7 8 11 7 8 11
68 // | \ | | \ | | \ |
69 // | 9 \ | | 9 \ | | 9 \ |
70 // | \ | | \ | | \ |
71 // | \| | \| | \|
72 // 3 ----6---- 2 3 ----6---- 2 3 ----6---- 2
73
74 // Build the complex
75 for (unsigned i=0; i<num; ++i)
76 c1.addSimplex(ss[i]);
77
78 c2 = c1;
79 c2.simplices[5].value = 11;
80
81 c3 = c2;
82 c3.simplices[10].value = 12;
83
84 o1.reset();
85 o2.reset();
86 o3.reset();
87 o3b.reset();
88 o3b.makeMonotoneFiltration();
89 }
90
91 virtual void tear_down() {
92 }
93
94 void test_isComplex() {
95 TEST_ASSERT(c1.isComplex());
96 TEST_ASSERT(c2.isComplex());
97 TEST_ASSERT(c3.isComplex());
98 }
99
100 void test_isMonotoneComplex() {
101 TEST_ASSERT(c1.isMonotone());
102 TEST_ASSERT(!c2.isMonotone());
103 TEST_ASSERT(c3.isMonotone());
104 }
105
106 void test_isOrderFiltration() {
107 TEST_ASSERT(o1.isFiltration());
108 TEST_ASSERT(o2.isFiltration());
109 TEST_ASSERT(o3.isFiltration());
110 TEST_ASSERT(o3b.isFiltration());
111 }
112
113 void test_isOrderMonotone() {
114 TEST_ASSERT(o1.isMonotone());
115 TEST_ASSERT(!o2.isMonotone());
116 TEST_ASSERT(!o3.isMonotone());
117 TEST_ASSERT(o3b.isMonotone());
118 }
119
120 void test_boundaryMatrix() {
121 bm mat1 = o1.getBoundaryMatrix();
122 bm mat1e(c1.size());
123 mat1e.set(0, 4, true);
124 mat1e.set(1, 4, true);
125 mat1e.set(1, 5, true);
126 mat1e.set(2, 5, true);
127 mat1e.set(2, 6, true);
128 mat1e.set(3, 6, true);
129 mat1e.set(3, 7, true);
130 mat1e.set(0, 7, true);
131 mat1e.set(0, 8, true);
132 mat1e.set(2, 8, true);
133 mat1e.set(6, 9, true);
134 mat1e.set(7, 9, true);
135 mat1e.set(8, 9, true);
136 mat1e.set(4, 10, true);
137 mat1e.set(5, 10, true);
138 mat1e.set(8, 10, true);
139 TEST_ASSERT(mat1 == mat1e);
140
141 bm mat3b = o3b.getBoundaryMatrix();
142 bm mat3be(c1.size());
143 mat3be.set(0, 4, true);
144 mat3be.set(1, 4, true);
145 mat3be.set(2, 5, true);
146 mat3be.set(3, 5, true);
147 mat3be.set(3, 6, true);
148 mat3be.set(0, 6, true);
149 mat3be.set(0, 7, true);
150 mat3be.set(2, 7, true);
151 mat3be.set(5, 8, true);
152 mat3be.set(6, 8, true);
153 mat3be.set(7, 8, true);
154 mat3be.set(1, 9, true);
155 mat3be.set(2, 9, true);
156 mat3be.set(4, 10, true);
157 mat3be.set(7, 10, true);
158 mat3be.set(9, 10, true);
159
160 //std::cout << mat3b << std::endl << std::endl;
161 //std::cout << ((bm::colbase) mat3b) << std::endl << std::endl;
162 //std::cout << ((bm::rowbase) mat3b) << std::endl << std::endl;
163
164 TEST_ASSERT(mat3b == mat3be);
165 }
166 };
167
168 #endif