| 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 | * TesselationUnitTest.cpp | 
|---|
| 25 | * | 
|---|
| 26 | *  Created on: Aug 26, 2009 | 
|---|
| 27 | *      Author: heber | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | // include config.h | 
|---|
| 31 | #ifdef HAVE_CONFIG_H | 
|---|
| 32 | #include <config.h> | 
|---|
| 33 | #endif | 
|---|
| 34 |  | 
|---|
| 35 | using namespace std; | 
|---|
| 36 |  | 
|---|
| 37 | #include <cppunit/CompilerOutputter.h> | 
|---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
| 39 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
| 40 |  | 
|---|
| 41 | #include <cstring> | 
|---|
| 42 |  | 
|---|
| 43 | #include "CodePatterns/Log.hpp" | 
|---|
| 44 | #include "Helpers/defs.hpp" | 
|---|
| 45 | #include "LinkedCell/PointCloudAdaptor.hpp" | 
|---|
| 46 | #include "LinkedCell/linkedcell.hpp" | 
|---|
| 47 | #include "Tesselation/BoundaryLineSet.hpp" | 
|---|
| 48 | #include "Tesselation/BoundaryTriangleSet.hpp" | 
|---|
| 49 | #include "Tesselation/CandidateForTesselation.hpp" | 
|---|
| 50 | #include "Atom/TesselPoint.hpp" | 
|---|
| 51 |  | 
|---|
| 52 | #include "TesselationUnitTest.hpp" | 
|---|
| 53 |  | 
|---|
| 54 | #ifdef HAVE_TESTRUNNER | 
|---|
| 55 | #include "UnitTestMain.hpp" | 
|---|
| 56 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 57 |  | 
|---|
| 58 | const double TesselationTest::SPHERERADIUS=2.; | 
|---|
| 59 |  | 
|---|
| 60 | /********************************************** Test classes **************************************/ | 
|---|
| 61 |  | 
|---|
| 62 | // Registers the fixture into the 'registry' | 
|---|
| 63 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest ); | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | void TesselationTest::setUp() | 
|---|
| 67 | { | 
|---|
| 68 | // create corners | 
|---|
| 69 | class TesselPoint *Walker; | 
|---|
| 70 | Walker = new TesselPoint; | 
|---|
| 71 | Walker->setPosition(Vector(1., 0., -1.)); | 
|---|
| 72 | Walker->setName("1"); | 
|---|
| 73 | Walker->setNr(1); | 
|---|
| 74 | Corners.push_back(Walker); | 
|---|
| 75 | Walker = new TesselPoint; | 
|---|
| 76 | Walker->setPosition(Vector(-1., 1., -1.)); | 
|---|
| 77 | Walker->setName("2"); | 
|---|
| 78 | Walker->setNr(2); | 
|---|
| 79 | Corners.push_back(Walker); | 
|---|
| 80 | Walker = new TesselPoint; | 
|---|
| 81 | Walker->setPosition(Vector(-1., -1., -1.)); | 
|---|
| 82 | Walker->setName("3"); | 
|---|
| 83 | Walker->setNr(3); | 
|---|
| 84 | Corners.push_back(Walker); | 
|---|
| 85 | Walker = new TesselPoint; | 
|---|
| 86 | Walker->setPosition(Vector(-1., 0., 1.)); | 
|---|
| 87 | Walker->setName("4"); | 
|---|
| 88 | Walker->setNr(4); | 
|---|
| 89 | Corners.push_back(Walker); | 
|---|
| 90 |  | 
|---|
| 91 | // create tesselation | 
|---|
| 92 | TesselStruct = new Tesselation; | 
|---|
| 93 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() ); | 
|---|
| 94 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() ); | 
|---|
| 95 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() ); | 
|---|
| 96 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList"); | 
|---|
| 97 | (*TesselStruct)(cloud, SPHERERADIUS); | 
|---|
| 98 | }; | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | void TesselationTest::tearDown() | 
|---|
| 102 | { | 
|---|
| 103 | delete(TesselStruct); | 
|---|
| 104 | for (TesselPointSTLList::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) | 
|---|
| 105 | delete(*Runner); | 
|---|
| 106 | Corners.clear(); | 
|---|
| 107 | logger::purgeInstance(); | 
|---|
| 108 | errorLogger::purgeInstance(); | 
|---|
| 109 | }; | 
|---|
| 110 |  | 
|---|
| 111 | /** UnitTest for Contains...() | 
|---|
| 112 | * | 
|---|
| 113 | */ | 
|---|
| 114 | void TesselationTest::ContainmentTest() | 
|---|
| 115 | { | 
|---|
| 116 | class BoundaryPointSet *point = NULL; | 
|---|
| 117 | class BoundaryLineSet *line = NULL; | 
|---|
| 118 |  | 
|---|
| 119 | // check ContainsBoundaryPoint | 
|---|
| 120 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) { | 
|---|
| 121 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0])); | 
|---|
| 122 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1])); | 
|---|
| 123 | } | 
|---|
| 124 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) { | 
|---|
| 125 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { | 
|---|
| 126 | point = PointRunner->second; | 
|---|
| 127 | for (int i=0;i<3;i++) | 
|---|
| 128 | if (point == (Runner->second)->endpoints[i]) | 
|---|
| 129 | point = NULL; | 
|---|
| 130 | if (point != NULL) | 
|---|
| 131 | break; | 
|---|
| 132 | } | 
|---|
| 133 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0])); | 
|---|
| 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1])); | 
|---|
| 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2])); | 
|---|
| 136 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point)); | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | // check ContainsBoundaryLine | 
|---|
| 140 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) { | 
|---|
| 141 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) { | 
|---|
| 142 | line = LineRunner->second; | 
|---|
| 143 | for (int i=0;i<3;i++) | 
|---|
| 144 | if (line == (Runner->second)->lines[i]) | 
|---|
| 145 | line = NULL; | 
|---|
| 146 | if (line != NULL) | 
|---|
| 147 | break; | 
|---|
| 148 | } | 
|---|
| 149 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0])); | 
|---|
| 150 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1])); | 
|---|
| 151 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2])); | 
|---|
| 152 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line)); | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | // check IsPresentTupel | 
|---|
| 156 | CPPUNIT_ASSERT_EQUAL( true, true ); | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | /** UnitTest for Tesselation::GetAllTriangles() | 
|---|
| 160 | * | 
|---|
| 161 | */ | 
|---|
| 162 | void TesselationTest::GetAllTrianglesTest() | 
|---|
| 163 | { | 
|---|
| 164 | class BoundaryPointSet *Walker = NULL; | 
|---|
| 165 |  | 
|---|
| 166 | // check that there are three adjacent triangles for every boundary point | 
|---|
| 167 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) { | 
|---|
| 168 | Walker = Runner->second; | 
|---|
| 169 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker); | 
|---|
| 170 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() ); | 
|---|
| 171 | // check that the returned triangle all contain the Walker | 
|---|
| 172 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++) | 
|---|
| 173 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) ); | 
|---|
| 174 | delete(triangles); | 
|---|
| 175 | } | 
|---|
| 176 | } | 
|---|