]>
git.sthu.org Git - libstick.git/blob - tests/booleanmatrix.h
1 #ifndef booleanmatrix_h_ohYeiveiKanashie
2 #define booleanmatrix_h_ohYeiveiKanashie
5 #include <cpptest-suite.h>
7 #include <libstick-0.1/booleanmatrix.h>
9 using namespace libstick
;
12 class boolean_matrix_TestSuite
: public Test::Suite
{
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
<> >);
19 TEST_ADD(boolean_matrix_TestSuite::test_addgetcolumn
<boolean_colmatrix
<> >);
20 TEST_ADD(boolean_matrix_TestSuite::test_addgetcolumn
<boolean_colrowmatrix
<> >);
22 TEST_ADD(boolean_matrix_TestSuite::test_addgetrow
<boolean_rowmatrix
<> >);
23 TEST_ADD(boolean_matrix_TestSuite::test_addgetrow
<boolean_colrowmatrix
<> >);
27 virtual void setup() {
30 virtual void tear_down() {
35 void test_getsetsize() {
36 const unsigned size
= 17;
40 for (unsigned r
=0; r
< size
; ++r
)
41 for (unsigned c
=0; c
< size
; ++c
)
42 TEST_ASSERT(mat
.get(r
, c
) == false);
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)
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
))
57 void test_addgetcolumn() {
58 const unsigned size
= 17;
60 typename
T::column_type col
;
62 // Check if columns are empty
63 for (unsigned c
=0; c
< size
; ++c
)
64 TEST_ASSERT(mat
.get_column(c
).size() == 0);
71 // Add column and test for values
72 mat
.add_column(5, col
);
73 for (unsigned c
=0; c
< size
; ++c
) {
75 for (unsigned r
=0; r
< size
; ++r
)
76 TEST_ASSERT(mat
.get(r
,c
) == (r
==0 || r
==3 || r
==8 || r
==14));
78 TEST_ASSERT(mat
.get_column(c
).size() == 0);
84 void test_addgetrow() {
85 const unsigned size
= 17;
87 typename
T::row_type row
;
89 // Check if rows are empty
90 for (unsigned r
=0; r
< size
; ++r
)
91 TEST_ASSERT(mat
.get_row(r
).size() == 0);
98 // Add row and test for values
100 for (unsigned r
=0; r
< size
; ++r
) {
102 for (unsigned c
=0; c
< size
; ++c
)
103 TEST_ASSERT(mat
.get(r
,c
) == (c
==0 || c
==3 || c
==8 || c
==14));
105 TEST_ASSERT(mat
.get_row(r
).size() == 0);