| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [d04966] | 8 | /* | 
|---|
| [f844ef] | 9 | * TesselationUnitTest.cpp | 
|---|
| [d04966] | 10 | * | 
|---|
|  | 11 | *  Created on: Aug 26, 2009 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
| [d04966] | 19 |  | 
|---|
|  | 20 | using namespace std; | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [49e1ae] | 26 | #include <cstring> | 
|---|
|  | 27 |  | 
|---|
| [53c7fc] | 28 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 29 | #include "Helpers/defs.hpp" | 
|---|
|  | 30 | #include "LinkedCell/PointCloudAdaptor.hpp" | 
|---|
| [cc21cd] | 31 | #include "LinkedCell/linkedcell.hpp" | 
|---|
| [d127c8] | 32 | #include "Tesselation/BoundaryLineSet.hpp" | 
|---|
|  | 33 | #include "Tesselation/BoundaryTriangleSet.hpp" | 
|---|
|  | 34 | #include "Tesselation/CandidateForTesselation.hpp" | 
|---|
| [6f0841] | 35 | #include "Atom/TesselPoint.hpp" | 
|---|
| [f844ef] | 36 |  | 
|---|
|  | 37 | #include "TesselationUnitTest.hpp" | 
|---|
| [d04966] | 38 |  | 
|---|
| [9b6b2f] | 39 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 40 | #include "UnitTestMain.hpp" | 
|---|
|  | 41 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 42 |  | 
|---|
| [88b400] | 43 | const double TesselationTest::SPHERERADIUS=2.; | 
|---|
| [d04966] | 44 |  | 
|---|
|  | 45 | /********************************************** Test classes **************************************/ | 
|---|
|  | 46 |  | 
|---|
|  | 47 | // Registers the fixture into the 'registry' | 
|---|
|  | 48 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest ); | 
|---|
|  | 49 |  | 
|---|
|  | 50 |  | 
|---|
|  | 51 | void TesselationTest::setUp() | 
|---|
|  | 52 | { | 
|---|
|  | 53 | // create corners | 
|---|
|  | 54 | class TesselPoint *Walker; | 
|---|
|  | 55 | Walker = new TesselPoint; | 
|---|
| [d74077] | 56 | Walker->setPosition(Vector(1., 0., -1.)); | 
|---|
| [68f03d] | 57 | Walker->setName("1"); | 
|---|
| [a479fa] | 58 | Walker->setNr(1); | 
|---|
| [d04966] | 59 | Corners.push_back(Walker); | 
|---|
|  | 60 | Walker = new TesselPoint; | 
|---|
| [d74077] | 61 | Walker->setPosition(Vector(-1., 1., -1.)); | 
|---|
| [68f03d] | 62 | Walker->setName("2"); | 
|---|
| [a479fa] | 63 | Walker->setNr(2); | 
|---|
| [d04966] | 64 | Corners.push_back(Walker); | 
|---|
|  | 65 | Walker = new TesselPoint; | 
|---|
| [d74077] | 66 | Walker->setPosition(Vector(-1., -1., -1.)); | 
|---|
| [68f03d] | 67 | Walker->setName("3"); | 
|---|
| [a479fa] | 68 | Walker->setNr(3); | 
|---|
| [d04966] | 69 | Corners.push_back(Walker); | 
|---|
|  | 70 | Walker = new TesselPoint; | 
|---|
| [d74077] | 71 | Walker->setPosition(Vector(-1., 0., 1.)); | 
|---|
| [68f03d] | 72 | Walker->setName("4"); | 
|---|
| [a479fa] | 73 | Walker->setNr(4); | 
|---|
| [d04966] | 74 | Corners.push_back(Walker); | 
|---|
|  | 75 |  | 
|---|
|  | 76 | // create tesselation | 
|---|
|  | 77 | TesselStruct = new Tesselation; | 
|---|
| [c15ca2] | 78 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() ); | 
|---|
|  | 79 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() ); | 
|---|
|  | 80 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() ); | 
|---|
| [cc21cd] | 81 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList"); | 
|---|
|  | 82 | (*TesselStruct)(cloud, SPHERERADIUS); | 
|---|
| [d04966] | 83 | }; | 
|---|
|  | 84 |  | 
|---|
|  | 85 |  | 
|---|
|  | 86 | void TesselationTest::tearDown() | 
|---|
|  | 87 | { | 
|---|
|  | 88 | delete(TesselStruct); | 
|---|
| [34c43a] | 89 | for (TesselPointSTLList::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) | 
|---|
| [d04966] | 90 | delete(*Runner); | 
|---|
|  | 91 | Corners.clear(); | 
|---|
| [c15ca2] | 92 | logger::purgeInstance(); | 
|---|
|  | 93 | errorLogger::purgeInstance(); | 
|---|
| [d04966] | 94 | }; | 
|---|
|  | 95 |  | 
|---|
|  | 96 | /** UnitTest for Contains...() | 
|---|
|  | 97 | * | 
|---|
|  | 98 | */ | 
|---|
|  | 99 | void TesselationTest::ContainmentTest() | 
|---|
|  | 100 | { | 
|---|
|  | 101 | class BoundaryPointSet *point = NULL; | 
|---|
|  | 102 | class BoundaryLineSet *line = NULL; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | // check ContainsBoundaryPoint | 
|---|
|  | 105 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) { | 
|---|
|  | 106 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0])); | 
|---|
|  | 107 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1])); | 
|---|
|  | 108 | } | 
|---|
|  | 109 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) { | 
|---|
|  | 110 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { | 
|---|
|  | 111 | point = PointRunner->second; | 
|---|
|  | 112 | for (int i=0;i<3;i++) | 
|---|
|  | 113 | if (point == (Runner->second)->endpoints[i]) | 
|---|
|  | 114 | point = NULL; | 
|---|
|  | 115 | if (point != NULL) | 
|---|
|  | 116 | break; | 
|---|
|  | 117 | } | 
|---|
|  | 118 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0])); | 
|---|
|  | 119 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1])); | 
|---|
|  | 120 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2])); | 
|---|
|  | 121 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point)); | 
|---|
|  | 122 | } | 
|---|
|  | 123 |  | 
|---|
|  | 124 | // check ContainsBoundaryLine | 
|---|
|  | 125 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) { | 
|---|
|  | 126 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) { | 
|---|
|  | 127 | line = LineRunner->second; | 
|---|
|  | 128 | for (int i=0;i<3;i++) | 
|---|
|  | 129 | if (line == (Runner->second)->lines[i]) | 
|---|
|  | 130 | line = NULL; | 
|---|
|  | 131 | if (line != NULL) | 
|---|
|  | 132 | break; | 
|---|
|  | 133 | } | 
|---|
|  | 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0])); | 
|---|
|  | 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1])); | 
|---|
|  | 136 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2])); | 
|---|
|  | 137 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line)); | 
|---|
|  | 138 | } | 
|---|
|  | 139 |  | 
|---|
|  | 140 | // check IsPresentTupel | 
|---|
|  | 141 | CPPUNIT_ASSERT_EQUAL( true, true ); | 
|---|
|  | 142 | } | 
|---|
|  | 143 |  | 
|---|
|  | 144 | /** UnitTest for Tesselation::GetAllTriangles() | 
|---|
|  | 145 | * | 
|---|
|  | 146 | */ | 
|---|
|  | 147 | void TesselationTest::GetAllTrianglesTest() | 
|---|
|  | 148 | { | 
|---|
|  | 149 | class BoundaryPointSet *Walker = NULL; | 
|---|
|  | 150 |  | 
|---|
|  | 151 | // check that there are three adjacent triangles for every boundary point | 
|---|
|  | 152 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) { | 
|---|
|  | 153 | Walker = Runner->second; | 
|---|
| [e138de] | 154 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker); | 
|---|
| [d04966] | 155 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() ); | 
|---|
|  | 156 | // check that the returned triangle all contain the Walker | 
|---|
|  | 157 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++) | 
|---|
|  | 158 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) ); | 
|---|
| [c26f44] | 159 | delete(triangles); | 
|---|
| [d04966] | 160 | } | 
|---|
|  | 161 | } | 
|---|