source: src/Parameters/unittests/ValueTest.cpp@ 4892c3

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

added ValueTest (unit test)

  • fixed many minor problems in Value<T> and Validator<T>...
  • Property mode set to 100644
File size: 4.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 * 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/DummyValidator.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( ValueTest );
38
39
40void ValueTest::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 ValueTest::tearDown()
51{
52 ValidValues.clear();
53}
54
55/************************************ tests ***********************************/
56
57
58/** Unit test for isValid.
59 *
60 */
61void ValueTest::isValidTest()
62{
63 // create instance
64 Value<int> test(ValidValues);
65
66 // checking valid values
67 for (int i=1; i<=3;++i)
68 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
69
70 // checking invalid values
71 for (int i=-10; i<=0;++i)
72 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
73 for (int i=4; i<=0;++i)
74 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
75}
76
77/** Unit test for appendValidValue.
78 *
79 */
80void ValueTest::appendValidValueTest()
81{
82 // create instance
83/* Value<int> test(ValidValues);
84
85 // adding values 4,5,6
86 for (int i=4; i<=6;++i) {
87 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
88 test.appendValidValue(i);
89 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
90 }
91
92 // adding same value, throws assertion
93 const size_t size_before = test.ValidValues.size();
94#ifndef NDEBUG
95 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
96 for (int i=1; i<=6;++i)
97 CPPUNIT_ASSERT_THROW(test.appendValidValue(i), Assert::AssertionFailure);
98#endif
99 CPPUNIT_ASSERT_EQUAL( size_before, test.ValidValues.size() );
100
101 // checking valid values
102 for (int i=1; i<=6;++i)
103 CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
104
105 // checking invalid values
106 for (int i=-10; i<=0;++i)
107 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
108
109 // checking invalid values
110 for (int i=7; i<=10;++i)
111 CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));*/
112}
113
114/** Unit test for setters and getters.
115 *
116 */
117void ValueTest::settergetterTest()
118{
119 // create instance
120 Value<int> test(ValidValues);
121
122 // unset calling of get, throws
123#ifndef NDEBUG
124 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
125 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);
126#endif
127
128 // setting invalid, throws
129#ifndef NDEBUG
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.set(4), Assert::AssertionFailure);
132#endif
133#ifndef NDEBUG
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.set(0), Assert::AssertionFailure);
136#endif
137
138 // checking all valid ones
139 for (int i=1; i<=3;++i) {
140 test.set(i);
141 CPPUNIT_ASSERT_EQUAL(i, test.get());
142 }
143
144}
145
146/** Unit test for comparator.
147 *
148 */
149void ValueTest::comparatorTest()
150{
151 {
152 // create instance
153 Value<int> test(ValidValues);
154 Value<int> instance(ValidValues);
155 test.set(1);
156 instance.set(1);
157
158 // same value, same range
159 {
160 CPPUNIT_ASSERT(test == instance);
161 }
162
163 // different value, same range
164 {
165 const int oldvalue = instance.get();
166 instance.set(2);
167 CPPUNIT_ASSERT(test != instance);
168 instance.set(oldvalue);
169 }
170 }
171 {
172 Value<int> test(ValidValues);
173 Value<int> instance(ValidValues);
174// instance.appendValidValue(4); TODO
175
176 test.set(1);
177 instance.set(1);
178
179 // same value, same range
180 {
181 //CPPUNIT_ASSERT(test != instance);
182 }
183
184 // different value, same range
185 {
186 const int oldvalue = instance.get();
187 instance.set(2);
188 CPPUNIT_ASSERT(test != instance);
189 instance.set(oldvalue);
190 }
191 }
192}
Note: See TracBrowser for help on using the repository browser.