source: src/unittests/Box_BoundaryConditionsUnitTest.cpp@ aec098

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

Add new namespace BoundaryConditions with class BCContainer.

  • BCContainer is a convenience wrapper for the enumeration of the boundary conditions that allows easy setting/getting via strings.
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 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 * Box_BoundaryConditionsUnitTest.cpp
10 *
11 * Created on: Jan 2, 2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include <sstream>
25
26#include "Box_BoundaryConditions.hpp"
27#include "CodePatterns/Assert.hpp"
28#include "LinearAlgebra/defs.hpp"
29
30#include "Box_BoundaryConditionsUnitTest.hpp"
31
32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36/********************************************** Test classes **************************************/
37
38// Registers the fixture into the 'registry'
39CPPUNIT_TEST_SUITE_REGISTRATION( Box_BoundaryConditionsTest );
40
41void Box_BoundaryConditionsTest::setUp(){
42 // failing asserts should be thrown
43 ASSERT_DO(Assert::Throw);
44
45 CPPUNIT_ASSERT_NO_THROW( bc = new BoundaryConditions::BCContainer );
46}
47
48void Box_BoundaryConditionsTest::tearDown()
49{
50 delete bc;
51}
52
53void Box_BoundaryConditionsTest::getTest()
54{
55 // check default values
56 for (size_t index = 0; index < NDIM; ++index)
57 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(index));
58
59 // check throw
60#ifndef NDEBUG
61 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
62 CPPUNIT_ASSERT_THROW( bc->get(4), Assert::AssertionFailure );
63 CPPUNIT_ASSERT_THROW( bc->get(-1), Assert::AssertionFailure );
64#endif
65}
66
67void Box_BoundaryConditionsTest::setTest()
68{
69 // set to other values
70 bc->set(1, BoundaryConditions::Ignore);
71 bc->set(2, BoundaryConditions::Bounce);
72
73 // check that is not Wrap anymore
74 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(1) );
75 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(2) );
76
77 // check throw
78#ifndef NDEBUG
79 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
80 CPPUNIT_ASSERT_THROW( bc->set(4, BoundaryConditions::Wrap), Assert::AssertionFailure );
81 CPPUNIT_ASSERT_THROW( bc->set(-1, BoundaryConditions::Wrap), Assert::AssertionFailure );
82#endif
83
84 // set all at once
85 BoundaryConditions::Conditions_t conditions(3, BoundaryConditions::Wrap);
86
87 // check throw
88 conditions.resize(NDIM+1, BoundaryConditions::Wrap);
89#ifndef NDEBUG
90 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
91 CPPUNIT_ASSERT_THROW( bc->set(conditions), Assert::AssertionFailure );
92#endif
93 conditions.resize(NDIM-1, BoundaryConditions::Wrap);
94#ifndef NDEBUG
95 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
96 CPPUNIT_ASSERT_THROW( bc->set(conditions), Assert::AssertionFailure );
97#endif
98}
99
100void Box_BoundaryConditionsTest::outputTest()
101{
102 std::stringstream outstream;
103 outstream << *bc;
104 CPPUNIT_ASSERT( outstream.str() == std::string("Wrap, Wrap, Wrap"));
105}
106
107void Box_BoundaryConditionsTest::converterTest()
108{
109 // enum to string
110 for (size_t index = (size_t)0; index < (size_t)BoundaryConditions::MAX_BoundaryCondition_t;index++)
111 CPPUNIT_ASSERT_EQUAL(
112 bc->ConverterBiMap[(BoundaryConditions::BoundaryCondition_t)index],
113 bc->getName((BoundaryConditions::BoundaryCondition_t)index) );
114 // check throw
115#ifndef NDEBUG
116 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
117 CPPUNIT_ASSERT_THROW( bc->getName(BoundaryConditions::MAX_BoundaryCondition_t), Assert::AssertionFailure );
118#endif
119
120 // enum to string
121 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->getEnum(std::string("Wrap")) );
122 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->getEnum(std::string("Bounce")) );
123 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->getEnum(std::string("Ignore")) );
124 // check throw
125#ifndef NDEBUG
126 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
127 CPPUNIT_ASSERT_THROW( bc->getEnum("Unknown"), Assert::AssertionFailure );
128#endif
129}
130
131void Box_BoundaryConditionsTest::inputTest()
132{
133 // set by string
134 std::stringstream inputstream(" Bounce, Wrap, Ignore");
135 CPPUNIT_ASSERT_NO_THROW( inputstream >> *bc );
136
137 // check
138 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
139 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
140 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
141
142 // check throw
143 std::stringstream invalidstream1("Bounce");
144 std::stringstream invalidstream2("Bounce, Bounce, Wrap, Ignore");
145#ifndef NDEBUG
146 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
147 CPPUNIT_ASSERT_THROW( invalidstream1 >> *bc, Assert::AssertionFailure );
148 CPPUNIT_ASSERT_THROW( invalidstream2 >> *bc, Assert::AssertionFailure );
149#endif
150
151 // check that all is still the same
152 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
153 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
154 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
155}
156
Note: See TracBrowser for help on using the repository browser.