source: src/Parser/Parameters/unittests/DiscreteValueUnitTest.cpp@ 0aa122

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 0aa122 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 6.5 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 * DiscreteValueUnitTest.cpp
10 *
11 * Created on: Sep 28, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "DiscreteValueUnitTest.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/DiscreteValue.hpp"
27
28#include "CodePatterns/toString.hpp"
29
30#ifdef HAVE_TESTRUNNER
31#include "UnitTestMain.hpp"
32#endif /*HAVE_TESTRUNNER*/
33
34using namespace std;
35
36// Registers the fixture into the 'registry'
37CPPUNIT_TEST_SUITE_REGISTRATION( DiscreteValueTest );
38
39
40void DiscreteValueTest::setUp()
41{
42 // failing asserts should be thrown
43 ASSERT_DO(Assert::Throw);
44
45 for (int i=1; i<=3;++i) {
46 ValidValues.push_back(i);
47 }
48}
49
50void DiscreteValueTest::tearDown()
51{
52 ValidValues.clear();
53}
54
55/************************************ tests ***********************************/
56
57/** Unit test for findIndexOfValue.
58 *
59 */
60void DiscreteValueTest::findIndexOfValueTest()
61{
62 // create instance
63 DiscreteValue<int> test(ValidValues);
64
65 // check valid values indices
66 CPPUNIT_ASSERT_EQUAL((size_t)0, test.findIndexOfValue(1));
67 CPPUNIT_ASSERT_EQUAL((size_t)1, test.findIndexOfValue(2));
68 CPPUNIT_ASSERT_EQUAL((size_t)2, test.findIndexOfValue(3));
69
70 // check invalid ones
71 for (int i=-10; i<=0;++i)
72 CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
73 for (int i=4; i<=0;++i)
74 CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
75}
76
77/** Unit test for isValidValue.
78 *
79 */
80void DiscreteValueTest::isValidValueTest()
81{
82 // create instance
83 DiscreteValue<int> test(ValidValues);
84
85 // checking valid values
86 for (int i=1; i<=3;++i)
87 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
88
89 // checking invalid values
90 for (int i=-10; i<=0;++i)
91 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
92 for (int i=4; i<=0;++i)
93 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
94}
95
96/** Unit test for isValid.
97 *
98 */
99void DiscreteValueTest::isValidTest()
100{
101 // create instance
102 DiscreteValue<int> test(ValidValues);
103
104 // checking valid values
105 for (int i=1; i<=3;++i)
106 CPPUNIT_ASSERT_EQUAL(true, test.isValid(toString(i)));
107
108 // checking invalid values
109 for (int i=-10; i<=0;++i)
110 CPPUNIT_ASSERT_EQUAL(false, test.isValid(toString(i)));
111 for (int i=4; i<=0;++i)
112 CPPUNIT_ASSERT_EQUAL(false, test.isValid(toString(i)));
113}
114
115/** Unit test for appendValidValue.
116 *
117 */
118void DiscreteValueTest::appendValidValueTest()
119{
120 // create instance
121 DiscreteValue<int> test(ValidValues);
122
123 // adding values 4,5,6
124 for (int i=4; i<=6;++i) {
125 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
126 test.appendValidValue(i);
127 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
128 }
129
130 // adding same value, throws assertion
131 const size_t size_before = test.ValidValues.size();
132#ifndef NDEBUG
133 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
134 for (int i=1; i<=6;++i)
135 CPPUNIT_ASSERT_THROW(test.appendValidValue(i), Assert::AssertionFailure);
136#endif
137 CPPUNIT_ASSERT_EQUAL( size_before, test.ValidValues.size() );
138
139 // checking valid values
140 for (int i=1; i<=6;++i)
141 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
142
143 // checking invalid values
144 for (int i=-10; i<=0;++i)
145 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
146
147 // checking invalid values
148 for (int i=7; i<=10;++i)
149 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
150}
151
152/** Unit test for setters and getters.
153 *
154 */
155void DiscreteValueTest::settergetterTest()
156{
157 // create instance
158 DiscreteValue<int> test(ValidValues);
159
160 // unset calling of get, throws
161#ifndef NDEBUG
162 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
163 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
164#endif
165
166 // setting invalid, throws
167#ifndef NDEBUG
168 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
169 CPPUNIT_ASSERT_THROW(test.set(toString(4)), Assert::AssertionFailure);
170#endif
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.set(toString(0)), Assert::AssertionFailure);
174#endif
175
176 // checking all valid ones
177 for (int i=1; i<=3;++i) {
178 test.set(toString(i));
179 CPPUNIT_ASSERT_EQUAL(toString(i), test.get());
180 }
181
182}
183
184/** Unit test for setValue and getValue.
185 *
186 */
187void DiscreteValueTest::settergetterValueTest()
188{
189 // create instance
190 DiscreteValue<int> test(ValidValues);
191
192 // unset calling of get, throws
193#ifndef NDEBUG
194 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
195 CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
196#endif
197
198 // setting invalid, throws
199#ifndef NDEBUG
200 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
201 CPPUNIT_ASSERT_THROW(test.setValue(4), Assert::AssertionFailure);
202#endif
203#ifndef NDEBUG
204 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
205 CPPUNIT_ASSERT_THROW(test.setValue(0), Assert::AssertionFailure);
206#endif
207
208 // checking all valid ones
209 for (int i=1; i<=3;++i) {
210 test.setValue(i);
211 CPPUNIT_ASSERT_EQUAL(i, test.getValue());
212 }
213}
214
215/** Unit test for comparator.
216 *
217 */
218void DiscreteValueTest::comparatorTest()
219{
220 {
221 // create instance
222 DiscreteValue<int> test(ValidValues);
223 DiscreteValue<int> instance(ValidValues);
224 test.setValue(1);
225 instance.setValue(1);
226
227 // same value, same range
228 {
229 CPPUNIT_ASSERT(test == instance);
230 }
231
232 // different value, same range
233 {
234 const int oldvalue = instance.getValue();
235 instance.setValue(2);
236 CPPUNIT_ASSERT(test != instance);
237 instance.setValue(oldvalue);
238 }
239 }
240 {
241 DiscreteValue<int> test(ValidValues);
242 DiscreteValue<int> instance(ValidValues);
243 instance.appendValidValue(4);
244
245 test.setValue(1);
246 instance.setValue(1);
247
248 // same value, same range
249 {
250 CPPUNIT_ASSERT(test != instance);
251 }
252
253 // different value, same range
254 {
255 const int oldvalue = instance.getValue();
256 instance.setValue(2);
257 CPPUNIT_ASSERT(test != instance);
258 instance.setValue(oldvalue);
259 }
260 }
261}
Note: See TracBrowser for help on using the repository browser.