/* * AnalysisCorrelationToPointUnitTest.cpp * * Created on: Oct 13, 2009 * Author: heber */ using namespace std; #include #include #include #include #include "analysis_correlation.hpp" #include "AnalysisCorrelationToPointUnitTest.hpp" #include "World.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" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest ); void AnalysisCorrelationToPointUnitTest::setUp() { atom *Walker = NULL; // init private all pointers to zero TestList = NULL; TestMolecule = NULL; hydrogen = NULL; tafel = NULL; pointmap = NULL; binmap = NULL; point = NULL; // construct element hydrogen = new element; hydrogen->Z = 1; strcpy(hydrogen->name, "hydrogen"); strcpy(hydrogen->symbol, "H"); // construct periodentafel tafel = World::getInstance().getPeriode(); tafel->AddElement(hydrogen); // construct molecule (tetraeder of hydrogens) TestMolecule = World::getInstance().createMolecule(); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(1., 0., 1. ); TestMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(0., 1., 1. ); TestMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(1., 1., 0. ); TestMolecule->AddAtom(Walker); Walker = World::getInstance().createAtom(); Walker->type = hydrogen; *Walker->node = Vector(0., 0., 0. ); TestMolecule->AddAtom(Walker); // check that TestMolecule was correctly constructed CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); TestList = World::getInstance().getMolecules(); TestList->insert(TestMolecule); TestMolecule->ActiveFlag = true; // init point point = new Vector(1.,1.,1.); // init maps pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, (const element * const)hydrogen, (const Vector *)point ); binmap = NULL; }; void AnalysisCorrelationToPointUnitTest::tearDown() { if (pointmap != NULL) delete(pointmap); if (binmap != NULL) delete(binmap); delete(point); World::purgeInstance(); MemoryUsageObserver::purgeInstance(); logger::purgeInstance(); }; void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest() { // do the pair correlation CPPUNIT_ASSERT( pointmap != NULL ); CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() ); }; void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest() { BinPairMap::iterator tester; // put pair correlation into bins and check with no range binmap = BinData( pointmap, 0.5, 0., 0. ); OutputCorrelation ( (ofstream *)&cout, binmap ); CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() ); tester = binmap->begin(); CPPUNIT_ASSERT_EQUAL( 1., tester->first ); CPPUNIT_ASSERT_EQUAL( 3, tester->second ); }; void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest() { BinPairMap::iterator tester; // ... and check with [0., 2.] range binmap = BinData( pointmap, 0.5, 0., 2. ); OutputCorrelation ( (ofstream *)&cout, binmap ); CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() ); tester = binmap->begin(); CPPUNIT_ASSERT_EQUAL( 0., tester->first ); tester = binmap->find(1.); CPPUNIT_ASSERT_EQUAL( 1., tester->first ); CPPUNIT_ASSERT_EQUAL( 3, tester->second ); };