source: src/Parameters/unittests/ContinuousValueTest.cpp@ dbb533

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 dbb533 was dbb533, checked in by Michael Ankele <ankele@…>, 13 years ago

updated Parameters' unittests

  • renamed "xxxUnitTest" -> "xxxTest" (to evade naming conflicts)
  • removed string operations
  • fixed missing template <T>s
  • Property mode set to 100644
File size: 6.1 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 * ContinuousValueTest.cpp
10 *
11 * Created on: Sep 29, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "ContinuousValueTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "Parameters/ContinuousValue.hpp"
27
28#ifdef HAVE_TESTRUNNER
29#include "UnitTestMain.hpp"
30#endif /*HAVE_TESTRUNNER*/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( ContinuousValueTest );
34
35
36void ContinuousValueTest::setUp()
37{
38 // failing asserts should be thrown
39 ASSERT_DO(Assert::Throw);
40
41 ValidRange = new range<int>(1,4);
42}
43
44void ContinuousValueTest::tearDown()
45{
46 delete ValidRange;
47}
48
49/************************************ tests ***********************************/
50
51/** Unit test for isValid.
52 *
53 */
54void ContinuousValueTest::isValidValueTest()
55{
56 // create instance
57 ContinuousValue<int> test(*ValidRange);
58
59 // checking valid values
60 for (int i=1; i<=4;++i)
61 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
62
63 // checking invalid values
64 for (int i=-10; i<=0;++i)
65 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
66 for (int i=5; i<=0;++i)
67 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
68}
69
70/** Unit test for isValid.
71 *
72 */
73void ContinuousValueTest::isValidTest()
74{
75 // create instance
76 ContinuousValue<int> test(*ValidRange);
77
78 // checking valid values
79 for (int i=1; i<=4;++i)
80 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
81
82 // checking invalid values
83 for (int i=-10; i<=0;++i)
84 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
85 for (int i=5; i<=0;++i)
86 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
87}
88
89/** Unit test for setting/getting valid range.
90 *
91 */
92void ContinuousValueTest::setgetValidRangeTest()
93{
94 {
95 // create instance
96 ContinuousValue<int> test(*ValidRange);
97
98 // extending range and checking
99 for (int i=5; i<=6;++i)
100 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
101 test.setValidRange(range<int>(1,6));
102 for (int i=5; i<=6;++i)
103 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
104 }
105
106 {
107 // create instance
108 ContinuousValue<int> test(*ValidRange);
109
110 // lowering range with set value
111 test.setValue(4);
112 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
113#ifndef NDEBUG
114 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
115 CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), Assert::AssertionFailure);
116#else
117 test.setValidRange(range<int>(1,3));
118#endif
119#ifndef NDEBUG
120 // no value is not set
121 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
122 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
123#endif
124 // value gets invalidated in either case
125 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
126 }
127}
128
129/** Unit test for setValue and getValue.
130 *
131 */
132void ContinuousValueTest::settergetterValueTest()
133{
134 // create instance
135 ContinuousValue<int> test(*ValidRange);
136
137 // unset calling of get, throws
138#ifndef NDEBUG
139 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
140 CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
141#endif
142
143 // setting invalid, throws
144#ifndef NDEBUG
145 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
146 CPPUNIT_ASSERT_THROW(test.setValue(5), Assert::AssertionFailure);
147#endif
148#ifndef NDEBUG
149 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
150 CPPUNIT_ASSERT_THROW(test.setValue(0), Assert::AssertionFailure);
151#endif
152
153 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
154 // checking all valid ones
155 for (int i=1; i<=4;++i) {
156 test.setValue(i);
157 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
158 CPPUNIT_ASSERT_EQUAL(i, test.getValue());
159 }
160}
161
162/** Unit test for setters and getters.
163 *
164 */
165void ContinuousValueTest::settergetterTest()
166{
167 // create instance
168 ContinuousValue<int> test(*ValidRange);
169
170 // unset calling of get, throws
171#ifndef NDEBUG
172 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
173 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
174#endif
175
176 // setting invalid, throws
177#ifndef NDEBUG
178 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
179 CPPUNIT_ASSERT_THROW(test.set(5), Assert::AssertionFailure);
180#endif
181#ifndef NDEBUG
182 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
183 CPPUNIT_ASSERT_THROW(test.set(0), Assert::AssertionFailure);
184#endif
185
186 // checking all valid ones
187 for (int i=1; i<=4;++i) {
188 test.set(i);
189 CPPUNIT_ASSERT_EQUAL(i, test.get());
190 }
191}
192
193/** Unit test for comparator.
194 *
195 */
196void ContinuousValueTest::comparatorTest()
197{
198 {
199 // create instance
200 ContinuousValue<int> test(*ValidRange);
201 ContinuousValue<int> instance(*ValidRange);
202 test.setValue(1);
203 instance.setValue(1);
204
205 // same value, same range
206 {
207 CPPUNIT_ASSERT(test == instance);
208 }
209
210 // different value, same range
211 {
212 const int oldvalue = instance.getValue();
213 instance.setValue(2);
214 CPPUNIT_ASSERT(test != instance);
215 instance.setValue(oldvalue);
216 }
217 }
218 {
219 ContinuousValue<int> test(*ValidRange);
220 range<int> OtherValidRange(1,5);
221 ContinuousValue<int> instance(OtherValidRange);
222
223 test.setValue(1);
224 instance.setValue(1);
225
226 // same value, same range
227 {
228 CPPUNIT_ASSERT(test != instance);
229 }
230
231 // different value, same range
232 {
233 const int oldvalue = instance.getValue();
234 instance.setValue(2);
235 CPPUNIT_ASSERT(test != instance);
236 instance.setValue(oldvalue);
237 }
238 }
239}
Note: See TracBrowser for help on using the repository browser.