]> git.sthu.org Git - libstick.git/blob - tests/booleanmatrix.h
Remove obsolete ::reduce_boundary_matrix()
[libstick.git] / tests / booleanmatrix.h
1 #ifndef booleanmatrix_h_ohYeiveiKanashie
2 #define booleanmatrix_h_ohYeiveiKanashie
3
4 #include <cpptest.h>
5 #include <cpptest-suite.h>
6
7 #include <libstick-0.1/booleanmatrix.h>
8
9 using namespace libstick;
10
11
12 class boolean_matrix_TestSuite: public Test::Suite {
13 public:
14 boolean_matrix_TestSuite() {
15 TEST_ADD(boolean_matrix_TestSuite::test_getsetsize<boolean_rowmatrix<> >);
16 TEST_ADD(boolean_matrix_TestSuite::test_getsetsize<boolean_colmatrix<> >);
17 TEST_ADD(boolean_matrix_TestSuite::test_getsetsize<boolean_colrowmatrix<> >);
18
19 TEST_ADD(boolean_matrix_TestSuite::test_addgetcolumn<boolean_colmatrix<> >);
20 TEST_ADD(boolean_matrix_TestSuite::test_addgetcolumn<boolean_colrowmatrix<> >);
21
22 TEST_ADD(boolean_matrix_TestSuite::test_addgetrow<boolean_rowmatrix<> >);
23 TEST_ADD(boolean_matrix_TestSuite::test_addgetrow<boolean_colrowmatrix<> >);
24 }
25
26 protected:
27 virtual void setup() {
28 }
29
30 virtual void tear_down() {
31 }
32
33 private:
34 template<typename T>
35 void test_getsetsize() {
36 const unsigned size = 17;
37 T mat(size);
38
39 // Must all be zero
40 for (unsigned r=0; r < size; ++r)
41 for (unsigned c=0; c < size; ++c)
42 TEST_ASSERT(mat.get(r, c) == false);
43
44 // Set a few of them one
45 for (unsigned r=0; r < size; ++r)
46 for (unsigned c=0; c < size; ++c)
47 if ((257*c + 65537*r + 7)%11 == 0)
48 mat.set(r, c, true);
49
50 // Check if they are one
51 for (unsigned r=0; r < size; ++r)
52 for (unsigned c=0; c < size; ++c)
53 TEST_ASSERT(((257*c + 65537*r + 7)%11 == 0) == mat.get(r, c))
54 }
55
56 template<typename T>
57 void test_addgetcolumn() {
58 const unsigned size = 17;
59 T mat(size);
60 typename T::column_type col;
61
62 // Check if columns are empty
63 for (unsigned c=0; c < size; ++c)
64 TEST_ASSERT(mat.get_column(c).size() == 0);
65
66 col.push_back(0);
67 col.push_back(3);
68 col.push_back(8);
69 col.push_back(14);
70
71 // Add column and test for values
72 mat.add_column(5, col);
73 for (unsigned c=0; c < size; ++c) {
74 if (c==5) {
75 for (unsigned r=0; r < size; ++r )
76 TEST_ASSERT(mat.get(r,c) == (r==0 || r==3 || r==8 || r==14));
77 } else {
78 TEST_ASSERT(mat.get_column(c).size() == 0);
79 }
80 }
81 }
82
83 template<typename T>
84 void test_addgetrow() {
85 const unsigned size = 17;
86 T mat(size);
87 typename T::row_type row;
88
89 // Check if rows are empty
90 for (unsigned r=0; r < size; ++r)
91 TEST_ASSERT(mat.get_row(r).size() == 0);
92
93 row.push_back(0);
94 row.push_back(8);
95 row.push_back(14);
96 row.push_back(3);
97
98 // Add row and test for values
99 mat.add_row(5, row);
100 for (unsigned r=0; r < size; ++r) {
101 if (r==5) {
102 for (unsigned c=0; c < size; ++c )
103 TEST_ASSERT(mat.get(r,c) == (c==0 || c==3 || c==8 || c==14));
104 } else {
105 TEST_ASSERT(mat.get_row(r).size() == 0);
106 }
107 }
108 }
109 };
110
111 #endif