source: src/Parser/unittests/DiscreteValueUnitTest.cpp@ 3308b6

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 3308b6 was e09d67, checked in by Frederik Heber <heber@…>, 14 years ago

Added class DiscreteValue that contains enums.

  • class has extensive unit test.
  • this should replace enums in MpqcParser_Parameters.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 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/DiscreteValue.hpp"
27
28#ifdef HAVE_TESTRUNNER
29#include "UnitTestMain.hpp"
30#endif /*HAVE_TESTRUNNER*/
31
32using namespace std;
33
34// Registers the fixture into the 'registry'
35CPPUNIT_TEST_SUITE_REGISTRATION( DiscreteValueTest );
36
37
38void DiscreteValueTest::setUp()
39{
40 // failing asserts should be thrown
41 ASSERT_DO(Assert::Throw);
42
43 for (int i=1; i<=3;++i) {
44 ValidValues.push_back(i);
45 }
46}
47
48void DiscreteValueTest::tearDown()
49{
50 ValidValues.clear();
51}
52
53/************************************ tests ***********************************/
54
55/** Unit test for findIndexOfValue.
56 *
57 */
58void DiscreteValueTest::findIndexOfValueTest()
59{
60 // create instance
61 DiscreteValue<int> test(ValidValues);
62
63 // check valid values indices
64 CPPUNIT_ASSERT_EQUAL((size_t)0, test.findIndexOfValue(1));
65 CPPUNIT_ASSERT_EQUAL((size_t)1, test.findIndexOfValue(2));
66 CPPUNIT_ASSERT_EQUAL((size_t)2, test.findIndexOfValue(3));
67
68 // check invalid ones
69 for (int i=-10; i<=0;++i)
70 CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
71 for (int i=4; i<=0;++i)
72 CPPUNIT_ASSERT_EQUAL((size_t)-1, test.findIndexOfValue(i));
73}
74
75/** Unit test for isValid.
76 *
77 */
78void DiscreteValueTest::isValidTest()
79{
80 // create instance
81 DiscreteValue<int> test(ValidValues);
82
83 // checking valid values
84 for (int i=1; i<=3;++i)
85 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
86
87 // checking invalid values
88 for (int i=-10; i<=0;++i)
89 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
90 for (int i=4; i<=0;++i)
91 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
92}
93
94/** Unit test for appendValidValue.
95 *
96 */
97void DiscreteValueTest::appendValidValueTest()
98{
99 // create instance
100 DiscreteValue<int> test(ValidValues);
101
102 // adding values 4,5,6
103 for (int i=4; i<=6;++i) {
104 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
105 test.appendValidValue(i);
106 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
107 }
108
109 // adding same value, throws assertion
110#ifndef NDEBUG
111 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
112 for (int i=1; i<=6;++i)
113 CPPUNIT_ASSERT_THROW(test.appendValidValue(i), Assert::AssertionFailure);
114#endif
115
116 // checking valid values
117 for (int i=1; i<=6;++i)
118 CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
119
120 // checking invalid values
121 for (int i=-10; i<=0;++i)
122 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
123
124 // checking invalid values
125 for (int i=7; i<=10;++i)
126 CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
127}
128
129/** Unit test for setters and getters.
130 *
131 */
132void DiscreteValueTest::settergetterTest()
133{
134 // create instance
135 DiscreteValue<int> test(ValidValues);
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.get(), 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.set(4), 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.set(0), Assert::AssertionFailure);
151#endif
152
153 // checking all valid ones
154 for (int i=1; i<=3;++i) {
155 test.set(i);
156 CPPUNIT_ASSERT_EQUAL(i, test.get());
157 }
158}
159
160
161
Note: See TracBrowser for help on using the repository browser.