]> git.sthu.org Git - libstick.git/blob - tests/simplicialcomplex.h
Updating pkg-config file
[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 simplicial_complex_TestSuite: public Test::Suite {
13
14 private:
15 typedef simplicial_complex<3, uint32_t, double> scomplex;
16 typedef scomplex::simplex_order::boundary_matrix bm;
17
18 bool setupcalled;
19 scomplex c1, c2, c3;
20 scomplex::simplex_order o1, o2, o3, o3b;
21
22 public:
23 simplicial_complex_TestSuite() :
24 setupcalled(false),
25 o1(c1),
26 o2(c2),
27 o3(c3),
28 o3b(c3)
29 {
30 TEST_ADD(simplicial_complex_TestSuite::test_is_complex);
31 TEST_ADD(simplicial_complex_TestSuite::test_is_monotoneComplex);
32 TEST_ADD(simplicial_complex_TestSuite::test_is_order_filtration);
33 TEST_ADD(simplicial_complex_TestSuite::test_is_order_monotone);
34 TEST_ADD(simplicial_complex_TestSuite::test_boundary_matrix);
35 }
36
37 protected:
38 virtual void setup() {
39 if (setupcalled)
40 return;
41 setupcalled = true;
42
43 scomplex::simplex ss[] = {
44 // dimension, faces, value...
45 {0, {}, 1},
46 {0, {}, 2},
47 {0, {}, 3},
48 {0, {}, 4},
49 {1, {1, 2}, 5},
50 {1, {2, 3}, 6},
51 {1, {3, 4}, 7},
52 {1, {4, 1}, 8},
53 {1, {1, 3}, 9},
54 {2, {7, 8, 9}, 10},
55 {2, {5, 6, 9}, 11}
56 };
57 const size_t cntss = sizeof(ss)/sizeof(scomplex::simplex);
58 c1.add_simplices(ss, cntss);
59
60 // This is o1 This is o2 This is o3(b)
61 // (value = index) (values) (values)
62 //
63 // 1 ----5---- 2 1 ----5---- 2 1 ----5---- 2
64 // |\ | |\ | |\ |
65 // | \ 11 | | \ 11 | | \ 13 |
66 // | \ | | \ | | \ |
67 // | \ | | \ | | \ |
68 // 8 9 6 8 9 12 8 9 12
69 // | \ | | \ | | \ |
70 // | 10 \ | | 10 \ | | 10 \ |
71 // | \ | | \ | | \ |
72 // | \| | \| | \|
73 // 4 ----7---- 3 4 ----7---- 3 4 ----7---- 3
74
75 c2 = c1;
76 c2.simplices[6].value = 12;
77
78 c3 = c2;
79 c3.simplices[11].value = 13;
80
81 o1.reset();
82 o2.reset();
83 o3.reset();
84 o3b.reset();
85 o3b.make_monotone_filtration();
86 }
87
88 virtual void tear_down() {
89 }
90
91 void test_is_complex() {
92 TEST_ASSERT(c1.is_complex());
93 TEST_ASSERT(c2.is_complex());
94 TEST_ASSERT(c3.is_complex());
95 }
96
97 void test_is_monotoneComplex() {
98 TEST_ASSERT(c1.is_monotone());
99 TEST_ASSERT(!c2.is_monotone());
100 TEST_ASSERT(c3.is_monotone());
101 }
102
103 void test_is_order_filtration() {
104 TEST_ASSERT(o1.is_filtration());
105 TEST_ASSERT(o2.is_filtration());
106 TEST_ASSERT(o3.is_filtration());
107 TEST_ASSERT(o3b.is_filtration());
108 }
109
110 void test_is_order_monotone() {
111 TEST_ASSERT(o1.is_monotone());
112 TEST_ASSERT(!o2.is_monotone());
113 TEST_ASSERT(!o3.is_monotone());
114 TEST_ASSERT(o3b.is_monotone());
115 }
116
117 void test_boundary_matrix() {
118 bm mat1 = o1.get_boundary_matrix();
119 bm mat1e(c1.size());
120 uint32_t mat1e_coords[][2] = {
121 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 5}, {2, 5}, {2, 6}, {3, 6}, {3, 7}, {4, 7}, {1, 8}, {4, 8},
122 {1, 9}, {3, 9}, {7, 10}, {8, 10}, {9, 10}, {5, 11}, {6, 11}, {9, 11}
123 };
124 mat1e.set_all(mat1e_coords, sizeof(mat1e_coords)/(2*sizeof(uint32_t)), true);
125 TEST_ASSERT(mat1 == mat1e);
126
127
128 bm mat3b = o3b.get_boundary_matrix();
129 bm mat3be(c1.size());
130 uint32_t mat3be_coords[][2] = {
131 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 5}, {2, 5}, {3, 6}, {4, 6}, {1, 7}, {4, 7}, {1, 8}, {3, 8},
132 {6, 9}, {7, 9}, {8, 9}, {2, 10}, {3, 10}, {5, 11}, {8, 11}, {10, 11}
133 };
134 mat3be.set_all(mat3be_coords, sizeof(mat3be_coords)/(2*sizeof(uint32_t)), true);
135 TEST_ASSERT(mat3b == mat3be);
136
137 //std::cout << mat3b << std::endl << std::endl;
138 //std::cout << mat3be << std::endl << std::endl;
139 //std::cout << ((bm::colbase) mat3b) << std::endl << std::endl;
140 //std::cout << ((bm::rowbase) mat3b) << std::endl << std::endl;
141 }
142 };
143
144 #endif