Changeset 8cbb97 for src/unittests/vectorunittest.cpp
- Timestamp:
- Apr 29, 2010, 1:55:21 PM (15 years ago)
- Branches:
- 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
- Children:
- d79639
- Parents:
- 632bc3 (diff), 753f02 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/vectorunittest.cpp
r632bc3 r8cbb97 17 17 #include "memoryusageobserver.hpp" 18 18 #include "vector.hpp" 19 #include "vector_ops.hpp" 19 20 #include "vectorunittest.hpp" 21 #include "Plane.hpp" 22 #include "Exceptions/LinearDependenceException.hpp" 20 23 21 24 #ifdef HAVE_TESTRUNNER … … 23 26 #endif /*HAVE_TESTRUNNER*/ 24 27 28 #include <iostream> 29 30 using namespace std; 31 25 32 /********************************************** Test classes **************************************/ 26 33 … … 31 38 void VectorTest::setUp() 32 39 { 33 zero .Init(0.,0.,0.);34 unit .Init(1.,0.,0.);35 otherunit .Init(0.,1.,0.);36 notunit .Init(0.,1.,1.);37 two .Init(2.,1.,0.);40 zero = Vector(0.,0.,0.); 41 unit = Vector(1.,0.,0.); 42 otherunit = Vector(0.,1.,0.); 43 notunit = Vector(0.,1.,1.); 44 two = Vector(2.,1.,0.); 38 45 }; 39 46 … … 66 73 double factor; 67 74 // copy vector 68 fixture .Init(2.,3.,4.);75 fixture = Vector(2.,3.,4.); 69 76 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture ); 70 77 // summation and scaling 71 fixture.CopyVector(&zero); 72 fixture.AddVector(&unit); 73 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 74 fixture.CopyVector(&zero); 75 fixture.SubtractVector(&unit); 78 fixture = zero + unit; 79 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 80 fixture = zero - unit; 76 81 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 77 82 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 78 fixture.CopyVector(&zero); 79 fixture.AddVector(&zero); 83 fixture = zero + zero; 80 84 CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() ); 81 fixture.CopyVector(¬unit); 82 fixture.SubtractVector(&otherunit); 83 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 84 fixture.CopyVector(&unit); 85 fixture.AddVector(&otherunit); 85 fixture = notunit - otherunit; 86 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 87 fixture = unit - otherunit; 86 88 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 87 fixture.CopyVector(¬unit); 88 fixture.SubtractVector(&unit); 89 fixture.SubtractVector(&otherunit); 89 fixture = notunit - unit - otherunit; 90 90 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 91 fixture.CopyVector(&unit); 92 fixture.Scale(0.98); 91 fixture = 0.98 * unit; 93 92 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 94 fixture.CopyVector(&unit); 95 fixture.Scale(1.); 96 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 97 fixture.CopyVector(&unit); 93 fixture = 1. * unit; 94 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 98 95 factor = 0.98; 99 fixture .Scale(factor);96 fixture = factor * unit; 100 97 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 101 fixture.CopyVector(&unit);102 98 factor = 1.; 103 fixture .Scale(factor);99 fixture = factor * unit; 104 100 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 105 101 }; … … 131 127 void VectorTest::EuclidianScalarProductTest() 132 128 { 133 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &zero) );134 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &unit) );135 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &otherunit) );136 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( ¬unit) );137 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct( &unit) );138 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );139 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );140 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct( ¬unit) );141 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct( &unit) );142 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( &otherunit) );143 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( ¬unit) );129 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(zero) ); 130 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(unit) ); 131 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(otherunit) ); 132 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(notunit) ); 133 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(unit) ); 134 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 135 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 136 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(notunit) ); 137 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(unit) ); 138 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(otherunit) ); 139 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(notunit) ); 144 140 } 145 141 … … 162 158 void VectorTest::EuclidianDistancesTest() 163 159 { 164 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance( &unit) );165 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance( &unit) );166 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance( ¬unit) );167 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance( ¬unit) );168 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance( ¬unit) );160 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(unit) ); 161 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(unit) ); 162 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(notunit) ); 163 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(notunit) ); 164 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(notunit) ); 169 165 } 170 166 … … 173 169 void VectorTest::EuclidianAnglesTest() 174 170 { 175 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle( &unit) );176 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle( &unit) );177 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle( &unit)) < MYEPSILON );178 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle( ¬unit)) < MYEPSILON );179 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle( ¬unit)) < MYEPSILON );171 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(unit) ); 172 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(unit) ); 173 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(unit)) < MYEPSILON ); 174 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(notunit)) < MYEPSILON ); 175 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(notunit)) < MYEPSILON ); 180 176 }; 181 177 … … 184 180 void VectorTest::ProjectionTest() 185 181 { 186 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection( &unit) );187 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection( &unit) );188 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection( &two) );189 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection( &otherunit) );182 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(unit) ); 183 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(unit) ); 184 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection(two) ); 185 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection(otherunit) ); 190 186 }; 191 187 … … 195 191 { 196 192 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 197 CPPUNIT_ASSERT_ EQUAL( true, fixture.GetIntersectionWithPlane(&unit, &zero, &zero, &two) );193 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) ); 198 194 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 199 195 200 196 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 201 CPPUNIT_ASSERT_ EQUAL( true, fixture.GetIntersectionWithPlane(&otherunit, &two, &unit, ¬unit) );197 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) ); 202 198 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 203 199 204 200 // four vectors equal to zero 205 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) ); 201 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException); 202 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 203 204 // four vectors equal to unit 205 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException); 206 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 207 208 // two equal lines 209 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two)); 210 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 211 212 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 213 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) ); 214 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 215 216 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 217 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) ); 206 218 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 207 219 208 // four vectors equal to unit 209 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) ); 220 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 221 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) ); 222 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture ); 223 }; 224 225 /** UnitTest for vector rotations. 226 */ 227 void VectorTest::VectorRotationTest() 228 { 229 fixture = Vector(-1.,0.,0.); 230 231 // zero vector does not change 232 fixture = RotateVector(zero,unit, 1.); 210 233 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 211 234 212 // two equal lines 213 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) ); 235 fixture = RotateVector(zero, two, 1.); 236 CPPUNIT_ASSERT_EQUAL( zero, fixture); 237 238 // vector on axis does not change 239 fixture = RotateVector(unit,unit, 1.); 214 240 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 215 241 216 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???217 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &otherunit, NULL) );218 CPPUNIT_ASSERT_EQUAL( unit, fixture );219 220 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???221 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &zero, &zero, &two, NULL) );222 CPPUNIT_ASSERT_EQUAL( zero, fixture );223 224 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???225 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &zero, &otherunit, NULL) );226 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );227 };228 229 /** UnitTest for vector rotations.230 */231 void VectorTest::VectorRotationTest()232 {233 fixture.Init(-1.,0.,0.);234 235 // zero vector does not change236 fixture.CopyVector(&zero);237 fixture.RotateVector(&unit, 1.);238 CPPUNIT_ASSERT_EQUAL( zero, fixture );239 240 fixture.RotateVector(&two, 1.);241 CPPUNIT_ASSERT_EQUAL( zero, fixture);242 243 // vector on axis does not change244 fixture.CopyVector(&unit);245 fixture.RotateVector(&unit, 1.);246 CPPUNIT_ASSERT_EQUAL( unit, fixture );247 248 fixture.RotateVector(&unit, 1.);249 CPPUNIT_ASSERT_EQUAL( unit, fixture );250 251 242 // rotations 252 fixture.CopyVector(&otherunit); 253 fixture.RotateVector(&unit, M_PI); 243 fixture = RotateVector(otherunit, unit, M_PI); 254 244 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture ); 255 245 256 fixture.CopyVector(&otherunit); 257 fixture.RotateVector(&unit, 2. * M_PI); 246 fixture = RotateVector(otherunit, unit, 2. * M_PI); 258 247 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 259 248 260 fixture.CopyVector(&otherunit); 261 fixture.RotateVector(&unit, 0); 249 fixture = RotateVector(otherunit,unit, 0); 262 250 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 263 251 264 fixture.Init(0.,0.,1.); 265 fixture.RotateVector(¬unit, M_PI); 252 fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI); 266 253 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 267 254 } … … 283 270 parallelepiped[8] = 1; 284 271 285 fixture .CopyVector(zero);286 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 287 fixture .Init(2.5,2.5,2.5);272 fixture = zero; 273 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 274 fixture = Vector(2.5,2.5,2.5); 288 275 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 289 fixture .Init(1.,1.,1.);290 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 291 fixture .Init(3.5,3.5,3.5);292 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 293 fixture .Init(2.,2.,2.);276 fixture = Vector(1.,1.,1.); 277 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 278 fixture = Vector(3.5,3.5,3.5); 279 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 280 fixture = Vector(2.,2.,2.); 294 281 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 295 fixture .Init(2.,3.,2.);282 fixture = Vector(2.,3.,2.); 296 283 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 297 fixture .Init(-2.,2.,-1.);298 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 299 } 300 284 fixture = Vector(-2.,2.,-1.); 285 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 286 } 287
Note:
See TracChangeset
for help on using the changeset viewer.