| [a367b8] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010-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 |  * ShapeFactoryUnitTest.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Sep 5, 2012
 | 
|---|
 | 27 |  *      Author: ankele
 | 
|---|
 | 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 <cmath>
 | 
|---|
 | 40 | #include <limits>
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 43 | #include "UnitTestMain.hpp"
 | 
|---|
 | 44 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 | #include "Helpers/defs.hpp"
 | 
|---|
 | 49 | #include "Shapes/BaseShapes_impl.hpp"
 | 
|---|
 | 50 | #include "Shapes/Shape_impl.hpp"
 | 
|---|
 | 51 | #include "Shapes/ShapeFactory.hpp"
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | #include "ShapeFactoryUnitTest.hpp"
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | // Registers the fixture into the 'registry'
 | 
|---|
 | 56 | CPPUNIT_TEST_SUITE_REGISTRATION( ShapeFactoryTest );
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | void ShapeFactoryTest::setUp()
 | 
|---|
 | 59 | {
 | 
|---|
 | 60 |   // failing asserts should be thrown
 | 
|---|
 | 61 |   ASSERT_DO(Assert::Throw);
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 |   ShapeFactory::getInstance();
 | 
|---|
 | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | void ShapeFactoryTest::tearDown()
 | 
|---|
 | 67 | {
 | 
|---|
 | 68 |   ShapeFactory::purgeInstance();
 | 
|---|
 | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | void ShapeFactoryTest::typeTest()
 | 
|---|
 | 72 | {
 | 
|---|
| [842aac] | 73 |   CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(NowhereType).getType(), NowhereType );
 | 
|---|
| [a367b8] | 74 | 
 | 
|---|
| [842aac] | 75 |   CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(EverywhereType).getType(), EverywhereType );
 | 
|---|
| [a367b8] | 76 | 
 | 
|---|
| [842aac] | 77 |   CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(SphereType).getType(), SphereType );
 | 
|---|
| [a367b8] | 78 | 
 | 
|---|
| [842aac] | 79 |   CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(CuboidType).getType(), CuboidType );
 | 
|---|
| [a367b8] | 80 | 
 | 
|---|
| [842aac] | 81 |   CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(CylinderType).getType(), CylinderType );
 | 
|---|
| [a367b8] | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | void ShapeFactoryTest::resizeTest()
 | 
|---|
 | 85 | {
 | 
|---|
| [842aac] | 86 |   Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(2., 2., 2.));
 | 
|---|
| [a367b8] | 87 | 
 | 
|---|
 | 88 |   CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
 | 
|---|
 | 89 |   CPPUNIT_ASSERT( s.isInside( Vector(0.,1.5,0.) ) );
 | 
|---|
 | 90 |   CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,1.5) ) );
 | 
|---|
 | 91 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
 | 
|---|
 | 92 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,2.,0.) ) );
 | 
|---|
 | 93 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,2.) ) );
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | void ShapeFactoryTest::translateTest()
 | 
|---|
 | 97 | {
 | 
|---|
| [842aac] | 98 |   Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(1., 0., 0.));
 | 
|---|
| [a367b8] | 99 | 
 | 
|---|
 | 100 |   CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
 | 
|---|
 | 101 |   CPPUNIT_ASSERT( s.isInside( Vector(1.,.5,0.) ) );
 | 
|---|
 | 102 |   CPPUNIT_ASSERT( s.isInside( Vector(1.,0.,.5) ) );
 | 
|---|
 | 103 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
 | 
|---|
 | 104 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,1.,0.) ) );
 | 
|---|
 | 105 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,1.) ) );
 | 
|---|
 | 106 |   CPPUNIT_ASSERT( !s.isInside( Vector(-.5,0.,0.) ) );
 | 
|---|
 | 107 |   CPPUNIT_ASSERT( !s.isInside( Vector(0.,-.5,0.) ) );
 | 
|---|
 | 108 |   CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,-.5) ) );
 | 
|---|
 | 109 | }
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 | void ShapeFactoryTest::stretchTest()
 | 
|---|
 | 112 | {
 | 
|---|
| [842aac] | 113 |   Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(2., 1., 1.));
 | 
|---|
| [a367b8] | 114 | 
 | 
|---|
 | 115 |   CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
 | 
|---|
 | 116 |   CPPUNIT_ASSERT( !s.isInside( Vector(0.,1.5,0.) ) );
 | 
|---|
 | 117 |   CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,1.5) ) );
 | 
|---|
 | 118 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
 | 
|---|
 | 119 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
 | 
|---|
 | 120 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
 | 
|---|
 | 121 | }
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | void ShapeFactoryTest::transformTest()
 | 
|---|
 | 124 | {
 | 
|---|
| [842aac] | 125 |   Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(1., 1., 1.), 45., 0., 0.);
 | 
|---|
| [a367b8] | 126 | 
 | 
|---|
 | 127 |   CPPUNIT_ASSERT( s.isInside( Vector(.5,0.,0.) ) );
 | 
|---|
 | 128 |   CPPUNIT_ASSERT( s.isInside( Vector(0.,.5,0.) ) );
 | 
|---|
 | 129 |   CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,.5) ) );
 | 
|---|
 | 130 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,0.) ) );
 | 
|---|
 | 131 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
 | 
|---|
 | 132 |   CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,1.) ) );
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | void ShapeFactoryTest::getterSetterTest()
 | 
|---|
 | 136 | {
 | 
|---|
 | 137 | #ifndef NDEBUG
 | 
|---|
| [842aac] | 138 |   CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce((ShapeType)-1), Assert::AssertionFailure );
 | 
|---|
| [a367b8] | 139 | #endif
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 | #ifndef NDEBUG
 | 
|---|
| [842aac] | 143 |   CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(0., 0., 0.)), Assert::AssertionFailure );
 | 
|---|
| [a367b8] | 144 | #endif
 | 
|---|
 | 145 | #ifndef NDEBUG
 | 
|---|
| [842aac] | 146 |   CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(1., 1., 0.)), Assert::AssertionFailure );
 | 
|---|
| [a367b8] | 147 | #endif
 | 
|---|
 | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|