/* * AnalysisCorrelationToSurfaceUnitTest.cpp * * Created on: Oct 13, 2009 * Author: heber */ using namespace std; #include #include #include #include #include "analysis_correlation.hpp" #include "AnalysisCorrelationToSurfaceUnitTest.hpp" #include "atom.hpp" #include "boundary.hpp" #include "element.hpp" #include "molecule.hpp" #include "linkedcell.hpp" #include "periodentafel.hpp" #include "tesselation.hpp" #include "World.hpp" #include "Helpers/Assert.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest ); void AnalysisCorrelationToSurfaceUnitTest::setUp() { //ASSERT_DO(Assert::Throw); atom *Walker = NULL; // init private all pointers to zero TestList = NULL; TestSurfaceMolecule = NULL; surfacemap = NULL; binmap = NULL; Surface = NULL; LC = NULL; // construct molecule (tetraeder of hydrogens) base hydrogen = World::getInstance().getPeriode()->FindElement(1); TestSurfaceMolecule = World::getInstance().createMolecule(); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(1., 0., 1. ); TestSurfaceMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(0., 1., 1. ); TestSurfaceMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(1., 1., 0. ); TestSurfaceMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(0., 0., 0. ); TestSurfaceMolecule->AddAtom(Walker); // check that TestMolecule was correctly constructed CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 ); TestList = World::getInstance().getMolecules(); TestSurfaceMolecule->ActiveFlag = true; TestList->insert(TestSurfaceMolecule); // init tesselation and linked cell Surface = new Tesselation; LC = new LinkedCell(TestSurfaceMolecule, 5.); FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL); // add outer atoms carbon = World::getInstance().getPeriode()->FindElement(6); TestSurfaceMolecule = World::getInstance().createMolecule(); Walker = World::getInstance().createAtom(); Walker->type = carbon; *Walker->node = Vector(4., 0., 4. ); TestSurfaceMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = carbon; *Walker->node = Vector(0., 4., 4. ); TestSurfaceMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = carbon; *Walker->node = Vector(4., 4., 0. ); TestSurfaceMolecule->AddAtom(Walker); // add inner atoms Walker = World::getInstance().createAtom(); Walker->type = carbon; *Walker->node = Vector(0.5, 0.5, 0.5 ); TestSurfaceMolecule->AddAtom(Walker); TestSurfaceMolecule->ActiveFlag = true; TestList->insert(TestSurfaceMolecule); // init maps surfacemap = NULL; binmap = NULL; }; void AnalysisCorrelationToSurfaceUnitTest::tearDown() { if (surfacemap != NULL) delete(surfacemap); if (binmap != NULL) delete(binmap); delete(Surface); // note that all the atoms are cleaned by TestMolecule delete(LC); World::purgeInstance(); MemoryUsageObserver::purgeInstance(); logger::purgeInstance(); }; /** Checks whether setup() does the right thing. */ void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest() { CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount ); CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() ); CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() ); CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() ); }; void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest() { // do the pair correlation surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); CPPUNIT_ASSERT( surfacemap != NULL ); CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() ); }; void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest() { BinPairMap::iterator tester; surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); // put pair correlation into bins and check with no range // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); binmap = BinData( surfacemap, 0.5, 0., 0. ); CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() ); OutputCorrelation ( (ofstream *)&cout, binmap ); tester = binmap->begin(); CPPUNIT_ASSERT_EQUAL( 0., tester->first ); CPPUNIT_ASSERT_EQUAL( 4, tester->second ); }; void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest() { BinPairMap::iterator tester; surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); // ... and check with [0., 2.] range binmap = BinData( surfacemap, 0.5, 0., 2. ); CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() ); // OutputCorrelation ( (ofstream *)&cout, binmap ); tester = binmap->begin(); CPPUNIT_ASSERT_EQUAL( 0., tester->first ); CPPUNIT_ASSERT_EQUAL( 4, tester->second ); tester = binmap->find(1.); CPPUNIT_ASSERT_EQUAL( 1., tester->first ); CPPUNIT_ASSERT_EQUAL( 0, tester->second ); }; void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest() { BinPairMap::iterator tester; surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); // put pair correlation into bins and check with no range binmap = BinData( surfacemap, 0.5, 0., 0. ); //OutputCorrelation ( (ofstream *)&cout, binmap ); CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() ); // inside point is first and must have negative value tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and CPPUNIT_ASSERT( tester != binmap->end() ); CPPUNIT_ASSERT_EQUAL( 3, tester->second ); // inner point tester = binmap->lower_bound(0.); CPPUNIT_ASSERT( tester != binmap->end() ); CPPUNIT_ASSERT_EQUAL( 1, tester->second ); }; void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest() { BinPairMap::iterator tester; surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); // ... and check with [0., 2.] range binmap = BinData( surfacemap, 0.5, -2., 4. ); //OutputCorrelation ( (ofstream *)&cout, binmap ); CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() ); // three outside points tester = binmap->lower_bound(4.25-0.5); CPPUNIT_ASSERT( tester != binmap->end() ); CPPUNIT_ASSERT_EQUAL( 3, tester->second ); // inner point tester = binmap->lower_bound(0.); CPPUNIT_ASSERT( tester != binmap->end() ); CPPUNIT_ASSERT_EQUAL( 1, tester->second ); };