| [dd067a] | 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'
 | 
|---|
 | 39 | CPPUNIT_TEST_SUITE_REGISTRATION( Box_BoundaryConditionsTest );
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | void 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 | 
 | 
|---|
 | 48 | void Box_BoundaryConditionsTest::tearDown()
 | 
|---|
 | 49 | {
 | 
|---|
 | 50 |   delete bc;
 | 
|---|
 | 51 | }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | void 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 | 
 | 
|---|
 | 67 | void 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 | 
 | 
|---|
 | 100 | void Box_BoundaryConditionsTest::outputTest()
 | 
|---|
 | 101 | {
 | 
|---|
 | 102 |   std::stringstream outstream;
 | 
|---|
 | 103 |   outstream << *bc;
 | 
|---|
 | 104 |   CPPUNIT_ASSERT( outstream.str() == std::string("Wrap, Wrap, Wrap"));
 | 
|---|
 | 105 | }
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | void 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 | 
 | 
|---|
 | 131 | void 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 | 
 | 
|---|