Index: src/tesselationunittest.cpp
===================================================================
--- src/tesselationunittest.cpp	(revision 0227a9778aafa7940161d45586d48cd6db8113c8)
+++ src/tesselationunittest.cpp	(revision 0227a9778aafa7940161d45586d48cd6db8113c8)
@@ -0,0 +1,202 @@
+/*
+ * tesselationunittest.cpp
+ *
+ *  Created on: Aug 26, 2009
+ *      Author: heber
+ */
+
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "defs.hpp"
+#include "tesselation.hpp"
+#include "tesselationunittest.hpp"
+
+#define SPHERERADIUS 2.
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
+
+
+void TesselationTest::setUp()
+{
+  // create corners
+  class TesselPoint *Walker;
+  Walker = new TesselPoint;
+  Walker->node = new Vector(1., 0., 0.);
+  Walker->Name = new char[3];
+  strcpy(Walker->Name, "1");
+  Walker->nr = 1;
+  Corners.push_back(Walker);
+  Walker = new TesselPoint;
+  Walker->node = new Vector(-1., 1., 0.);
+  Walker->Name = new char[3];
+  strcpy(Walker->Name, "2");
+  Walker->nr = 2;
+  Corners.push_back(Walker);
+  Walker = new TesselPoint;
+  Walker->node = new Vector(-1., -1., 0.);
+  Walker->Name = new char[3];
+  strcpy(Walker->Name, "3");
+  Walker->nr = 3;
+  Corners.push_back(Walker);
+  Walker = new TesselPoint;
+  Walker->node = new Vector(-1., 0., 1.);
+  Walker->Name = new char[3];
+  strcpy(Walker->Name, "4");
+  Walker->nr = 4;
+  Corners.push_back(Walker);
+
+  // create linkedcell
+  LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
+
+  // create tesselation
+  TesselStruct = new Tesselation;
+  TesselStruct->PointsOnBoundary.clear();
+  TesselStruct->LinesOnBoundary.clear();
+  TesselStruct->TrianglesOnBoundary.clear();
+  TesselStruct->FindStartingTriangle((ofstream *)&cout, SPHERERADIUS, LinkedList);
+  bool flag = false;
+
+  LineMap::iterator baseline = TesselStruct->LinesOnBoundary.begin();
+  while (baseline != TesselStruct->LinesOnBoundary.end()) {
+    if (baseline->second->triangles.size() == 1) {
+      flag = TesselStruct->FindNextSuitableTriangle((ofstream *)&cout, *(baseline->second), *(((baseline->second->triangles.begin()))->second), SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
+    }
+    baseline++;
+    if ((baseline == TesselStruct->LinesOnBoundary.end()) && (flag)) {
+      baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
+      flag = false;
+    }
+  }
+};
+
+
+void TesselationTest::tearDown()
+{
+  delete(LinkedList);
+  delete(TesselStruct);
+  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
+    delete((*Runner)->Name);
+    delete((*Runner)->node);
+    delete(*Runner);
+  }
+  Corners.clear();
+};
+
+/** UnitTest for Tesselation::IsInnerPoint()
+ */
+void TesselationTest::IsInnerPointTest()
+{
+  // true inside points
+  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.,0.,0.), LinkedList) );
+  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.5,0.,0.), LinkedList) );
+  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.,0.5,0.), LinkedList) );
+  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.,0.,0.5), LinkedList) );
+
+  // corners
+  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
+    CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((ofstream *)&cout, (*Runner), LinkedList) );
+
+  // true outside points
+  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.,5.,0.), LinkedList) );
+  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(0.,0.,5.), LinkedList) );
+  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(1.,1.,1.), LinkedList) );
+
+  // tricky point, there are three equally close triangles
+  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint((ofstream *)&cout, Vector(5.,0.,0.), LinkedList) );
+
+};
+
+/** UnitTest for Contains...()
+ *
+ */
+void TesselationTest::ContainmentTest()
+{
+  class BoundaryPointSet *point = NULL;
+  class BoundaryLineSet *line = NULL;
+
+  // check ContainsBoundaryPoint
+  for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
+  }
+  for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
+    for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
+      point = PointRunner->second;
+      for (int i=0;i<3;i++)
+        if (point == (Runner->second)->endpoints[i])
+          point = NULL;
+      if (point != NULL)
+        break;
+    }
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
+    CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
+  }
+
+  // check ContainsBoundaryLine
+  for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
+    for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
+      line = LineRunner->second;
+      for (int i=0;i<3;i++)
+        if (line == (Runner->second)->lines[i])
+          line = NULL;
+      if (line != NULL)
+        break;
+    }
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
+    CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
+    CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
+  }
+
+  // check IsPresentTupel
+  CPPUNIT_ASSERT_EQUAL( true, true );
+}
+
+/** UnitTest for Tesselation::GetAllTriangles()
+ *
+ */
+void TesselationTest::GetAllTrianglesTest()
+{
+  class BoundaryPointSet *Walker = NULL;
+
+  // check that there are three adjacent triangles for every boundary point
+  for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
+    Walker = Runner->second;
+    set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles((ofstream *)&cout, Walker);
+    CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
+    // check that the returned triangle all contain the Walker
+    for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
+      CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
+  }
+}
+
+/********************************************** Main routine **************************************/
+
+int main(int argc, char **argv)
+{
+  // Get the top level suite from the registry
+  CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+
+  // Adds the test to the list of test to run
+  CppUnit::TextUi::TestRunner runner;
+  runner.addTest( suite );
+
+  // Change the default outputter to a compiler error format outputter
+  runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
+                                                       std::cerr ) );
+  // Run the tests.
+  bool wasSucessful = runner.run();
+
+  // Return error code 1 if the one of test failed.
+  return wasSucessful ? 0 : 1;
+};
Index: src/tesselationunittest.hpp
===================================================================
--- src/tesselationunittest.hpp	(revision 0227a9778aafa7940161d45586d48cd6db8113c8)
+++ src/tesselationunittest.hpp	(revision 0227a9778aafa7940161d45586d48cd6db8113c8)
@@ -0,0 +1,42 @@
+/*
+ * tesselationunittest.hpp
+ *
+ *  Created on: Aug 26, 2009
+ *      Author: heber
+ */
+
+#ifndef TESSELATIONUNITTEST_HPP_
+#define TESSELATIONUNITTEST_HPP_
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "tesselation.hpp"
+
+/********************************************** Test classes **************************************/
+
+class TesselationTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( TesselationTest) ;
+    CPPUNIT_TEST ( IsInnerPointTest );
+    CPPUNIT_TEST ( GetAllTrianglesTest );
+    CPPUNIT_TEST ( ContainmentTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void IsInnerPointTest();
+      void GetAllTrianglesTest();
+      void ContainmentTest();
+
+
+private:
+      class Tesselation *TesselStruct;
+      LinkedNodes Corners;
+      class LinkedCell *LinkedList;
+};
+
+
+
+#endif /* TESSELATIONUNITTEST_HPP_ */
