| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * ContinuousParameterUnitTest.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: Sep 30, 2011 | 
|---|
| 12 | *      Author: heber | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include "ContinuousParameterUnitTest.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
| 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
| 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
| 25 |  | 
|---|
| 26 | #include "Parser/Parameters/ContinuousParameter.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | #include "CodePatterns/Range.hpp" | 
|---|
| 29 |  | 
|---|
| 30 | #ifdef HAVE_TESTRUNNER | 
|---|
| 31 | #include "UnitTestMain.hpp" | 
|---|
| 32 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 33 |  | 
|---|
| 34 | // Registers the fixture into the 'registry' | 
|---|
| 35 | CPPUNIT_TEST_SUITE_REGISTRATION( ContinuousParameterTest ); | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | void ContinuousParameterTest::setUp() | 
|---|
| 39 | { | 
|---|
| 40 | // failing asserts should be thrown | 
|---|
| 41 | ASSERT_DO(Assert::Throw); | 
|---|
| 42 |  | 
|---|
| 43 | ValidRange = new range<int>(1,4); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | void ContinuousParameterTest::tearDown() | 
|---|
| 47 | { | 
|---|
| 48 | delete ValidRange; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | /************************************ tests ***********************************/ | 
|---|
| 52 |  | 
|---|
| 53 | /** Unit test for comparator. | 
|---|
| 54 | * | 
|---|
| 55 | */ | 
|---|
| 56 | void ContinuousParameterTest::comparatorTest() | 
|---|
| 57 | { | 
|---|
| 58 | // create instance | 
|---|
| 59 | ContinuousParameter<int> test("intParam", *ValidRange); | 
|---|
| 60 | ContinuousParameter<int> samenamedsamevalued("intParam", *ValidRange); | 
|---|
| 61 | ContinuousParameter<int> samenamedelsevalued("intParam", *ValidRange); | 
|---|
| 62 | ContinuousParameter<int> elsenamedsamevalued("int2Param", *ValidRange); | 
|---|
| 63 | ContinuousParameter<int> elsenamedelsevalued("int2Param", *ValidRange); | 
|---|
| 64 | test.setValue(1); | 
|---|
| 65 | samenamedsamevalued.setValue(1); | 
|---|
| 66 | samenamedelsevalued.setValue(2); | 
|---|
| 67 | elsenamedsamevalued.setValue(1); | 
|---|
| 68 | elsenamedelsevalued.setValue(2); | 
|---|
| 69 |  | 
|---|
| 70 | CPPUNIT_ASSERT( test == samenamedsamevalued ); | 
|---|
| 71 | CPPUNIT_ASSERT( test != samenamedelsevalued ); | 
|---|
| 72 | CPPUNIT_ASSERT( test != elsenamedsamevalued ); | 
|---|
| 73 | CPPUNIT_ASSERT( test != elsenamedelsevalued ); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | /** Unit test for clone. | 
|---|
| 77 | * | 
|---|
| 78 | */ | 
|---|
| 79 | void ContinuousParameterTest::cloneTest() | 
|---|
| 80 | { | 
|---|
| 81 | // create instance | 
|---|
| 82 | ContinuousParameter<int> test("intParam", *ValidRange); | 
|---|
| 83 |  | 
|---|
| 84 | // check that we throw because of unset parameter | 
|---|
| 85 | #ifndef NDEBUG | 
|---|
| 86 | std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; | 
|---|
| 87 | CPPUNIT_ASSERT_THROW(test.clone(), Assert::AssertionFailure); | 
|---|
| 88 | #endif | 
|---|
| 89 |  | 
|---|
| 90 | // set parameter | 
|---|
| 91 | test.setValue(2); | 
|---|
| 92 |  | 
|---|
| 93 | // is returned as Parameter but we can compare only in true class as | 
|---|
| 94 | // Parameter may also be a DiscreteParameter where comparison is nonsense | 
|---|
| 95 | ContinuousParameter<int> *instance = dynamic_cast< ContinuousParameter<int> *> (test.clone()); | 
|---|
| 96 |  | 
|---|
| 97 | // different places in memory | 
|---|
| 98 | CPPUNIT_ASSERT( &test != instance); | 
|---|
| 99 |  | 
|---|
| 100 | // but same contents | 
|---|
| 101 | CPPUNIT_ASSERT( test == *instance); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|