]> ruin.nu Git - germs.git/blob - src/test/genesortertest.cpp
setting up things for implementing the sorting
[germs.git] / src / test / genesortertest.cpp
1 #include <cppunit/TestFixture.h>
2 #include <cppunit/extensions/HelperMacros.h>
3
4 #include <genesorter.h>
5 #include <geneorder.h>
6 #include <genealgorithms.h>
7 #include <reverseaction.h>
8
9 #include <algorithm>
10 #include <iterator>
11 using namespace std;
12
13 /* 
14  * A test case that is designed to produce
15  * example errors and failures.
16  *
17  */
18
19 #define TESTNAME GeneSorterTest
20
21
22 class TESTNAME : public CPPUNIT_NS::TestFixture
23 {
24   CPPUNIT_TEST_SUITE( TESTNAME );
25   CPPUNIT_TEST( testCreate );
26   CPPUNIT_TEST( testSafeActions );
27   CPPUNIT_TEST( testSort );
28   CPPUNIT_TEST_SUITE_END();
29
30 protected:
31                 vector<int> _validPerm;
32                 vector<int> _validPerm2;
33                 vector<int> _validPerm3;
34                 vector<int> _validPerm4;
35
36 public:
37
38         void setUp (){
39                 int validPerm[] = {1,2,3,4};
40                 _validPerm.assign(validPerm,validPerm+4);
41                 int validPerm2[] = {1,-3,-2,4};
42                 _validPerm2.assign(validPerm2,validPerm2+4);
43                 int validPerm3[] = {0,-2,-1,4,3,5,-8,6,7,9};
44                 _validPerm3.assign(validPerm3,validPerm3+10);
45                 int validPerm4[] = {-3,1,2,4,6,5,7,-15,-13,-14,-12,-10,-11,-9,8};
46                 _validPerm4.assign(validPerm4,validPerm4+15);
47
48         }
49
50 protected:
51
52         void testCreate (){
53                 GeneSorter so;
54                 so = so;
55         }
56         void testSort (){
57                 GeneSorter so;
58                 GeneOrder go(_validPerm.begin(),_validPerm.end());
59                 GeneSorter::ActionList al = so.sort(go);
60                 CPPUNIT_ASSERT_EQUAL(0ul,al.size());
61
62                 GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
63                 al = so.sort(go2);
64                 CPPUNIT_ASSERT_EQUAL(1ul,al.size());
65                 CPPUNIT_ASSERT(al[0] == ReverseAction(2,3));
66
67                 GeneOrder go3(_validPerm3.begin(),_validPerm3.end());
68                 al = so.sort(go3);
69                 CPPUNIT_ASSERT_EQUAL(5ul,al.size());
70         }
71         void testSafeActions (){
72                 GeneSorter so;
73                 GeneOrder go(_validPerm.begin(),_validPerm.end());
74                 GeneSorter::ActionList al = so.safeActions(go);
75                 CPPUNIT_ASSERT_EQUAL(0ul,al.size());
76
77                 GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
78                 al = so.safeActions(go2);
79                 CPPUNIT_ASSERT_EQUAL(1ul,al.size());
80                 CPPUNIT_ASSERT(al[0] == ReverseAction(2,3));
81         }
82
83 };
84
85 CPPUNIT_TEST_SUITE_REGISTRATION( TESTNAME );
86
87 #undef TESTNAME