Changeset 7d1b6a for src/Parameters/unittests
- Timestamp:
- May 21, 2012, 11:53:49 AM (13 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:
- c5e7313
- Parents:
- 85d89b
- git-author:
- Michael Ankele <ankele@…> (04/10/12 14:29:59)
- git-committer:
- Michael Ankele <ankele@…> (05/21/12 11:53:49)
- Location:
- src/Parameters/unittests
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parameters/unittests/ContinuousParameterTest.cpp
r85d89b r7d1b6a 26 26 #include "Parameters/ContinuousParameter.hpp" 27 27 28 #include " CodePatterns/Range.hpp"28 #include "../Range.hpp" 29 29 30 30 #ifdef HAVE_TESTRUNNER … … 41 41 ASSERT_DO(Assert::Throw); 42 42 43 ValidRange = new range<int>(1,4); 43 ValidIntRange = new range<int>(1,4); 44 ValidVectorRange = new range<Vector>(Vector(0,1,2), Vector(10,11,12)); 44 45 } 45 46 46 47 void ContinuousParameterTest::tearDown() 47 48 { 48 delete ValidRange; 49 delete ValidIntRange; 50 delete ValidVectorRange; 49 51 } 50 52 … … 57 59 { 58 60 // create instance 59 ContinuousParameter<int> test("intParam", *Valid Range);60 ContinuousParameter<int> samenamedsamevalued("intParam", *Valid Range);61 ContinuousParameter<int> samenamedelsevalued("intParam", *Valid Range);62 ContinuousParameter<int> elsenamedsamevalued("int2Param", *Valid Range);63 ContinuousParameter<int> elsenamedelsevalued("int2Param", *Valid Range);61 ContinuousParameter<int> test("intParam", *ValidIntRange); 62 ContinuousParameter<int> samenamedsamevalued("intParam", *ValidIntRange); 63 ContinuousParameter<int> samenamedelsevalued("intParam", *ValidIntRange); 64 ContinuousParameter<int> elsenamedsamevalued("int2Param", *ValidIntRange); 65 ContinuousParameter<int> elsenamedelsevalued("int2Param", *ValidIntRange); 64 66 test.setValue(1); 65 67 samenamedsamevalued.setValue(1); … … 80 82 { 81 83 // create instance 82 ContinuousParameter<int> test("intParam", *Valid Range);84 ContinuousParameter<int> test("intParam", *ValidIntRange); 83 85 84 86 // check that we throw because of unset parameter -
src/Parameters/unittests/ContinuousParameterTest.hpp
r85d89b r7d1b6a 17 17 #include <cppunit/extensions/HelperMacros.h> 18 18 19 #include "LinearAlgebra/Vector.hpp" 20 19 21 template<class T> struct range; 22 class Vector; 20 23 21 24 class ContinuousParameterTest : public CppUnit::TestFixture … … 34 37 35 38 private: 36 range<int> *ValidRange; 39 range<int> *ValidIntRange; 40 range<Vector> *ValidVectorRange; 37 41 }; 38 42 -
src/Parameters/unittests/ContinuousValueTest.cpp
r85d89b r7d1b6a 39 39 ASSERT_DO(Assert::Throw); 40 40 41 ValidRange = new range<int>(1,4); 41 ValidIntRange = new range<int>(1,4); 42 ValidVectorRange = new range<Vector>(Vector(0,1,2), Vector(10,11,12)); 42 43 } 43 44 44 45 void ContinuousValueTest::tearDown() 45 46 { 46 delete ValidRange; 47 delete ValidIntRange; 48 delete ValidVectorRange; 47 49 } 48 50 … … 52 54 * 53 55 */ 54 void ContinuousValueTest::isValid ValueTest()55 { 56 // create instance 57 ContinuousValue<int> test(*Valid Range);56 void ContinuousValueTest::isValidIntValueTest() 57 { 58 // create instance 59 ContinuousValue<int> test(*ValidIntRange); 58 60 59 61 // checking valid values … … 71 73 * 72 74 */ 73 void ContinuousValueTest::isValid Test()74 { 75 // create instance 76 ContinuousValue<int> test(*Valid Range);75 void ContinuousValueTest::isValidIntTest() 76 { 77 // create instance 78 ContinuousValue<int> test(*ValidIntRange); 77 79 78 80 // checking valid values … … 90 92 * 91 93 */ 92 void ContinuousValueTest::setgetValid RangeTest()93 { 94 { 95 // create instance 96 ContinuousValue<int> test(*Valid Range);94 void ContinuousValueTest::setgetValidIntRangeTest() 95 { 96 { 97 // create instance 98 ContinuousValue<int> test(*ValidIntRange); 97 99 98 100 // extending range and checking … … 106 108 { 107 109 // create instance 108 ContinuousValue<int> test(*Valid Range);110 ContinuousValue<int> test(*ValidIntRange); 109 111 110 112 // lowering range with set value … … 130 132 * 131 133 */ 132 void ContinuousValueTest::settergetter ValueTest()133 { 134 // create instance 135 ContinuousValue<int> test(*Valid Range);134 void ContinuousValueTest::settergetterIntValueTest() 135 { 136 // create instance 137 ContinuousValue<int> test(*ValidIntRange); 136 138 137 139 // unset calling of get, throws … … 163 165 * 164 166 */ 165 void ContinuousValueTest::settergetter Test()166 { 167 // create instance 168 ContinuousValue<int> test(*Valid Range);167 void ContinuousValueTest::settergetterIntTest() 168 { 169 // create instance 170 ContinuousValue<int> test(*ValidIntRange); 169 171 170 172 // unset calling of get, throws … … 194 196 * 195 197 */ 196 void ContinuousValueTest::comparator Test()197 { 198 { 199 // create instance 200 ContinuousValue<int> test(*Valid Range);201 ContinuousValue<int> instance(*Valid Range);198 void ContinuousValueTest::comparatorIntTest() 199 { 200 { 201 // create instance 202 ContinuousValue<int> test(*ValidIntRange); 203 ContinuousValue<int> instance(*ValidIntRange); 202 204 test.setValue(1); 203 205 instance.setValue(1); … … 217 219 } 218 220 { 219 ContinuousValue<int> test(*Valid Range);220 range<int> OtherValid Range(1,5);221 ContinuousValue<int> instance(OtherValid Range);221 ContinuousValue<int> test(*ValidIntRange); 222 range<int> OtherValidIntRange(1,5); 223 ContinuousValue<int> instance(OtherValidIntRange); 222 224 223 225 test.setValue(1); … … 238 240 } 239 241 } 242 243 244 245 /***************************** vector tests ***********************************/ 246 247 /** Unit test for isValid. 248 * 249 */ 250 void ContinuousValueTest::isValidVectorValueTest() 251 { 252 // create instance 253 ContinuousValue<Vector> test(*ValidVectorRange); 254 255 // checking valid values 256 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(0,1,2))); 257 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(9.9,10.9,11.9))); 258 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(5,5,5))); 259 260 // checking invalid values 261 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-0.1,0.9,1.9))); 262 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(10.1,11.1,12.1))); 263 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,-1))); 264 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,5))); 265 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,5))); 266 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,20))); 267 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,5))); 268 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,5))); 269 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(0,0,0))); 270 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,-1))); 271 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,-1))); 272 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,-1,5))); 273 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20))); 274 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20))); 275 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5))); 276 } 277 278 /** Unit test for isValid. 279 * 280 */ 281 void ContinuousValueTest::isValidVectorTest() 282 { 283 // create instance 284 ContinuousValue<Vector> test(*ValidVectorRange); 285 286 // checking valid values 287 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(0,1,2))); 288 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(9.9,10.9,11.9))); 289 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(5,5,5))); 290 291 // checking invalid values 292 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-0.1,0.9,1.9))); 293 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(10.1,11.1,12.1))); 294 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,-1))); 295 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,5))); 296 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,5))); 297 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,20))); 298 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,5))); 299 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,5))); 300 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(0,0,0))); 301 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,-1))); 302 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,-1))); 303 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,-1,5))); 304 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,20))); 305 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,20))); 306 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,20,5))); 307 } 308 309 /** Unit test for setting/getting valid range. 310 * 311 */ 312 void ContinuousValueTest::setgetValidVectorRangeTest() 313 { 314 { 315 // create instance 316 ContinuousValue<Vector> test(*ValidVectorRange); 317 318 // extending range and checking 319 for (int i=15; i<=16;++i) 320 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(i,5,5))); 321 test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12))); 322 for (int i=15; i<=16;++i) 323 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(i,5,5))); 324 } 325 326 { 327 // create instance 328 ContinuousValue<Vector> test(*ValidVectorRange); 329 330 // lowering range with set value 331 test.setValue(Vector(4,4,4)); 332 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); 333 #ifndef NDEBUG 334 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 335 CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), Assert::AssertionFailure); 336 #else 337 test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))); 338 #endif 339 #ifndef NDEBUG 340 // no value is not set 341 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 342 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure); 343 #endif 344 // value gets invalidated in either case 345 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); 346 } 347 } 348 349 /** Unit test for setValue and getValue. 350 * 351 */ 352 void ContinuousValueTest::settergetterVectorValueTest() 353 { 354 // create instance 355 ContinuousValue<Vector> test(*ValidVectorRange); 356 357 // unset calling of get, throws 358 #ifndef NDEBUG 359 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 360 CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure); 361 #endif 362 363 // setting invalid, throws 364 #ifndef NDEBUG 365 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 366 CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,0,0)), Assert::AssertionFailure); 367 #endif 368 #ifndef NDEBUG 369 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 370 CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,20,5)), Assert::AssertionFailure); 371 #endif 372 373 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); 374 // checking some valid ones 375 for (int i=1; i<=4;++i) { 376 Vector v(i,5,5); 377 test.setValue(v); 378 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); 379 CPPUNIT_ASSERT_EQUAL(v, test.getValue()); 380 } 381 } 382 383 /** Unit test for setters and getters. 384 * 385 */ 386 void ContinuousValueTest::settergetterVectorTest() 387 { 388 // create instance 389 ContinuousValue<Vector> test(*ValidVectorRange); 390 391 // unset calling of get, throws 392 #ifndef NDEBUG 393 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 394 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure); 395 #endif 396 397 // setting invalid, throws 398 #ifndef NDEBUG 399 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 400 CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), Assert::AssertionFailure); 401 #endif 402 #ifndef NDEBUG 403 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 404 CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), Assert::AssertionFailure); 405 #endif 406 407 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); 408 // checking some valid ones 409 for (int i=1; i<=4;++i) { 410 Vector v(i,5,5); 411 test.set(v); 412 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); 413 CPPUNIT_ASSERT_EQUAL(v, test.get()); 414 } 415 } 416 417 /** Unit test for comparator. 418 * 419 */ 420 void ContinuousValueTest::comparatorVectorTest() 421 { 422 { 423 // create instance 424 ContinuousValue<Vector> test(*ValidVectorRange); 425 ContinuousValue<Vector> instance(*ValidVectorRange); 426 test.setValue(Vector(5,6,7)); 427 instance.setValue(Vector(5,6,7)); 428 429 // same value, same range 430 { 431 CPPUNIT_ASSERT(test == instance); 432 } 433 434 // different value, same range 435 { 436 const Vector oldvalue = instance.getValue(); 437 instance.setValue(Vector(2,3,4)); 438 CPPUNIT_ASSERT(test != instance); 439 instance.setValue(oldvalue); 440 } 441 } 442 { 443 ContinuousValue<Vector> test(*ValidVectorRange); 444 range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22)); 445 ContinuousValue<Vector> instance(OtherValidVectorRange); 446 447 test.setValue(Vector(1,2,3)); 448 instance.setValue(Vector(1,2,3)); 449 450 // same value, same range 451 { 452 CPPUNIT_ASSERT(test != instance); 453 } 454 455 // different value, same range 456 { 457 const Vector oldvalue = instance.getValue(); 458 instance.setValue(Vector(2,3,4)); 459 CPPUNIT_ASSERT(test != instance); 460 instance.setValue(oldvalue); 461 } 462 } 463 } -
src/Parameters/unittests/ContinuousValueTest.hpp
r85d89b r7d1b6a 17 17 #include <cppunit/extensions/HelperMacros.h> 18 18 19 #include "LinearAlgebra/Vector.hpp" 20 19 21 template<class T> struct range; 22 class Vector; 20 23 21 24 class ContinuousValueTest : public CppUnit::TestFixture 22 25 { 23 26 CPPUNIT_TEST_SUITE( ContinuousValueTest ) ; 24 CPPUNIT_TEST ( isValidValueTest ); 25 CPPUNIT_TEST ( isValidTest ); 26 CPPUNIT_TEST ( setgetValidRangeTest ); 27 CPPUNIT_TEST ( settergetterValueTest ); 28 CPPUNIT_TEST ( settergetterTest ); 29 CPPUNIT_TEST ( comparatorTest ); 27 CPPUNIT_TEST ( isValidIntValueTest ); 28 CPPUNIT_TEST ( isValidIntTest ); 29 CPPUNIT_TEST ( setgetValidIntRangeTest ); 30 CPPUNIT_TEST ( settergetterIntValueTest ); 31 CPPUNIT_TEST ( settergetterIntTest ); 32 CPPUNIT_TEST ( comparatorIntTest ); 33 CPPUNIT_TEST ( isValidVectorValueTest ); 34 CPPUNIT_TEST ( isValidVectorTest ); 35 CPPUNIT_TEST ( setgetValidVectorRangeTest ); 36 CPPUNIT_TEST ( settergetterVectorValueTest ); 37 CPPUNIT_TEST ( settergetterVectorTest ); 38 CPPUNIT_TEST ( comparatorVectorTest ); 30 39 CPPUNIT_TEST_SUITE_END(); 31 40 … … 34 43 void tearDown(); 35 44 36 void isValidValueTest(); 37 void isValidTest(); 38 void setgetValidRangeTest(); 39 void settergetterValueTest(); 40 void settergetterTest(); 41 void comparatorTest(); 45 void isValidIntValueTest(); 46 void isValidIntTest(); 47 void setgetValidIntRangeTest(); 48 void settergetterIntValueTest(); 49 void settergetterIntTest(); 50 void comparatorIntTest(); 51 52 void isValidVectorValueTest(); 53 void isValidVectorTest(); 54 void setgetValidVectorRangeTest(); 55 void settergetterVectorValueTest(); 56 void settergetterVectorTest(); 57 void comparatorVectorTest(); 42 58 43 59 private: 44 range<int> *ValidRange; 60 range<int> *ValidIntRange; 61 range<Vector> *ValidVectorRange; 45 62 }; 46 63 -
src/Parameters/unittests/Makefile.am
r85d89b r7d1b6a 33 33 ../Parameters/ContinuousValue.hpp \ 34 34 ../Parameters/ContinuousValue_impl.hpp \ 35 ../Parameters/Range.hpp \ 35 36 ../Parameters/ValueInterface.hpp 36 37 ContinuousValueTest_LDADD = \ 37 $(PARAMETERSLIBS) 38 $(PARAMETERSLIBS) \ 39 $(top_builddir)/LinearAlgebra/src/LinearAlgebra/libLinearAlgebra.la 38 40 39 41 ContinuousParameterTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ … … 48 50 ../Parameters/ValueInterface.hpp 49 51 ContinuousParameterTest_LDADD = \ 50 $(PARAMETERSLIBS) 52 $(PARAMETERSLIBS) \ 53 $(top_builddir)/LinearAlgebra/src/LinearAlgebra/libLinearAlgebra.la 51 54 52 55 DiscreteValueTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
Note:
See TracChangeset
for help on using the changeset viewer.