1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2016 Frederik Heber. 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 | * FragmentForcesUnitTest.cpp
|
---|
25 | *
|
---|
26 | * Created on: Aug 18, 2016
|
---|
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 headers that implement a archive in simple text format
|
---|
42 | #include <boost/archive/text_oarchive.hpp>
|
---|
43 | #include <boost/archive/text_iarchive.hpp>
|
---|
44 |
|
---|
45 | #include "FragmentForcesUnitTest.hpp"
|
---|
46 |
|
---|
47 | #include <algorithm>
|
---|
48 | #include <limits>
|
---|
49 |
|
---|
50 | #include <boost/assign.hpp>
|
---|
51 | #include <boost/foreach.hpp>
|
---|
52 |
|
---|
53 | #include <sstream>
|
---|
54 |
|
---|
55 | #include "CodePatterns/Assert.hpp"
|
---|
56 |
|
---|
57 | #ifdef HAVE_TESTRUNNER
|
---|
58 | #include "UnitTestMain.hpp"
|
---|
59 | #endif /*HAVE_TESTRUNNER*/
|
---|
60 |
|
---|
61 | using namespace boost::assign;
|
---|
62 |
|
---|
63 | #include "Fragmentation/Summation/SetValues/FragmentForces.hpp"
|
---|
64 |
|
---|
65 | /********************************************** Test classes **************************************/
|
---|
66 |
|
---|
67 | // Registers the fixture into the 'registry'
|
---|
68 | CPPUNIT_TEST_SUITE_REGISTRATION( FragmentForcesTest );
|
---|
69 |
|
---|
70 |
|
---|
71 | void FragmentForcesTest::setUp()
|
---|
72 | {
|
---|
73 | // failing asserts should be thrown
|
---|
74 | ASSERT_DO(Assert::Throw);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void FragmentForcesTest::tearDown()
|
---|
78 | {
|
---|
79 | }
|
---|
80 |
|
---|
81 | /** UnitTest for operator==()
|
---|
82 | */
|
---|
83 | void FragmentForcesTest::equality_Test()
|
---|
84 | {
|
---|
85 | // create different forces
|
---|
86 | FragmentForces::force_t zeroforce;
|
---|
87 | zeroforce += 0., 0., 0.;
|
---|
88 | FragmentForces::force_t oneforce;
|
---|
89 | oneforce += 1., 2., 3.;
|
---|
90 | FragmentForces::force_t twoforce;
|
---|
91 | twoforce += 0., 1., 4.;
|
---|
92 |
|
---|
93 | FragmentForces emptyfragment;
|
---|
94 | FragmentForces fragment;
|
---|
95 | fragment += oneforce;
|
---|
96 | fragment += twoforce;
|
---|
97 | FragmentForces samefragment;
|
---|
98 | samefragment += oneforce;
|
---|
99 | samefragment += twoforce;
|
---|
100 | FragmentForces otherfragment;
|
---|
101 | otherfragment += twoforce;
|
---|
102 | otherfragment += twoforce;
|
---|
103 | FragmentForces largerfragment;
|
---|
104 | largerfragment += oneforce;
|
---|
105 | largerfragment += oneforce;
|
---|
106 | largerfragment += oneforce;
|
---|
107 | FragmentForces smallerfragment;
|
---|
108 | smallerfragment += oneforce;
|
---|
109 |
|
---|
110 | // test against different instance with same contents
|
---|
111 | CPPUNIT_ASSERT( (fragment == samefragment) );
|
---|
112 | CPPUNIT_ASSERT( !(fragment != samefragment) );
|
---|
113 |
|
---|
114 | // test against other fragment
|
---|
115 | CPPUNIT_ASSERT( !(fragment == otherfragment) );
|
---|
116 | CPPUNIT_ASSERT( fragment != otherfragment );
|
---|
117 |
|
---|
118 | // test against larger fragment
|
---|
119 | CPPUNIT_ASSERT( !(fragment == largerfragment) );
|
---|
120 | CPPUNIT_ASSERT( fragment != largerfragment );
|
---|
121 |
|
---|
122 | // test against smaller fragment
|
---|
123 | CPPUNIT_ASSERT( !(fragment == smallerfragment) );
|
---|
124 | CPPUNIT_ASSERT( fragment != smallerfragment );
|
---|
125 |
|
---|
126 | // test against empty
|
---|
127 | CPPUNIT_ASSERT( !(fragment == emptyfragment) );
|
---|
128 | CPPUNIT_ASSERT( fragment != emptyfragment );
|
---|
129 |
|
---|
130 | // tests against themselves
|
---|
131 | CPPUNIT_ASSERT( fragment == fragment );
|
---|
132 | CPPUNIT_ASSERT( samefragment == samefragment );
|
---|
133 | CPPUNIT_ASSERT( otherfragment == otherfragment );
|
---|
134 | CPPUNIT_ASSERT( largerfragment == largerfragment );
|
---|
135 | CPPUNIT_ASSERT( smallerfragment == smallerfragment );
|
---|
136 | CPPUNIT_ASSERT( emptyfragment == emptyfragment );
|
---|
137 | }
|
---|
138 |
|
---|
139 | /** UnitTest for operator+=()
|
---|
140 | */
|
---|
141 | void FragmentForcesTest::operatorPlusEqual_Test()
|
---|
142 | {
|
---|
143 | // create different forces
|
---|
144 | FragmentForces::force_t zeroforce;
|
---|
145 | zeroforce += 0., 0., 0.;
|
---|
146 | FragmentForces::force_t oneforce;
|
---|
147 | oneforce += 1., 2., 3.;
|
---|
148 | FragmentForces::force_t twoforce;
|
---|
149 | twoforce += 0., 1., 4.;
|
---|
150 | FragmentForces::force_t resultforce;
|
---|
151 | resultforce += 1., 3., 7.;
|
---|
152 |
|
---|
153 | FragmentForces fragment;
|
---|
154 | fragment += oneforce;
|
---|
155 | fragment += oneforce;
|
---|
156 | FragmentForces otherfragment;
|
---|
157 | otherfragment += twoforce;
|
---|
158 | otherfragment += twoforce;
|
---|
159 | FragmentForces resultfragment;
|
---|
160 | resultfragment += resultforce;
|
---|
161 | resultfragment += resultforce;
|
---|
162 |
|
---|
163 | FragmentForces sumfragment = fragment;
|
---|
164 | sumfragment.operator+=(otherfragment);
|
---|
165 | CPPUNIT_ASSERT( sumfragment == resultfragment);
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** UnitTest for operator+=() with different number of components
|
---|
169 | */
|
---|
170 | void FragmentForcesTest::operatorPlusEqual_NonOverlapping_Test()
|
---|
171 | {
|
---|
172 | // create different forces
|
---|
173 | FragmentForces::force_t zeroforce;
|
---|
174 | zeroforce += 0., 0., 0.;
|
---|
175 | FragmentForces::force_t surplusforce;
|
---|
176 | surplusforce += 0., 0., 0., 1.;
|
---|
177 | FragmentForces::force_t oneforce;
|
---|
178 | oneforce += 1., 2., 3.;
|
---|
179 | FragmentForces::force_t twoforce;
|
---|
180 | twoforce += 0., 1., 4.;
|
---|
181 | FragmentForces::force_t resultforce;
|
---|
182 | resultforce += 1., 3., 7.;
|
---|
183 |
|
---|
184 | FragmentForces fragment;
|
---|
185 | fragment += oneforce;
|
---|
186 | fragment += oneforce;
|
---|
187 | FragmentForces otherfragment;
|
---|
188 | otherfragment += twoforce;
|
---|
189 | FragmentForces surplusfragment;
|
---|
190 | surplusfragment += surplusforce;
|
---|
191 | surplusfragment += twoforce;
|
---|
192 |
|
---|
193 | {
|
---|
194 | FragmentForces sumfragment = fragment;
|
---|
195 | #ifndef NDEBUG
|
---|
196 | std::cout << "The following assertion is expected and does not mean a failure of the test." << std::endl;
|
---|
197 | CPPUNIT_ASSERT_THROW( (sumfragment.operator+=(otherfragment)) ,Assert::AssertionFailure);
|
---|
198 | #endif
|
---|
199 | }
|
---|
200 | {
|
---|
201 | FragmentForces sumfragment = fragment;
|
---|
202 | #ifndef NDEBUG
|
---|
203 | std::cout << "The following assertion is expected and does not mean a failure of the test." << std::endl;
|
---|
204 | CPPUNIT_ASSERT_THROW( (sumfragment.operator+=(surplusfragment)) ,Assert::AssertionFailure);
|
---|
205 | #endif
|
---|
206 | }
|
---|
207 | }
|
---|