Ignore:
Timestamp:
Aug 19, 2009, 12:23:05 PM (16 years ago)
Author:
Frederik Heber <heber@…>
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
Message:

VectorUnitTest extended to Projections and Line intersection, some subsequent bug fixes.

Note: VectorUnitTest is running fine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/vectorunittest.cpp

    r658efb ref9df36  
    2525void VectorTest::setUp()
    2626{
     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.);
    2732};
    2833
     
    3641void VectorTest::UnityTest()
    3742{
    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 
    4343  // unity and zero tests
    4444  CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() );
     
    5555void VectorTest::SimpleAlgebraTest()
    5656{
    57   Vector zero(0.,0.,0.);
    58   Vector unit(1.,0.,0.);
    59   Vector otherunit(0.,1.,0.);
    60   Vector notunit(0.,1.,1.);
    6157  Vector helper;
    6258  double factor;
    63 
    6459  // summation and scaling
    6560  helper.CopyVector(&zero);
     
    10499void VectorTest::OperatorAlgebraTest()
    105100{
    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 
    111101  // summation and scaling
     102  CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
    112103  CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
    113104  CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() );
     
    119110  CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() );
    120111  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 */
     120void VectorTest::EuclidianScalarProductTest()
     121{
    134122  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&zero) );
    135123  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&unit) );
     
    143131  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&otherunit) );
    144132  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&notunit) );
    145 
    146   // Norms
     133}
     134
     135/** UnitTest for norms.
     136 */
     137void VectorTest::EuclidianNormTest()
     138{
    147139  CPPUNIT_ASSERT_EQUAL( 0., zero.Norm() );
    148140  CPPUNIT_ASSERT_EQUAL( 0., zero.NormSquared() );
     
    153145  CPPUNIT_ASSERT_EQUAL( 2., notunit.NormSquared() );
    154146  CPPUNIT_ASSERT_EQUAL( sqrt(2.), notunit.Norm() );
    155 
    156   // distances
     147}
     148
     149/** UnitTest for distances.
     150 */
     151void VectorTest::EuclidianDistancesTest()
     152{
    157153  CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(&unit) );
    158154  CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(&unit) );
     
    160156  CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(&notunit) );
    161157  CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(&notunit) );
    162 
    163   // Angles
     158}
     159
     160/** UnitTest for angles.
     161 */
     162void VectorTest::EuclidianAnglesTest()
     163{
    164164  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(&notunit)) < MYEPSILON );
     168  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(&notunit)) < MYEPSILON );
     169};
     170
     171/** UnitTest for projections.
     172 */
     173void 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 */
     183void 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, &notunit) );
     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};
    167218
    168219/********************************************** Main routine **************************************/
Note: See TracChangeset for help on using the changeset viewer.