| [d8421f] | 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 | * ShapeRegistryUnitTest.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Sep 13, 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.hpp" | 
|---|
|  | 50 | #include "Shapes/BaseShapes_impl.hpp" | 
|---|
|  | 51 | #include "Shapes/Shape_impl.hpp" | 
|---|
|  | 52 | #include "Shapes/ShapeRegistry.hpp" | 
|---|
|  | 53 |  | 
|---|
|  | 54 | #include "ShapeRegistryUnitTest.hpp" | 
|---|
|  | 55 |  | 
|---|
|  | 56 | // Registers the fixture into the 'registry' | 
|---|
|  | 57 | CPPUNIT_TEST_SUITE_REGISTRATION( ShapeRegistryTest ); | 
|---|
|  | 58 |  | 
|---|
|  | 59 | void ShapeRegistryTest::setUp() | 
|---|
|  | 60 | { | 
|---|
|  | 61 | // failing asserts should be thrown | 
|---|
|  | 62 | ASSERT_DO(Assert::Throw); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | ShapeRegistry::getInstance(); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | Shape s = Sphere(); | 
|---|
|  | 67 | s.setName("Sphere1"); | 
|---|
|  | 68 | ShapeRegistry::getInstance().addShape(s); | 
|---|
|  | 69 | s = Cuboid(); | 
|---|
|  | 70 | s.setName("Cube1"); | 
|---|
|  | 71 | ShapeRegistry::getInstance().addShape(s); | 
|---|
|  | 72 | s = Sphere(Vector(1,0,0), 1); | 
|---|
|  | 73 | s.setName("Sphere2"); | 
|---|
|  | 74 | ShapeRegistry::getInstance().addShape(s); | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
|  | 77 | void ShapeRegistryTest::tearDown() | 
|---|
|  | 78 | { | 
|---|
|  | 79 | ShapeRegistry::purgeInstance(); | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 | void ShapeRegistryTest::queryTest() | 
|---|
|  | 83 | { | 
|---|
|  | 84 | CPPUNIT_ASSERT(ShapeRegistry::getInstance().isPresentByName("Sphere1")); | 
|---|
|  | 85 | CPPUNIT_ASSERT(ShapeRegistry::getInstance().isPresentByName("Sphere2")); | 
|---|
|  | 86 | CPPUNIT_ASSERT(ShapeRegistry::getInstance().isPresentByName("Cube1")); | 
|---|
|  | 87 | CPPUNIT_ASSERT(!ShapeRegistry::getInstance().isPresentByName("Sphere7")); | 
|---|
|  | 88 | CPPUNIT_ASSERT(!ShapeRegistry::getInstance().isPresentByName("sdfksdfhjkh")); | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | void ShapeRegistryTest::sphereTest() | 
|---|
|  | 92 | { | 
|---|
|  | 93 | CPPUNIT_ASSERT(ShapeRegistry::getInstance().isPresentByName("Sphere2")); | 
|---|
|  | 94 | Shape *s = ShapeRegistry::getInstance().getByName("Sphere2"); | 
|---|
|  | 95 |  | 
|---|
|  | 96 | CPPUNIT_ASSERT( s->isInside( Vector(1.5,0.,0.) ) ); | 
|---|
|  | 97 | CPPUNIT_ASSERT( s->isInside( Vector(1.,.5,0.) ) ); | 
|---|
|  | 98 | CPPUNIT_ASSERT( s->isInside( Vector(1.,0.,.5) ) ); | 
|---|
|  | 99 | CPPUNIT_ASSERT( s->isOnSurface( Vector(2.,0.,0.) ) ); | 
|---|
|  | 100 | CPPUNIT_ASSERT( s->isOnSurface( Vector(1.,1.,0.) ) ); | 
|---|
|  | 101 | CPPUNIT_ASSERT( s->isOnSurface( Vector(1.,0.,1.) ) ); | 
|---|
|  | 102 | CPPUNIT_ASSERT( !s->isInside( Vector(-.5,0.,0.) ) ); | 
|---|
|  | 103 | CPPUNIT_ASSERT( !s->isInside( Vector(0.,-.5,0.) ) ); | 
|---|
|  | 104 | CPPUNIT_ASSERT( !s->isInside( Vector(0.,0.,-.5) ) ); | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|