Coding style cleanup
[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 #include <libstick-0.1/matrixreduction.h>
9
10 using namespace libstick;
11
12
13 class simplicial_complex_TestSuite: public Test::Suite {
14
15 private:
16 typedef simplicial_complex<2, uint32_t, double> scomplex;
17 typedef scomplex::simplex_order::boundary_matrix bm;
18
19 bool setupcalled;
20 scomplex c1, c2, c3;
21 scomplex::simplex_order o1, o2, o3, o3b;
22
23 public:
24 simplicial_complex_TestSuite() :
25 setupcalled(false),
26 o1(c1),
27 o2(c2),
28 o3(c3),
29 o3b(c3)
30 {
31 TEST_ADD(simplicial_complex_TestSuite::test_is_complex);
32 TEST_ADD(simplicial_complex_TestSuite::test_is_monotoneComplex);
33 TEST_ADD(simplicial_complex_TestSuite::test_is_order_filtration);
34 TEST_ADD(simplicial_complex_TestSuite::test_is_order_monotone);
35 TEST_ADD(simplicial_complex_TestSuite::test_boundary_matrix);
36 TEST_ADD(simplicial_complex_TestSuite::test_matrix_reduction);
37 }
38
39 protected:
40 virtual void setup() {
41 if (setupcalled)
42 return;
43 setupcalled = true;
44
45 const unsigned num = 11;
46 scomplex::Simplex ss[num] = {
47 // dimension, faces, value...
48 {0, {}, 1},
49 {0, {}, 2},
50 {0, {}, 3},
51 {0, {}, 4},
52 {1, {1, 2}, 5},
53 {1, {2, 3}, 6},
54 {1, {3, 4}, 7},
55 {1, {4, 1}, 8},
56 {1, {1, 3}, 9},
57 {2, {7, 8, 9}, 10},
58 {2, {5, 6, 9}, 11}
59 };
60
61 // This is o1 This is o2 This is o3(b)
62 // (value = index) (values) (values)
63 //
64 // 1 ----5---- 2 1 ----5---- 2 1 ----5---- 2
65 // |\ | |\ | |\ |
66 // | \ 11 | | \ 11 | | \ 13 |
67 // | \ | | \ | | \ |
68 // | \ | | \ | | \ |
69 // 8 9 6 8 9 12 8 9 12
70 // | \ | | \ | | \ |
71 // | 10 \ | | 10 \ | | 10 \ |
72 // | \ | | \ | | \ |
73 // | \| | \| | \|
74 // 4 ----7---- 3 4 ----7---- 3 4 ----7---- 3
75
76 // Build the complex
77 for (unsigned i=0; i<num; ++i)
78 c1.add_simplex(ss[i]);
79
80 c2 = c1;
81 c2.simplices[6].value = 12;
82
83 c3 = c2;
84 c3.simplices[11].value = 13;
85
86 o1.reset();
87 o2.reset();
88 o3.reset();
89 o3b.reset();
90 o3b.make_monotone_filtration();
91 }
92
93 virtual void tear_down() {
94 }
95
96 void test_is_complex() {
97 TEST_ASSERT(c1.is_complex());
98 TEST_ASSERT(c2.is_complex());
99 TEST_ASSERT(c3.is_complex());
100 }
101
102 void test_is_monotoneComplex() {
103 TEST_ASSERT(c1.is_monotone());
104 TEST_ASSERT(!c2.is_monotone());
105 TEST_ASSERT(c3.is_monotone());
106 }
107
108 void test_is_order_filtration() {
109 TEST_ASSERT(o1.is_filtration());
110 TEST_ASSERT(o2.is_filtration());
111 TEST_ASSERT(o3.is_filtration());
112 TEST_ASSERT(o3b.is_filtration());
113 }
114
115 void test_is_order_monotone() {
116 TEST_ASSERT(o1.is_monotone());
117 TEST_ASSERT(!o2.is_monotone());
118 TEST_ASSERT(!o3.is_monotone());
119 TEST_ASSERT(o3b.is_monotone());
120 }
121
122 void test_boundary_matrix() {
123 bm mat1 = o1.get_boundary_matrix();
124 bm mat1e(c1.size());
125 mat1e.set(0, 1, true);
126 mat1e.set(0, 2, true);
127 mat1e.set(0, 3, true);
128 mat1e.set(0, 4, true);
129 mat1e.set(1, 5, true);
130 mat1e.set(2, 5, true);
131 mat1e.set(2, 6, true);
132 mat1e.set(3, 6, true);
133 mat1e.set(3, 7, true);
134 mat1e.set(4, 7, true);
135 mat1e.set(4, 8, true);
136 mat1e.set(1, 8, true);
137 mat1e.set(1, 9, true);
138 mat1e.set(3, 9, true);
139 mat1e.set(7, 10, true);
140 mat1e.set(8, 10, true);
141 mat1e.set(9, 10, true);
142 mat1e.set(5, 11, true);
143 mat1e.set(6, 11, true);
144 mat1e.set(9, 11, true);
145 TEST_ASSERT(mat1 == mat1e);
146
147 bm mat3b = o3b.get_boundary_matrix();
148 bm mat3be(c1.size());
149 mat3be.set(0, 1, true);
150 mat3be.set(0, 2, true);
151 mat3be.set(0, 3, true);
152 mat3be.set(0, 4, true);
153 mat3be.set(1, 5, true);
154 mat3be.set(2, 5, true);
155 mat3be.set(3, 6, true);
156 mat3be.set(4, 6, true);
157 mat3be.set(4, 7, true);
158 mat3be.set(1, 7, true);
159 mat3be.set(1, 8, true);
160 mat3be.set(3, 8, true);
161 mat3be.set(6, 9, true);
162 mat3be.set(7, 9, true);
163 mat3be.set(8, 9, true);
164 mat3be.set(2, 10, true);
165 mat3be.set(3, 10, true);
166 mat3be.set(5, 11, true);
167 mat3be.set(8, 11, true);
168 mat3be.set(10, 11, true);
169 TEST_ASSERT(mat3b == mat3be);
170
171 //std::cout << mat3b << std::endl << std::endl;
172 //std::cout << mat3be << std::endl << std::endl;
173 //std::cout << ((bm::colbase) mat3b) << std::endl << std::endl;
174 //std::cout << ((bm::rowbase) mat3b) << std::endl << std::endl;
175 }
176
177 void test_matrix_reduction() {
178 bm b = o3b.get_boundary_matrix();
179 bm v = create_unit_matrix<bm>(b.size());
180
181 bm b_orig = b;
182 reduce_boundary_matrix(b, v);
183 TEST_ASSERT(b == b_orig*v);
184
185 //std::cout << std::endl << "after reduce: " << std::endl;
186 //std::cout << std::endl << b << std::endl;
187 //std::cout << std::endl << v << std::endl;
188 //std::cout << std::endl << (b_orig*v) << std::endl;
189 }
190 };
191
192 #endif