source: src/Shapes/unittests/ShapeOpsUnitTest.cpp@ 84721b

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 84721b was 84721b, checked in by Frederik Heber <heber@…>, 13 years ago

Added new unit test ShapeOpsUnitTest, testing all ShapeOps.

  • BUGFIX: Stretch_impl() cstor had 1/... not 1./... for reciFactors.
  • Property mode set to 100644
File size: 3.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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ShapeOpsUnitTest.cpp
10 *
11 * Created on: Jun 18, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include <cmath>
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30#include "CodePatterns/Assert.hpp"
31
32#include "Helpers/defs.hpp"
33#include "LinearAlgebra/RealSpaceMatrix.hpp"
34#include "LinearAlgebra/Vector.hpp"
35#include "Shapes/BaseShapes.hpp"
36#include "Shapes/Shape.hpp"
37#include "Shapes/ShapeOps.hpp"
38
39#include "ShapeOpsUnitTest.hpp"
40
41// Registers the fixture into the 'registry'
42CPPUNIT_TEST_SUITE_REGISTRATION( ShapeOpsTest );
43
44void ShapeOpsTest::setUp()
45{
46 // failing asserts should be thrown
47 ASSERT_DO(Assert::Throw);
48}
49
50void ShapeOpsTest::tearDown()
51{}
52
53void ShapeOpsTest::resizeTest()
54{
55 Shape s = resize(Sphere(), 2.);
56
57 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
58 CPPUNIT_ASSERT( s.isInside( Vector(0.,1.5,0.) ) );
59 CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,1.5) ) );
60 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
61 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,2.,0.) ) );
62 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,2.) ) );
63}
64
65void ShapeOpsTest::translateTest()
66{
67 Shape s = translate(Sphere(), Vector(1.,0.,0.));
68
69 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
70 CPPUNIT_ASSERT( s.isInside( Vector(1.,.5,0.) ) );
71 CPPUNIT_ASSERT( s.isInside( Vector(1.,0.,.5) ) );
72 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
73 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,1.,0.) ) );
74 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,1.) ) );
75 CPPUNIT_ASSERT( !s.isInside( Vector(-.5,0.,0.) ) );
76 CPPUNIT_ASSERT( !s.isInside( Vector(0.,-.5,0.) ) );
77 CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,-.5) ) );
78}
79
80void ShapeOpsTest::stretchTest()
81{
82#ifndef NDEBUG
83 CPPUNIT_ASSERT_THROW( Shape test = stretch(Sphere(), Vector(-2.,0.,0.)), Assert::AssertionFailure );
84#endif
85 Shape s = stretch(Sphere(), Vector(2.,1.,1.));
86
87 CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
88 CPPUNIT_ASSERT( !s.isInside( Vector(0.,1.5,0.) ) );
89 CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,1.5) ) );
90 CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
91 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
92 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
93}
94
95void ShapeOpsTest::transformTest()
96{
97 RealSpaceMatrix M;
98 M.setRotation(45., 0., 0.);
99 Shape s = transform(Sphere(), M);
100
101 CPPUNIT_ASSERT( s.isInside( Vector(.5,0.,0.) ) );
102 CPPUNIT_ASSERT( s.isInside( Vector(0.,.5,0.) ) );
103 CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,.5) ) );
104 CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,0.) ) );
105 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
106 CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,1.) ) );
107}
108
Note: See TracBrowser for help on using the repository browser.