Changeset ef9df36 for src/vectorunittest.cpp
- Timestamp:
- Aug 19, 2009, 12:23:05 PM (16 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, Candidate_v1.7.0, 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:
- 99c484
- Parents:
- 658efb
- File:
-
- 1 edited
-
src/vectorunittest.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/vectorunittest.cpp
r658efb ref9df36 25 25 void VectorTest::setUp() 26 26 { 27 zero.Init(0.,0.,0.); 28 unit.Init(1.,0.,0.); 29 otherunit.Init(0.,1.,0.); 30 notunit.Init(0.,1.,1.); 31 two.Init(2.,1.,0.); 27 32 }; 28 33 … … 36 41 void VectorTest::UnityTest() 37 42 { 38 Vector zero(0.,0.,0.);39 Vector unit(1.,0.,0.);40 Vector otherunit(1./sqrt(2.),0.,1./sqrt(2.));41 Vector notunit(0.,1.,1.);42 43 43 // unity and zero tests 44 44 CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() ); … … 55 55 void VectorTest::SimpleAlgebraTest() 56 56 { 57 Vector zero(0.,0.,0.);58 Vector unit(1.,0.,0.);59 Vector otherunit(0.,1.,0.);60 Vector notunit(0.,1.,1.);61 57 Vector helper; 62 58 double factor; 63 64 59 // summation and scaling 65 60 helper.CopyVector(&zero); … … 104 99 void VectorTest::OperatorAlgebraTest() 105 100 { 106 Vector zero(0.,0.,0.);107 Vector unit(1.,0.,0.);108 Vector otherunit(0.,1.,0.);109 Vector notunit(0.,1.,1.);110 111 101 // summation and scaling 102 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() ); 112 103 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() ); 113 104 CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() ); … … 119 110 CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() ); 120 111 CPPUNIT_ASSERT_EQUAL( true, (unit*1.).IsOne() ); 121 }; 122 123 /** UnitTest for scalar products, norms, distances and angles. 124 */ 125 void VectorTest::EuclidianTest() 126 { 127 Vector zero(0.,0.,0.); 128 Vector unit(1.,0.,0.); 129 Vector otherunit(0.,1.,0.); 130 Vector notunit(0.,1.,1.); 131 Vector two(2.,1.,0.); 132 133 // SCP 112 113 CPPUNIT_ASSERT_EQUAL( unit, (zero+unit) ); 114 CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,1.), (notunit-otherunit) ); 115 CPPUNIT_ASSERT_EQUAL( Vector(-1, 0., 1.), (notunit-unit-otherunit) ); 116 }; 117 118 /** UnitTest for scalar products. 119 */ 120 void VectorTest::EuclidianScalarProductTest() 121 { 134 122 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&zero) ); 135 123 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&unit) ); … … 143 131 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&otherunit) ); 144 132 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(¬unit) ); 145 146 // Norms 133 } 134 135 /** UnitTest for norms. 136 */ 137 void VectorTest::EuclidianNormTest() 138 { 147 139 CPPUNIT_ASSERT_EQUAL( 0., zero.Norm() ); 148 140 CPPUNIT_ASSERT_EQUAL( 0., zero.NormSquared() ); … … 153 145 CPPUNIT_ASSERT_EQUAL( 2., notunit.NormSquared() ); 154 146 CPPUNIT_ASSERT_EQUAL( sqrt(2.), notunit.Norm() ); 155 156 // distances 147 } 148 149 /** UnitTest for distances. 150 */ 151 void VectorTest::EuclidianDistancesTest() 152 { 157 153 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(&unit) ); 158 154 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(&unit) ); … … 160 156 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(¬unit) ); 161 157 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(¬unit) ); 162 163 // Angles 158 } 159 160 /** UnitTest for angles. 161 */ 162 void VectorTest::EuclidianAnglesTest() 163 { 164 164 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(&unit) ); 165 }; 166 165 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(&unit) ); 166 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(&unit)) < MYEPSILON ); 167 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(¬unit)) < MYEPSILON ); 168 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(¬unit)) < MYEPSILON ); 169 }; 170 171 /** UnitTest for projections. 172 */ 173 void VectorTest::ProjectionTest() 174 { 175 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(&unit) ); 176 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(&unit) ); 177 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection(&two) ); 178 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection(&otherunit) ); 179 }; 180 181 /** UnitTest for line intersections. 182 */ 183 void VectorTest::LineIntersectionTest() 184 { 185 Vector helper; 186 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 187 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) ); 188 CPPUNIT_ASSERT_EQUAL( zero, helper ); 189 190 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 191 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, ¬unit) ); 192 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), helper ); 193 194 // four vectors equal to zero 195 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) ); 196 CPPUNIT_ASSERT_EQUAL( zero, helper ); 197 198 // four vectors equal to unit 199 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) ); 200 CPPUNIT_ASSERT_EQUAL( zero, helper ); 201 202 // two equal lines 203 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) ); 204 CPPUNIT_ASSERT_EQUAL( unit, helper ); 205 206 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 207 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) ); 208 CPPUNIT_ASSERT_EQUAL( unit, helper ); 209 210 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 211 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) ); 212 CPPUNIT_ASSERT_EQUAL( zero, helper ); 213 214 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 215 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) ); 216 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), helper ); 217 }; 167 218 168 219 /********************************************** Main routine **************************************/
Note:
See TracChangeset
for help on using the changeset viewer.
