source: src/Parameters/unittests/DiscreteValueTest.cpp@ 94d5ac6

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 94d5ac6 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.4 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * DiscreteValueTest.cpp
25 *
26 * Created on: Sep 28, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "DiscreteValueTest.hpp"
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "Parameters/ParameterExceptions.hpp"
42#include "Parameters/Value.hpp"
43
44#ifdef HAVE_TESTRUNNER
45#include "UnitTestMain.hpp"
46#endif /*HAVE_TESTRUNNER*/
47
48using namespace std;
49
50// Registers the fixture into the 'registry'
51CPPUNIT_TEST_SUITE_REGISTRATION( DiscreteValueTest );
52
53
54void DiscreteValueTest::setUp()
55{
56 // failing asserts should be thrown
57 ASSERT_DO(Assert::Throw);
58
59 for (int i=1; i<=3;++i) {
60 ValidValues.push_back(i);
61 }
62}
63
64void DiscreteValueTest::tearDown()
65{
66 ValidValues.clear();
67}
68
69/************************************ tests ***********************************/
70
71/** Unit test for findIndexOfValue.
72 *
73 */
74void DiscreteValueTest::findIndexOfValueTest()
75{
76 // create instance
77 Value<int> test(ValidValues);
78
79 // check valid values indices
80 CPPUNIT_ASSERT_EQUAL((size_t)0, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).findIndexOfValue(1));
81 CPPUNIT_ASSERT_EQUAL((size_t)1, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).findIndexOfValue(2));
82 CPPUNIT_ASSERT_EQUAL((size_t)2, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).findIndexOfValue(3));
83
84 // check invalid ones
85 for (int i=-10; i<=0;++i)
86 CPPUNIT_ASSERT_EQUAL((size_t)-1, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).findIndexOfValue(i));
87 for (int i=4; i<=0;++i)
88 CPPUNIT_ASSERT_EQUAL((size_t)-1, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).findIndexOfValue(i));
89}
90
91/** Unit test for isValidValue.
92 *
93 */
94void DiscreteValueTest::isValidAsStringTest()
95{
96 // create instance
97 Value<int> test(ValidValues);
98
99 // checking valid values
100 for (int i=1; i<=3;++i)
101 CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
102
103 // checking invalid values
104 for (int i=-10; i<=0;++i)
105 CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
106 for (int i=4; i<=0;++i)
107 CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
108}
109
110/** Unit test for isValid.
111 *
112 */
113void DiscreteValueTest::isValidTest()
114{
115 // create instance
116 Value<int> test(ValidValues);
117
118 // checking valid values
119 for (int i=1; i<=3;++i)
120 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
121
122 // checking invalid values
123 for (int i=-10; i<=0;++i)
124 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
125 for (int i=4; i<=0;++i)
126 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
127}
128
129/** Unit test for appendValidValue.
130 *
131 */
132void DiscreteValueTest::appendValidValueTest()
133{
134 // create instance
135 Value<int> test(ValidValues);
136
137 // adding values 4,5,6
138 for (int i=4; i<=6;++i) {
139 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
140 dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).appendValidValue(i);
141 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
142 }
143
144 // adding same value, throws assertion
145 const size_t size_before = dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size();
146 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
147 for (int i=1; i<=6;++i)
148 CPPUNIT_ASSERT_THROW(dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).appendValidValue(i), ParameterValidatorException);
149 CPPUNIT_ASSERT_EQUAL( size_before, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size() );
150
151 // checking valid values
152 for (int i=1; i<=6;++i)
153 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
154
155 // checking invalid values
156 for (int i=-10; i<=0;++i)
157 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
158
159 // checking invalid values
160 for (int i=7; i<=10;++i)
161 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
162}
163
164/** Unit test for setters and getters.
165 *
166 */
167void DiscreteValueTest::settergetterTest()
168{
169 // create instance
170 Value<int> test(ValidValues);
171
172 // unset calling of get, throws
173 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
174 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
175
176 // setting invalid, throws
177 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
178 CPPUNIT_ASSERT_THROW(test.set(4), ParameterValueException);
179 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
180 CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
181
182 // checking all valid ones
183 for (int i=1; i<=3;++i) {
184 test.set(i);
185 CPPUNIT_ASSERT_EQUAL(i, test.get());
186 }
187
188}
189
190/** Unit test for setValue and getValue.
191 *
192 */
193void DiscreteValueTest::settergetterAsStringTest()
194{
195 // create instance
196 Value<int> test(ValidValues);
197
198 // unset calling of get, throws
199 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
200 CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
201
202 // setting invalid, throws
203 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
204 CPPUNIT_ASSERT_THROW(test.setAsString(toString(4)), ParameterValueException);
205 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
206 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
207
208 // checking all valid ones
209 for (int i=1; i<=3;++i) {
210 test.setAsString(toString(i));
211 CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
212 }
213}
214
215/** Unit test for comparator.
216 *
217 */
218void DiscreteValueTest::comparatorTest()
219{
220 {
221 // create instance
222 Value<int> test(ValidValues);
223 Value<int> instance(ValidValues);
224 test.set(1);
225 instance.set(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.get();
235 instance.set(2);
236 CPPUNIT_ASSERT(test != instance);
237 instance.set(oldvalue);
238 }
239 }
240 {
241 Value<int> test(ValidValues);
242 Value<int> instance(ValidValues);
243 dynamic_cast<DiscreteValidator<int> &>(instance.getValidator()).appendValidValue(4);
244
245 test.set(1);
246 instance.set(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.get();
256 instance.set(2);
257 CPPUNIT_ASSERT(test != instance);
258 instance.set(oldvalue);
259 }
260 }
261}
Note: See TracBrowser for help on using the repository browser.