source: src/Parameters/unittests/ValueTest.cpp@ adcfc6

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
Last change on this file since adcfc6 was fc32ad, checked in by Michael Ankele <ankele@…>, 13 years ago

added VectorRangeValidator

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ValueTest.cpp
10 *
11 * Created on: Apr 13, 2012
12 * Author: ankele
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "ValueTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "Parameters/Value.hpp"
27#include "Parameters/Validators/DiscreteValidator.hpp"
28#include "Parameters/Validators/RangeValidator.hpp"
29#include "Parameters/Validators/VectorRangeValidator.hpp"
30#include "Parameters/Validators/DummyValidator.hpp"
31
32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36using namespace std;
37
38// Registers the fixture into the 'registry'
39CPPUNIT_TEST_SUITE_REGISTRATION( ValueTest );
40
41
42void ValueTest::setUp()
43{
44 // failing asserts should be thrown
45 ASSERT_DO(Assert::Throw);
46
47 for (int i=1; i<=3;++i) {
48 ValidValues.push_back(i);
49 }
50}
51
52void ValueTest::tearDown()
53{
54 ValidValues.clear();
55}
56
57/************************************ tests ***********************************/
58
59
60/** Unit test for isValid.
61 *
62 */
63void ValueTest::isValidTest()
64{
65 // create instance
66 Value<int> test(ValidValues);
67
68 // checking valid values
69 for (int i=1; i<=3;++i)
70 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
71
72 // checking invalid values
73 for (int i=-10; i<=0;++i)
74 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
75 for (int i=4; i<=0;++i)
76 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
77}
78
79/** Unit test for appendValidValue.
80 *
81 */
82void ValueTest::appendValidValueTest()
83{
84 // create instance
85 Value<int> test(ValidValues);
86
87 // adding values 4,5,6
88 for (int i=4; i<=6;++i) {
89 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
90 dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).appendValidValue(i);
91 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
92 }
93
94/* // adding same value, throws assertion
95 const size_t size_before = test.ValidValues.size();
96#ifndef NDEBUG
97 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
98 for (int i=1; i<=6;++i)
99 CPPUNIT_ASSERT_THROW(test.appendValidValue(i), Assert::AssertionFailure);
100#endif
101 CPPUNIT_ASSERT_EQUAL( size_before, test.ValidValues.size() );
102
103 // checking valid values
104 for (int i=1; i<=6;++i)
105 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
106
107 // checking invalid values
108 for (int i=-10; i<=0;++i)
109 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
110
111 // checking invalid values
112 for (int i=7; i<=10;++i)
113 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));*/
114}
115
116/** Unit test for setters and getters.
117 *
118 */
119void ValueTest::settergetterTest()
120{
121 // create instance
122 Value<int> test(ValidValues);
123
124 // unset calling of get, throws
125#ifndef NDEBUG
126 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
127 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
128#endif
129
130 // setting invalid, throws
131#ifndef NDEBUG
132 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
133 CPPUNIT_ASSERT_THROW(test.set(4), Assert::AssertionFailure);
134#endif
135#ifndef NDEBUG
136 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
137 CPPUNIT_ASSERT_THROW(test.set(0), Assert::AssertionFailure);
138#endif
139
140 // checking all valid ones
141 for (int i=1; i<=3;++i) {
142 test.set(i);
143 CPPUNIT_ASSERT_EQUAL(i, test.get());
144 }
145
146}
147
148/** Unit test for comparator.
149 *
150 */
151void ValueTest::comparatorTest()
152{
153 {
154 // create instance
155 Value<int> test(ValidValues);
156 Value<int> instance(ValidValues);
157 test.set(1);
158 instance.set(1);
159
160 // same value, same range
161 {
162 CPPUNIT_ASSERT(test == instance);
163 }
164
165 // different value, same range
166 {
167 const int oldvalue = instance.get();
168 instance.set(2);
169 CPPUNIT_ASSERT(test != instance);
170 instance.set(oldvalue);
171 }
172 }
173 {
174 Value<int> test(ValidValues);
175 Value<int> instance(ValidValues);
176 dynamic_cast<DiscreteValidator<int> &>(instance.getValidator()).appendValidValue(4);
177
178 test.set(1);
179 instance.set(1);
180
181 // same value, same range
182 {
183 //CPPUNIT_ASSERT(test != instance);
184 }
185
186 // different value, same range
187 {
188 const int oldvalue = instance.get();
189 instance.set(2);
190 CPPUNIT_ASSERT(test != instance);
191 instance.set(oldvalue);
192 }
193 }
194}
Note: See TracBrowser for help on using the repository browser.