source: src/Parameters/unittests/ContinuousValueTest.cpp@ 0cd8cf

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 0cd8cf 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: 13.7 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 * ContinuousValueTest.cpp
25 *
26 * Created on: Sep 29, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "ContinuousValueTest.hpp"
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "Parameters/Value.hpp"
42
43#ifdef HAVE_TESTRUNNER
44#include "UnitTestMain.hpp"
45#endif /*HAVE_TESTRUNNER*/
46
47// Registers the fixture into the 'registry'
48CPPUNIT_TEST_SUITE_REGISTRATION( ContinuousValueTest );
49
50
51void ContinuousValueTest::setUp()
52{
53 // failing asserts should be thrown
54 ASSERT_DO(Assert::Throw);
55
56 ValidIntRange = new range<int>(1,4);
57 ValidVectorRange = new range<Vector>(Vector(0,1,2), Vector(10,11,12));
58}
59
60void ContinuousValueTest::tearDown()
61{
62 delete ValidIntRange;
63 delete ValidVectorRange;
64}
65
66/************************************ tests ***********************************/
67
68/** Unit test for isValid.
69 *
70 */
71void ContinuousValueTest::isValidIntAsStringTest()
72{
73 // create instance
74 Value<int> test(*ValidIntRange);
75
76 // checking valid values
77 for (int i=1; i<=4;++i)
78 CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
79
80 // checking invalid values
81 for (int i=-10; i<=0;++i)
82 CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
83 for (int i=5; i<=0;++i)
84 CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
85}
86
87/** Unit test for isValid.
88 *
89 */
90void ContinuousValueTest::isValidIntTest()
91{
92 // create instance
93 Value<int> test(*ValidIntRange);
94
95 // checking valid values
96 for (int i=1; i<=4;++i)
97 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
98
99 // checking invalid values
100 for (int i=-10; i<=0;++i)
101 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
102 for (int i=5; i<=0;++i)
103 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
104}
105
106/** Unit test for setting/getting valid range.
107 *
108 */
109void ContinuousValueTest::setgetValidIntRangeTest()
110{
111 {
112 // create instance
113 Value<int> test(*ValidIntRange);
114
115 // extending range and checking
116 for (int i=5; i<=6;++i)
117 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
118 test.setValidRange(range<int>(1,6));
119 for (int i=5; i<=6;++i)
120 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
121 }
122
123 {
124 // create instance
125 Value<int> test(*ValidIntRange);
126
127 // lowering range with set value
128 test.set(4);
129 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
130 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
131 CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), ParameterValueException);
132
133 // no value is not set
134 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
135 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
136
137 // value gets invalidated in either case
138 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
139 }
140}
141
142/** Unit test for setValue and getValue.
143 *
144 */
145void ContinuousValueTest::settergetterIntAsStringTest()
146{
147 // create instance
148 Value<int> test(*ValidIntRange);
149
150 // unset calling of get, throws ParameterValueException
151 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
152 CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
153
154 // setting invalid, throws ParameterValueException
155 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
156 CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException);
157 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
158 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
159
160 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
161 // checking all valid ones
162 for (int i=1; i<=4;++i) {
163 test.setAsString(toString(i));
164 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
165 CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
166 }
167}
168
169/** Unit test for setters and getters.
170 *
171 */
172void ContinuousValueTest::settergetterIntTest()
173{
174 // create instance
175 Value<int> test(*ValidIntRange);
176
177 // unset calling of get, throws ParameterValueException
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.get(), ParameterValueException);
180
181 // setting invalid, throws ParameterValueException
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(5), ParameterValueException);
184 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
185 CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
186
187 // checking all valid ones
188 for (int i=1; i<=4;++i) {
189 test.set(i);
190 CPPUNIT_ASSERT_EQUAL(i, test.get());
191 }
192}
193
194/** Unit test for comparator.
195 *
196 */
197void ContinuousValueTest::comparatorIntTest()
198{
199 {
200 // create instance
201 Value<int> test(*ValidIntRange);
202 Value<int> instance(*ValidIntRange);
203 test.set(1);
204 instance.set(1);
205
206 // same value, same range
207 {
208 CPPUNIT_ASSERT(test == instance);
209 }
210
211 // different value, same range
212 {
213 const int oldvalue = instance.get();
214 instance.set(2);
215 CPPUNIT_ASSERT(test != instance);
216 instance.set(oldvalue);
217 }
218 }
219 {
220 Value<int> test(*ValidIntRange);
221 range<int> OtherValidIntRange(1,5);
222 Value<int> instance(OtherValidIntRange);
223
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
242
243
244/***************************** vector tests ***********************************/
245
246/** Unit test for isValid.
247 *
248 */
249void ContinuousValueTest::isValidVectorAsStringTest()
250{
251 // create instance
252 /*ContinuousValue<Vector> test(*ValidVectorRange);
253
254 // checking valid values
255 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(0,1,2)));
256 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(9.9,10.9,11.9)));
257 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(5,5,5)));
258
259 // checking invalid values
260 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-0.1,0.9,1.9)));
261 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(10.1,11.1,12.1)));
262 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,-1)));
263 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,5)));
264 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,5)));
265 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,5,20)));
266 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,5)));
267 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,5)));
268 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(0,0,0)));
269 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,-1,-1)));
270 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,5,-1)));
271 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(-1,-1,5)));
272 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20)));
273 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20)));
274 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/
275}
276
277/** Unit test for isValid.
278 *
279 */
280void ContinuousValueTest::isValidVectorTest()
281{
282 // create instance
283 Value<Vector> test(*ValidVectorRange);
284
285 // checking valid values
286 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(0,1,2)));
287 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(9.9,10.9,11.9)));
288 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(5,5,5)));
289
290 // checking invalid values
291 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-0.1,0.9,1.9)));
292 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(10.1,11.1,12.1)));
293 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,-1)));
294 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,5)));
295 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,5)));
296 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,5,20)));
297 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,5)));
298 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,5)));
299 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(0,0,0)));
300 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,-1,-1)));
301 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,5,-1)));
302 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(-1,-1,5)));
303 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(5,20,20)));
304 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,5,20)));
305 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(20,20,5)));
306}
307
308/** Unit test for setting/getting valid range.
309 *
310 */
311void ContinuousValueTest::setgetValidVectorRangeTest()
312{
313 {
314 // create instance
315 Value<Vector> test(*ValidVectorRange);
316
317 // extending range and checking
318 for (int i=15; i<=16;++i)
319 CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5)));
320 test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12)));
321 for (int i=15; i<=16;++i)
322 CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5)));
323 }
324
325 {
326 // create instance
327 Value<Vector> test(*ValidVectorRange);
328
329 // lowering range with set value
330 test.set(Vector(4,4,4));
331 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
332 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
333 CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException);
334
335 // no value is not set
336 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
337 CPPUNIT_ASSERT_THROW(test.get(), ParameterException);
338
339 // value gets invalidated in either case
340 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
341 }
342}
343
344/** Unit test for setValue and getValue.
345 *
346 */
347void ContinuousValueTest::settergetterVectorAsStringTest()
348{
349 // create instance
350 /*Value<Vector> test(*ValidVectorRange);
351
352 // unset calling of get, throws
353#ifndef NDEBUG
354 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
355 CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
356#endif
357
358 // setting invalid, throws
359#ifndef NDEBUG
360 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
361 CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,0,0)), Assert::AssertionFailure);
362#endif
363#ifndef NDEBUG
364 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
365 CPPUNIT_ASSERT_THROW(test.setValue(Vector(5,20,5)), Assert::AssertionFailure);
366#endif
367
368 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
369 // checking some valid ones
370 for (int i=1; i<=4;++i) {
371 Vector v(i,5,5);
372 test.setValue(v);
373 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
374 CPPUNIT_ASSERT_EQUAL(v, test.getValue());
375 }*/
376}
377
378/** Unit test for setters and getters.
379 *
380 */
381void ContinuousValueTest::settergetterVectorTest()
382{
383 // create instance
384 Value<Vector> test(*ValidVectorRange);
385
386 // unset calling of get, throws
387 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
388 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
389
390 // setting invalid, throws
391 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
392 CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException);
393 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
394 CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException);
395
396 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
397 // checking some valid ones
398 for (int i=1; i<=4;++i) {
399 Vector v(i,5,5);
400 test.set(v);
401 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
402 CPPUNIT_ASSERT_EQUAL(v, test.get());
403 }
404}
405
406/** Unit test for comparator.
407 *
408 */
409void ContinuousValueTest::comparatorVectorTest()
410{
411 {
412 // create instance
413 Value<Vector> test(*ValidVectorRange);
414 Value<Vector> instance(*ValidVectorRange);
415 test.set(Vector(5,6,7));
416 instance.set(Vector(5,6,7));
417
418 // same value, same range
419 {
420 CPPUNIT_ASSERT(test == instance);
421 }
422
423 // different value, same range
424 {
425 const Vector oldvalue = instance.get();
426 instance.set(Vector(2,3,4));
427 CPPUNIT_ASSERT(test != instance);
428 instance.set(oldvalue);
429 }
430 }
431 {
432 Value<Vector> test(*ValidVectorRange);
433 range<Vector> OtherValidVectorRange(Vector(0,1,2), Vector(20,21,22));
434 Value<Vector> instance(OtherValidVectorRange);
435
436 test.set(Vector(1,2,3));
437 instance.set(Vector(1,2,3));
438
439 // same value, same range
440 {
441 CPPUNIT_ASSERT(test != instance);
442 }
443
444 // different value, same range
445 {
446 const Vector oldvalue = instance.get();
447 instance.set(Vector(2,3,4));
448 CPPUNIT_ASSERT(test != instance);
449 instance.set(oldvalue);
450 }
451 }
452}
Note: See TracBrowser for help on using the repository browser.