source: src/Shapes/unittests/ShapeOpsUnitTest.cpp@ 6253ed

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 6253ed was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-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 * ShapeOpsUnitTest.cpp
25 *
26 * Created on: Jun 18, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include <cmath>
40#include <limits>
41
42#ifdef HAVE_TESTRUNNER
43#include "UnitTestMain.hpp"
44#endif /*HAVE_TESTRUNNER*/
45
46#include "CodePatterns/Assert.hpp"
47
48#include "Helpers/defs.hpp"
49#include "LinearAlgebra/RealSpaceMatrix.hpp"
50#include "LinearAlgebra/Vector.hpp"
51#include "Shapes/BaseShapes.hpp"
52#include "Shapes/Shape.hpp"
53#include "Shapes/ShapeOps.hpp"
54
55#include "ShapeOpsUnitTest.hpp"
56
57// Registers the fixture into the 'registry'
58CPPUNIT_TEST_SUITE_REGISTRATION( ShapeOpsTest );
59
60void ShapeOpsTest::setUp()
61{
62 // failing asserts should be thrown
63 ASSERT_DO(Assert::Throw);
64}
65
66void ShapeOpsTest::tearDown()
67{}
68
69void ShapeOpsTest::resizeTest()
70{
71 Shape s = resize(Sphere(), 2.);
72
73 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
74 CPPUNIT_ASSERT( s.isInside( Vector(0.,1.5,0.) ) );
75 CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,1.5) ) );
76 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
77 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,2.,0.) ) );
78 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,2.) ) );
79}
80
81void ShapeOpsTest::translateTest()
82{
83 Shape s = translate(Sphere(), Vector(1.,0.,0.));
84
85 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
86 CPPUNIT_ASSERT( s.isInside( Vector(1.,.5,0.) ) );
87 CPPUNIT_ASSERT( s.isInside( Vector(1.,0.,.5) ) );
88 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
89 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,1.,0.) ) );
90 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,1.) ) );
91 CPPUNIT_ASSERT( !s.isInside( Vector(-.5,0.,0.) ) );
92 CPPUNIT_ASSERT( !s.isInside( Vector(0.,-.5,0.) ) );
93 CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,-.5) ) );
94}
95
96void ShapeOpsTest::stretchTest()
97{
98#ifndef NDEBUG
99 CPPUNIT_ASSERT_THROW( Shape test = stretch(Sphere(), Vector(-2.,0.,0.)), Assert::AssertionFailure );
100#endif
101 Shape s = stretch(Sphere(), Vector(2.,1.,1.));
102
103 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
104 CPPUNIT_ASSERT( !s.isInside( Vector(0.,1.5,0.) ) );
105 CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,1.5) ) );
106 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
107 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
108 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
109}
110
111void ShapeOpsTest::transformTest()
112{
113 RealSpaceMatrix M;
114 M.setRotation(45., 0., 0.);
115 Shape s = transform(Sphere(), M);
116
117 CPPUNIT_ASSERT( s.isInside( Vector(.5,0.,0.) ) );
118 CPPUNIT_ASSERT( s.isInside( Vector(0.,.5,0.) ) );
119 CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,.5) ) );
120 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,0.) ) );
121 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
122 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,1.) ) );
123}
124
125void ShapeOpsTest::getCenterTest()
126{
127 Shape s = Sphere();
128 Shape t = Sphere(Vector(2.,0.,0.),1.);
129 Vector offset(1.,0.,0);
130 RealSpaceMatrix M;
131 M.setRotation(45.,0.,0.);
132
133 // Sphere
134 {
135 // sphere at origin
136 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), s.getCenter() );
137
138 // translated sphere
139 CPPUNIT_ASSERT_EQUAL( offset, translate(s, offset).getCenter() );
140
141 // resized sphere
142 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), resize(s, 2.).getCenter() );
143
144 // stretched sphere
145 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), stretch(s, Vector(2.,1.,1.)).getCenter() );
146
147 // transformed sphere
148 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), transform(s, M).getCenter() );
149
150 // resized and translated sphere
151 CPPUNIT_ASSERT_EQUAL( offset, translate(resize(s, 2.), offset).getCenter() );
152 }
153
154 // AND spheres
155 {
156 // sphere at origin
157 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (s && t).getCenter() );
158
159 // translated sphere
160 CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate((s && t), offset).getCenter() );
161
162 // resized sphere
163 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), resize((s && t), 2.).getCenter() );
164
165 // stretched sphere
166 CPPUNIT_ASSERT_EQUAL( Vector(1.5,0.,0), (stretch(s, Vector(2.,1.,1.)) && t).getCenter() );
167
168 // transformed sphere
169 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (transform(s, M) && t).getCenter() );
170
171 // resized and translated sphere
172 CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate(resize((s && t), 2.), offset).getCenter() );
173 }
174
175 // OR spheres
176 {
177 // sphere at origin
178 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (s || t).getCenter() );
179
180 // translated sphere
181 CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate((s || t), offset).getCenter() );
182
183 // resized sphere
184 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), resize((s || t), 2.).getCenter() );
185
186 // stretched sphere
187 CPPUNIT_ASSERT_EQUAL( Vector(0.5,0.,0), (stretch(s, Vector(2.,1.,1.)) || t).getCenter() );
188
189 // transformed sphere
190 CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (transform(s, M) || t).getCenter() );
191
192 // resized and translated sphere
193 CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate(resize((s || t), 2.), offset).getCenter() );
194 }
195
196 // NOT spheres
197 {
198 // sphere at origin
199 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), (!s).getCenter() );
200 }
201}
202
203void ShapeOpsTest::getRadiusTest()
204{
205 Shape s = Sphere();
206 Shape t = Sphere(Vector(2.,0.,0.),1.);
207 Vector offset(1.,0.,0);
208 RealSpaceMatrix M;
209 M.setRotation(45.,0.,0.);
210
211 // Sphere
212 {
213 // sphere at origin
214 CPPUNIT_ASSERT_EQUAL( 1., s.getRadius() );
215
216 // translated sphere
217 CPPUNIT_ASSERT_EQUAL( 1., translate(s, offset).getRadius() );
218
219 // resized sphere
220 CPPUNIT_ASSERT_EQUAL( 2., resize(s, 2.).getRadius() );
221
222 // stretched sphere
223 CPPUNIT_ASSERT_EQUAL( 2., stretch(s, Vector(2.,1.,1.)).getRadius() );
224
225 // transformed sphere
226 CPPUNIT_ASSERT_EQUAL( 1., transform(s, M).getRadius() );
227
228 // resized and translated sphere
229 CPPUNIT_ASSERT_EQUAL( 2., translate(resize(s, 2.), offset).getRadius() );
230 }
231
232 // AND spheres
233 {
234 // sphere at origin
235 CPPUNIT_ASSERT_EQUAL( 1., (s && t).getRadius() );
236
237 // translated sphere
238 CPPUNIT_ASSERT_EQUAL( 1., translate((s && t), offset).getRadius() );
239
240 // resized sphere
241 CPPUNIT_ASSERT_EQUAL( 2., resize((s && t), 2.).getRadius() );
242
243 // stretched sphere
244 CPPUNIT_ASSERT_EQUAL( 1., (stretch(s, Vector(2.,1.,1.)) && t).getRadius() );
245
246 // transformed sphere
247 CPPUNIT_ASSERT_EQUAL( 1., (transform(s, M) && t).getRadius() );
248
249 // resized and translated sphere
250 CPPUNIT_ASSERT_EQUAL( 2., translate(resize((s && t), 2.), offset).getRadius() );
251 }
252
253 // OR spheres
254 {
255 // sphere at origin
256 CPPUNIT_ASSERT_EQUAL( 2., (s || t).getRadius() );
257
258 // translated sphere
259 CPPUNIT_ASSERT_EQUAL( 2., translate((s || t), offset).getRadius() );
260
261 // resized sphere
262 CPPUNIT_ASSERT_EQUAL( 4., resize((s || t), 2.).getRadius() );
263
264 // stretched sphere
265 CPPUNIT_ASSERT_EQUAL( 2.5, (stretch(s, Vector(2.,1.,1.)) || t).getRadius() );
266
267 // transformed sphere
268 CPPUNIT_ASSERT_EQUAL( 2., (transform(s, M) || t).getRadius() );
269
270 // resized and translated sphere
271 CPPUNIT_ASSERT_EQUAL( 4., translate(resize((s || t), 2.), offset).getRadius() );
272 }
273
274 // NOT spheres
275 {
276 // sphere at origin
277 CPPUNIT_ASSERT_EQUAL( std::numeric_limits<double>::infinity(), (!s).getRadius() );
278 }
279}
280
Note: See TracBrowser for help on using the repository browser.