Add booleanmatrix and simplicialcomplex
[libstick.git] / tests / simplicialcomplex.h
diff --git a/tests/simplicialcomplex.h b/tests/simplicialcomplex.h
new file mode 100644 (file)
index 0000000..fa829e1
--- /dev/null
@@ -0,0 +1,168 @@
+#ifndef simplicialcomplex_h_ooDeimaexieghaev
+#define simplicialcomplex_h_ooDeimaexieghaev
+
+#include <cpptest.h>
+#include <cpptest-suite.h>
+
+#include <libstick-0.1/simplicialcomplex.h>
+
+using namespace libstick;
+
+
+class SimplicialComplexTestSuite: public Test::Suite {
+
+    private:
+        typedef SimplicialComplex<2, uint32_t, double> scomplex;
+        typedef scomplex::SimplexOrder::BoundaryMatrix bm;
+
+        bool setupcalled;
+        scomplex c1, c2, c3;
+        scomplex::SimplexOrder o1, o2, o3, o3b;
+
+    public:
+        SimplicialComplexTestSuite() :
+            setupcalled(false),
+            o1(c1),
+            o2(c2),
+            o3(c3),
+            o3b(c3)
+            {
+            TEST_ADD(SimplicialComplexTestSuite::test_isComplex);
+            TEST_ADD(SimplicialComplexTestSuite::test_isMonotoneComplex);
+            TEST_ADD(SimplicialComplexTestSuite::test_isOrderFiltration);
+            TEST_ADD(SimplicialComplexTestSuite::test_isOrderMonotone);
+            TEST_ADD(SimplicialComplexTestSuite::test_boundaryMatrix);
+        }
+
+    protected:
+        virtual void setup() {
+            if (setupcalled)
+                return;
+            setupcalled = true;
+
+            const unsigned num = 11;
+            scomplex::Simplex ss[num] = {
+                // dimension, faces, value...
+                {0, {0, 0, 0}, 0},
+                {0, {0, 0, 0}, 1},
+                {0, {0, 0, 0}, 2},
+                {0, {0, 0, 0}, 3},
+                {1, {0, 1, 0}, 4},
+                {1, {1, 2, 0}, 5},
+                {1, {2, 3, 0}, 6},
+                {1, {3, 0, 0}, 7},
+                {1, {0, 2, 0}, 8},
+                {2, {6, 7, 8}, 9},
+                {2, {4, 5, 8}, 10}
+            };
+
+            //  This is o1        This is o2         This is o3(b)
+            //  (value = index)   (values)           (values)
+            //
+            //  0  ----4---- 1    0  ----4---- 1     0  ----4---- 1
+            //  |\           |    |\           |     |\           |
+            //  |  \     10  |    |  \     10  |     |  \     12  |
+            //  |    \       |    |    \       |     |    \       |
+            //  |      \     |    |      \     |     |      \     |
+            //  7       8    5    7       8    11    7       8    11
+            //  |        \   |    |        \   |     |        \   |
+            //  |   9     \  |    |   9     \  |     |   9     \  |
+            //  |          \ |    |          \ |     |          \ |
+            //  |           \|    |           \|     |           \|
+            //  3  ----6---- 2    3  ----6---- 2     3  ----6---- 2
+
+            // Build the complex
+            for (unsigned i=0; i<num; ++i)
+                c1.addSimplex(ss[i]);
+
+            c2 = c1;
+            c2.simplices[5].value = 11;
+
+            c3 = c2;
+            c3.simplices[10].value = 12;
+
+            o1.reset();
+            o2.reset();
+            o3.reset();
+            o3b.reset();
+            o3b.makeMonotoneFiltration();
+        }
+
+        virtual void tear_down() {
+        }
+
+        void test_isComplex() {
+            TEST_ASSERT(c1.isComplex());
+            TEST_ASSERT(c2.isComplex());
+            TEST_ASSERT(c3.isComplex());
+        }
+
+        void test_isMonotoneComplex() {
+            TEST_ASSERT(c1.isMonotone());
+            TEST_ASSERT(!c2.isMonotone());
+            TEST_ASSERT(c3.isMonotone());
+        }
+
+        void test_isOrderFiltration() {
+            TEST_ASSERT(o1.isFiltration());
+            TEST_ASSERT(o2.isFiltration());
+            TEST_ASSERT(o3.isFiltration());
+            TEST_ASSERT(o3b.isFiltration());
+        }
+
+        void test_isOrderMonotone() {
+            TEST_ASSERT(o1.isMonotone());
+            TEST_ASSERT(!o2.isMonotone());
+            TEST_ASSERT(!o3.isMonotone());
+            TEST_ASSERT(o3b.isMonotone());
+        }
+
+        void test_boundaryMatrix() {
+            bm mat1 = o1.getBoundaryMatrix();
+            bm mat1e(c1.size());
+            mat1e.set(0, 4, true);
+            mat1e.set(1, 4, true);
+            mat1e.set(1, 5, true);
+            mat1e.set(2, 5, true);
+            mat1e.set(2, 6, true);
+            mat1e.set(3, 6, true);
+            mat1e.set(3, 7, true);
+            mat1e.set(0, 7, true);
+            mat1e.set(0, 8, true);
+            mat1e.set(2, 8, true);
+            mat1e.set(6, 9, true);
+            mat1e.set(7, 9, true);
+            mat1e.set(8, 9, true);
+            mat1e.set(4, 10, true);
+            mat1e.set(5, 10, true);
+            mat1e.set(8, 10, true);
+            TEST_ASSERT(mat1 == mat1e);
+
+            bm mat3b = o3b.getBoundaryMatrix();
+            bm mat3be(c1.size());
+            mat3be.set(0, 4, true);
+            mat3be.set(1, 4, true);
+            mat3be.set(2, 5, true);
+            mat3be.set(3, 5, true);
+            mat3be.set(3, 6, true);
+            mat3be.set(0, 6, true);
+            mat3be.set(0, 7, true);
+            mat3be.set(2, 7, true);
+            mat3be.set(5, 8, true);
+            mat3be.set(6, 8, true);
+            mat3be.set(7, 8, true);
+            mat3be.set(1, 9, true);
+            mat3be.set(2, 9, true);
+            mat3be.set(4, 10, true);
+            mat3be.set(7, 10, true);
+            mat3be.set(9, 10, true);
+
+            //std::cout << mat3b << std::endl << std::endl;
+            //std::cout << ((bm::colbase) mat3b) << std::endl << std::endl;
+            //std::cout << ((bm::rowbase) mat3b) << std::endl << std::endl;
+
+            TEST_ASSERT(mat3b == mat3be);
+        }
+};
+
+#endif