- Timestamp:
- Sep 12, 2016, 11:48:34 PM (9 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
- Children:
- 2199c2
- Parents:
- 158ecb
- git-author:
- Frederik Heber <heber@…> (06/12/14 07:23:12)
- git-committer:
- Frederik Heber <heber@…> (09/12/16 23:48:34)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp
r158ecb rb67d89 150 150 } 151 151 152 void perturbPolygon( 153 SphericalPointDistribution::Polygon_t &_polygon, 154 double _amplitude 155 ) 156 { 157 for (SphericalPointDistribution::Polygon_t::iterator iter = _polygon.begin(); 158 iter != _polygon.end(); ++iter) { 159 Vector perturber; 160 perturber.GetOneNormalVector((*iter)); 161 perturber.Scale(_amplitude); 162 *iter = *iter + perturber; 163 (*iter).Normalize(); 164 } 165 } 166 167 static 168 bool areEqualToWithinBounds( 169 const SphericalPointDistribution::Polygon_t &_polygon, 170 const SphericalPointDistribution::Polygon_t &_otherpolygon, 171 double _amplitude 172 ) 173 { 174 // same size? 175 if (_polygon.size() != _otherpolygon.size()) 176 return false; 177 // same points ? We just check witrh trivial mapping, nothing fancy ... 178 bool status = true; 179 SphericalPointDistribution::Polygon_t::const_iterator iter = _polygon.begin(); 180 SphericalPointDistribution::Polygon_t::const_iterator otheriter = _otherpolygon.begin(); 181 for (; iter != _polygon.end(); ++iter, ++otheriter) { 182 status &= (*iter - *otheriter).Norm() < _amplitude; 183 } 184 return status; 185 } 186 187 /** UnitTest for areEqualToWithinBounds() 188 */ 189 void SphericalPointDistributionTest::areEqualToWithinBoundsTest() 190 { 191 // test with no points 192 { 193 SphericalPointDistribution::Polygon_t polygon; 194 SphericalPointDistribution::Polygon_t expected = polygon; 195 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) ); 196 } 197 // test with one point 198 { 199 SphericalPointDistribution::Polygon_t polygon; 200 polygon += Vector(1.,0.,0.); 201 SphericalPointDistribution::Polygon_t expected = polygon; 202 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) ); 203 } 204 // test with two points 205 { 206 SphericalPointDistribution::Polygon_t polygon; 207 polygon += Vector(1.,0.,0.); 208 polygon += Vector(0.,1.,0.); 209 SphericalPointDistribution::Polygon_t expected = polygon; 210 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) ); 211 } 212 213 // test with two points in different order: THIS GOES WRONG: We only check trivially 214 { 215 SphericalPointDistribution::Polygon_t polygon; 216 polygon += Vector(1.,0.,0.); 217 polygon += Vector(0.,1.,0.); 218 SphericalPointDistribution::Polygon_t expected; 219 expected += Vector(0.,1.,0.); 220 expected += Vector(1.,0.,0.); 221 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) ); 222 } 223 224 // test with two different points 225 { 226 SphericalPointDistribution::Polygon_t polygon; 227 polygon += Vector(1.,0.,0.); 228 polygon += Vector(0.,1.,0.); 229 SphericalPointDistribution::Polygon_t expected; 230 expected += Vector(1.01,0.,0.); 231 expected += Vector(0.,1.,0.); 232 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, 0.05) ); 233 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.005) ); 234 } 235 236 // test with different number of points 237 { 238 SphericalPointDistribution::Polygon_t polygon; 239 polygon += Vector(1.,0.,0.); 240 polygon += Vector(0.,1.,0.); 241 SphericalPointDistribution::Polygon_t expected; 242 expected += Vector(0.,1.,0.); 243 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.05) ); 244 } 245 } 246 247 152 248 /** UnitTest for matchSphericalPointDistributions() with three points 153 249 */ … … 205 301 newpolygon); 206 302 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 303 // also slightly perturbed 304 const double amplitude = 0.05; 305 perturbPolygon(polygon, amplitude); 306 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 207 307 } 208 308 … … 227 327 newpolygon); 228 328 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 329 // also slightly perturbed 330 const double amplitude = 0.05; 331 perturbPolygon(polygon, amplitude); 332 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 229 333 } 230 334 … … 241 345 newpolygon); 242 346 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 347 // also slightly perturbed 348 const double amplitude = 0.05; 349 perturbPolygon(polygon, amplitude); 350 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 243 351 } 244 352 … … 260 368 newpolygon); 261 369 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 370 // also slightly perturbed 371 const double amplitude = 0.05; 372 perturbPolygon(polygon, amplitude); 373 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 262 374 } 263 375 } … … 318 430 newpolygon); 319 431 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 432 // also slightly perturbed 433 const double amplitude = 0.05; 434 perturbPolygon(polygon, amplitude); 435 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 436 } 437 438 // test with two points, matching trivially, also with slightly perturbed 439 { 440 SphericalPointDistribution::Polygon_t polygon; 441 polygon += Vector(1.,0.,0.), Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.); 442 SphericalPointDistribution::Polygon_t newpolygon = 443 SPD.get<4>(); 444 SphericalPointDistribution::Polygon_t expected = newpolygon; 445 expected.pop_front(); // remove first point 446 expected.pop_front(); // remove second point 447 SphericalPointDistribution::Polygon_t remaining = 448 SphericalPointDistribution::matchSphericalPointDistributions( 449 polygon, 450 newpolygon); 451 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 452 // also slightly perturbed 453 const double amplitude = 0.05; 454 perturbPolygon(polygon, amplitude); 455 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 320 456 } 321 457 … … 340 476 newpolygon); 341 477 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 478 // also slightly perturbed 479 const double amplitude = 0.05; 480 perturbPolygon(polygon, amplitude); 481 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 342 482 } 343 483 … … 360 500 newpolygon); 361 501 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 502 // also slightly perturbed 503 const double amplitude = 0.05; 504 perturbPolygon(polygon, amplitude); 505 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 362 506 } 363 507 … … 384 528 newpolygon); 385 529 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 530 // also slightly perturbed 531 const double amplitude = 0.05; 532 perturbPolygon(polygon, amplitude); 533 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 386 534 } 387 535 } … … 442 590 newpolygon); 443 591 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 592 // also slightly perturbed 593 const double amplitude = 0.05; 594 perturbPolygon(polygon, amplitude); 595 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 444 596 } 445 597 … … 494 646 newpolygon); 495 647 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 648 // also slightly perturbed 649 const double amplitude = 0.05; 650 perturbPolygon(polygon, amplitude); 651 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 496 652 } 497 653 … … 518 674 newpolygon); 519 675 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 676 // also slightly perturbed 677 const double amplitude = 0.05; 678 perturbPolygon(polygon, amplitude); 679 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 520 680 } 521 681 } … … 576 736 newpolygon); 577 737 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 738 // also slightly perturbed 739 const double amplitude = 0.05; 740 perturbPolygon(polygon, amplitude); 741 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 578 742 } 579 743 … … 628 792 newpolygon); 629 793 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 794 // also slightly perturbed 795 const double amplitude = 0.05; 796 perturbPolygon(polygon, amplitude); 797 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 630 798 } 631 799 … … 652 820 newpolygon); 653 821 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 822 // also slightly perturbed 823 const double amplitude = 0.05; 824 perturbPolygon(polygon, amplitude); 825 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 654 826 } 655 827 } … … 710 882 newpolygon); 711 883 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 884 // also slightly perturbed 885 const double amplitude = 0.05; 886 perturbPolygon(polygon, amplitude); 887 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 712 888 } 713 889 … … 762 938 newpolygon); 763 939 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 940 // also slightly perturbed 941 const double amplitude = 0.05; 942 perturbPolygon(polygon, amplitude); 943 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 764 944 } 765 945 … … 786 966 newpolygon); 787 967 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 968 // also slightly perturbed 969 const double amplitude = 0.05; 970 perturbPolygon(polygon, amplitude); 971 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 788 972 } 789 973 } … … 844 1028 newpolygon); 845 1029 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 1030 // also slightly perturbed 1031 const double amplitude = 0.05; 1032 perturbPolygon(polygon, amplitude); 1033 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 846 1034 } 847 1035 … … 900 1088 newpolygon); 901 1089 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 1090 // also slightly perturbed 1091 const double amplitude = 0.05; 1092 perturbPolygon(polygon, amplitude); 1093 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 902 1094 } 903 1095 … … 924 1116 newpolygon); 925 1117 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 1118 // also slightly perturbed 1119 const double amplitude = 0.05; 1120 perturbPolygon(polygon, amplitude); 1121 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) ); 926 1122 } 927 1123 }
Note:
See TracChangeset
for help on using the changeset viewer.