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