source: src/unittests/Box_BoundaryConditionsUnitTest.cpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef 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: 6.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 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 * Box_BoundaryConditionsUnitTest.cpp
25 *
26 * Created on: Jan 2, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include <sstream>
40
41#include "Box_BoundaryConditions.hpp"
42#include "CodePatterns/Assert.hpp"
43#include "LinearAlgebra/defs.hpp"
44
45#include "Box_BoundaryConditionsUnitTest.hpp"
46
47#ifdef HAVE_TESTRUNNER
48#include "UnitTestMain.hpp"
49#endif /*HAVE_TESTRUNNER*/
50
51/********************************************** Test classes **************************************/
52
53// Registers the fixture into the 'registry'
54CPPUNIT_TEST_SUITE_REGISTRATION( Box_BoundaryConditionsTest );
55
56void Box_BoundaryConditionsTest::setUp(){
57 // failing asserts should be thrown
58 ASSERT_DO(Assert::Throw);
59
60 CPPUNIT_ASSERT_NO_THROW( bc = new BoundaryConditions::BCContainer );
61}
62
63void Box_BoundaryConditionsTest::tearDown()
64{
65 delete bc;
66}
67
68void Box_BoundaryConditionsTest::getTest()
69{
70 // check default values
71 for (size_t index = 0; index < NDIM; ++index)
72 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(index));
73
74 // check throw
75#ifndef NDEBUG
76 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
77 CPPUNIT_ASSERT_THROW( bc->get(4), Assert::AssertionFailure );
78 CPPUNIT_ASSERT_THROW( bc->get(-1), Assert::AssertionFailure );
79#endif
80}
81
82void Box_BoundaryConditionsTest::setTest()
83{
84 // set to other values
85 bc->set(1, BoundaryConditions::Ignore);
86 bc->set(2, BoundaryConditions::Bounce);
87
88 // check that is not Wrap anymore
89 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(1) );
90 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(2) );
91
92 // check throw
93#ifndef NDEBUG
94 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
95 CPPUNIT_ASSERT_THROW( bc->set(4, BoundaryConditions::Wrap), Assert::AssertionFailure );
96 CPPUNIT_ASSERT_THROW( bc->set(-1, BoundaryConditions::Wrap), Assert::AssertionFailure );
97#endif
98
99 // set all at once
100 BoundaryConditions::Conditions_t conditions(3, BoundaryConditions::Wrap);
101
102 // check throw
103 conditions.resize(NDIM+1, BoundaryConditions::Wrap);
104#ifndef NDEBUG
105 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
106 CPPUNIT_ASSERT_THROW( bc->set(conditions), Assert::AssertionFailure );
107#endif
108 conditions.resize(NDIM-1, BoundaryConditions::Wrap);
109#ifndef NDEBUG
110 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
111 CPPUNIT_ASSERT_THROW( bc->set(conditions), Assert::AssertionFailure );
112#endif
113}
114
115void Box_BoundaryConditionsTest::outputTest()
116{
117 std::stringstream outstream;
118 outstream << *bc;
119 CPPUNIT_ASSERT( outstream.str() == std::string("Wrap Wrap Wrap"));
120}
121
122void Box_BoundaryConditionsTest::converterTest()
123{
124 // enum to string
125 for (size_t index = (size_t)0; index < (size_t)BoundaryConditions::MAX_BoundaryCondition_t;index++)
126 CPPUNIT_ASSERT_EQUAL(
127 bc->ConverterBiMap[(BoundaryConditions::BoundaryCondition_t)index],
128 bc->getName((BoundaryConditions::BoundaryCondition_t)index) );
129 // check throw
130#ifndef NDEBUG
131 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
132 CPPUNIT_ASSERT_THROW( bc->getName(BoundaryConditions::MAX_BoundaryCondition_t), Assert::AssertionFailure );
133#endif
134
135 // enum to string
136 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->getEnum(std::string("Wrap")) );
137 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->getEnum(std::string("Bounce")) );
138 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->getEnum(std::string("Ignore")) );
139 // check throw
140#ifndef NDEBUG
141 std::cout << "The following assertion is intended and does not represent a failure of the test.\n";
142 CPPUNIT_ASSERT_THROW( bc->getEnum("Unknown"), Assert::AssertionFailure );
143#endif
144}
145
146void Box_BoundaryConditionsTest::inputTest()
147{
148 // set by string
149 std::stringstream inputstream(" Bounce,Wrap,Ignore");
150 std::stringstream otherinputstream(" Bounce Wrap Ignore");
151 std::stringstream anotherinputstream(" Bounce, Wrap, Ignore");
152
153 // check
154 CPPUNIT_ASSERT_NO_THROW( inputstream >> *bc );
155 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
156 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
157 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
158
159 // check
160 CPPUNIT_ASSERT_NO_THROW( otherinputstream >> *bc );
161 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
162 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
163 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
164
165 // check
166 CPPUNIT_ASSERT_NO_THROW( anotherinputstream >> *bc );
167 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
168 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
169 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
170
171 // check throw
172 std::stringstream invalidstream1("Bounce");
173 std::stringstream invalidstream2("Bounce, Bounce, Wrap, Ignore");
174#ifndef NDEBUG
175 std::cout << "The following assertions are intended and do not represent a failure of the test.\n";
176 CPPUNIT_ASSERT_THROW( invalidstream1 >> *bc, Assert::AssertionFailure );
177 CPPUNIT_ASSERT_THROW( invalidstream2 >> *bc, Assert::AssertionFailure );
178#endif
179
180 // check that all is still the same
181 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Bounce, bc->get(0) );
182 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Wrap, bc->get(1) );
183 CPPUNIT_ASSERT_EQUAL( BoundaryConditions::Ignore, bc->get(2) );
184}
185
Note: See TracBrowser for help on using the repository browser.