1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * IndexSetContainerUnitTest.cpp
|
---|
25 | *
|
---|
26 | * Created on: Jul 3, 2012
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | #include <cppunit/CompilerOutputter.h>
|
---|
38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
40 |
|
---|
41 | #include "Fragmentation/Summation/IndexSetContainer.hpp"
|
---|
42 |
|
---|
43 | #include "IndexSetContainerUnitTest.hpp"
|
---|
44 |
|
---|
45 | #include <boost/assign.hpp>
|
---|
46 | #include <boost/foreach.hpp>
|
---|
47 |
|
---|
48 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
49 |
|
---|
50 | #ifdef HAVE_TESTRUNNER
|
---|
51 | #include "UnitTestMain.hpp"
|
---|
52 | #endif /*HAVE_TESTRUNNER*/
|
---|
53 |
|
---|
54 | using namespace boost::assign;
|
---|
55 |
|
---|
56 | /********************************************** Test classes **************************************/
|
---|
57 |
|
---|
58 | // Registers the fixture into the 'registry'
|
---|
59 | CPPUNIT_TEST_SUITE_REGISTRATION( IndexSetContainerTest );
|
---|
60 |
|
---|
61 |
|
---|
62 | void IndexSetContainerTest::setUp()
|
---|
63 | {
|
---|
64 | allsets.reserve(5);
|
---|
65 | IndexSet tempset;
|
---|
66 | tempset += 1;
|
---|
67 | allsets += tempset;
|
---|
68 | tempset += 2;
|
---|
69 | allsets += tempset;
|
---|
70 | tempset.clear();
|
---|
71 | tempset += 3;
|
---|
72 | allsets += tempset;
|
---|
73 | tempset += 2;
|
---|
74 | allsets += tempset;
|
---|
75 | tempset += 4;
|
---|
76 | allsets += tempset;
|
---|
77 | tempset += 1;
|
---|
78 | allsets += tempset;
|
---|
79 | CPPUNIT_ASSERT_EQUAL( (size_t)6, allsets.size() );
|
---|
80 |
|
---|
81 | SV = NULL;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | void IndexSetContainerTest::tearDown()
|
---|
86 | {
|
---|
87 | allsets.clear();
|
---|
88 | delete SV;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /** UnitTest for constructor
|
---|
92 | */
|
---|
93 | void IndexSetContainerTest::constructorTest()
|
---|
94 | {
|
---|
95 | SV = new IndexSetContainer(allsets);
|
---|
96 | // check that container is sorted
|
---|
97 | const IndexSetContainer::Container_t &container = SV->getContainer();
|
---|
98 | // BOOST_FOREACH( IndexSet_ptr a, container) {
|
---|
99 | // std::cout << *a << "\t";
|
---|
100 | // }
|
---|
101 | // std::cout << endl;
|
---|
102 | CPPUNIT_ASSERT_EQUAL( (size_t)6, container.size() );
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | /** UnitTest for operator==,!=,<,>()
|
---|
107 | */
|
---|
108 | void IndexSetContainerTest::comparatorTest()
|
---|
109 | {
|
---|
110 | SV = new IndexSetContainer(allsets);
|
---|
111 | // check that container is sorted
|
---|
112 | typedef IndexSetContainer::Container_t::const_iterator iterator;
|
---|
113 | const IndexSetContainer::Container_t &container = SV->getContainer();
|
---|
114 | iterator frontiter = ++(container.begin());
|
---|
115 | for (iterator backiter = container.begin();
|
---|
116 | frontiter != container.end(); ++backiter, ++frontiter) {
|
---|
117 | //std::cout << **backiter << " < " << **frontiter << std::endl;
|
---|
118 | CPPUNIT_ASSERT( **backiter < **frontiter );
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | /** Unit tests for insert()
|
---|
123 | *
|
---|
124 | */
|
---|
125 | void IndexSetContainerTest::insertTest()
|
---|
126 | {
|
---|
127 | SV = new IndexSetContainer(allsets);
|
---|
128 | IndexSet_ptr tempset(new IndexSet);
|
---|
129 | (*tempset) += 1,2,3,4;
|
---|
130 |
|
---|
131 | // insert present set and check that it is still sorted
|
---|
132 | CPPUNIT_ASSERT( SV->ContainerSorted );
|
---|
133 | SV->insert(tempset);
|
---|
134 | CPPUNIT_ASSERT( SV->ContainerSorted );
|
---|
135 |
|
---|
136 | // insert new set and check that it is now unsorted
|
---|
137 | (*tempset) += 5;
|
---|
138 | CPPUNIT_ASSERT( SV->ContainerSorted );
|
---|
139 | SV->insert(tempset);
|
---|
140 | CPPUNIT_ASSERT( !SV->ContainerSorted );
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** Unit tests for cstr(KeySetsContainer)
|
---|
144 | *
|
---|
145 | */
|
---|
146 | void IndexSetContainerTest::KeySetContainerTest()
|
---|
147 | {
|
---|
148 | KeySetsContainer keysets;
|
---|
149 | KeySetsContainer::IntVector vector1;
|
---|
150 | vector1 += 1,-1;
|
---|
151 | KeySetsContainer::IntVector vector2;
|
---|
152 | vector2 += -1,1,2,-1;
|
---|
153 | keysets.KeySets.push_back(vector1);
|
---|
154 | keysets.KeySets.push_back(vector2);
|
---|
155 | SV = new IndexSetContainer(keysets);
|
---|
156 |
|
---|
157 | // check sets
|
---|
158 | CPPUNIT_ASSERT_EQUAL( (size_t)2, SV->getContainer().size() );
|
---|
159 | CPPUNIT_ASSERT_EQUAL( (size_t)1, SV->getContainer()[0]->size() );
|
---|
160 | CPPUNIT_ASSERT_EQUAL( (size_t)2, SV->getContainer()[1]->size() );
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 | /** Unit tests for countSetsTillLevel()
|
---|
165 | *
|
---|
166 | */
|
---|
167 | void IndexSetContainerTest::countSetsTillLevelTest()
|
---|
168 | {
|
---|
169 | SV = new IndexSetContainer(allsets);
|
---|
170 |
|
---|
171 | CPPUNIT_ASSERT_EQUAL( (size_t)0, SV->countSetsTillLevel(0) );
|
---|
172 | CPPUNIT_ASSERT_EQUAL( (size_t)2, SV->countSetsTillLevel(1) );
|
---|
173 | CPPUNIT_ASSERT_EQUAL( (size_t)4, SV->countSetsTillLevel(2) );
|
---|
174 | CPPUNIT_ASSERT_EQUAL( (size_t)5, SV->countSetsTillLevel(3) );
|
---|
175 | CPPUNIT_ASSERT_EQUAL( (size_t)6, SV->countSetsTillLevel(4) );
|
---|
176 | CPPUNIT_ASSERT_EQUAL( (size_t)6, SV->countSetsTillLevel(5) );
|
---|
177 | }
|
---|