Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    rc6394d r4eb4fe  
    2424#include "periodentafel.hpp"
    2525#include "tesselation.hpp"
     26#include "World.hpp"
     27
     28#include "Helpers/Assert.hpp"
     29
     30#ifdef HAVE_TESTRUNNER
     31#include "UnitTestMain.hpp"
     32#endif /*HAVE_TESTRUNNER*/
    2633
    2734/********************************************** Test classes **************************************/
     
    3239void AnalysisCorrelationToSurfaceUnitTest::setUp()
    3340{
     41  //ASSERT_DO(Assert::Throw);
     42
    3443  atom *Walker = NULL;
    3544
    3645  // init private all pointers to zero
    3746  TestList = NULL;
    38   TestMolecule = NULL;
    39   hydrogen = NULL;
    40   tafel = NULL;
     47  TestSurfaceMolecule = NULL;
    4148  surfacemap = NULL;
    4249  binmap = NULL;
     
    4451  LC = NULL;
    4552
    46   // construct element
    47   hydrogen = new element;
    48   hydrogen->Z = 1;
    49   strcpy(hydrogen->name, "hydrogen");
    50   strcpy(hydrogen->symbol, "H");
    51   carbon = new element;
    52   carbon->Z = 6;
    53   strcpy(carbon->name, "carbon");
    54   strcpy(carbon->symbol, "C");
    55 
    56   // construct periodentafel
    57   tafel = new periodentafel;
    58   tafel->AddElement(hydrogen);
    59   tafel->AddElement(carbon);
    60 
    6153  // construct molecule (tetraeder of hydrogens) base
    62   TestMolecule = new molecule(tafel);
    63   Walker = new atom();
    64   Walker->type = hydrogen;
    65   Walker->node->Init(1., 0., 1. );
    66   TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
    68   Walker->type = hydrogen;
    69   Walker->node->Init(0., 1., 1. );
    70   TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
    72   Walker->type = hydrogen;
    73   Walker->node->Init(1., 1., 0. );
    74   TestMolecule->AddAtom(Walker);
    75   Walker = new atom();
    76   Walker->type = hydrogen;
    77   Walker->node->Init(0., 0., 0. );
    78   TestMolecule->AddAtom(Walker);
     54  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     55  TestSurfaceMolecule = World::getInstance().createMolecule();
     56  Walker = World::getInstance().createAtom();
     57  Walker->type = hydrogen;
     58  *Walker->node = Vector(1., 0., 1. );
     59
     60  TestSurfaceMolecule->AddAtom(Walker);
     61  Walker = World::getInstance().createAtom();
     62  Walker->type = hydrogen;
     63  *Walker->node = Vector(0., 1., 1. );
     64  TestSurfaceMolecule->AddAtom(Walker);
     65  Walker = World::getInstance().createAtom();
     66  Walker->type = hydrogen;
     67  *Walker->node = Vector(1., 1., 0. );
     68  TestSurfaceMolecule->AddAtom(Walker);
     69  Walker = World::getInstance().createAtom();
     70  Walker->type = hydrogen;
     71  *Walker->node = Vector(0., 0., 0. );
     72  TestSurfaceMolecule->AddAtom(Walker);
    7973
    8074  // check that TestMolecule was correctly constructed
    81   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    82 
    83   TestList = new MoleculeListClass;
    84   TestMolecule->ActiveFlag = true;
    85   TestList->insert(TestMolecule);
     75  CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
     76
     77  TestList = World::getInstance().getMolecules();
     78  TestSurfaceMolecule->ActiveFlag = true;
     79  TestList->insert(TestSurfaceMolecule);
    8680
    8781  // init tesselation and linked cell
    8882  Surface = new Tesselation;
    89   FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
    90   LC = new LinkedCell(TestMolecule, 5.);
    91   CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
    92   CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
    93   CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
     83  LC = new LinkedCell(TestSurfaceMolecule, 5.);
     84  FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
    9485
    9586  // add outer atoms
    96   Walker = new atom();
    97   Walker->type = carbon;
    98   Walker->node->Init(4., 0., 4. );
    99   TestMolecule->AddAtom(Walker);
    100   Walker = new atom();
    101   Walker->type = carbon;
    102   Walker->node->Init(0., 4., 4. );
    103   TestMolecule->AddAtom(Walker);
    104   Walker = new atom();
    105   Walker->type = carbon;
    106   Walker->node->Init(4., 4., 0. );
    107   TestMolecule->AddAtom(Walker);
     87  carbon = World::getInstance().getPeriode()->FindElement(6);
     88  TestSurfaceMolecule = World::getInstance().createMolecule();
     89  Walker = World::getInstance().createAtom();
     90  Walker->type = carbon;
     91  *Walker->node = Vector(4., 0., 4. );
     92  TestSurfaceMolecule->AddAtom(Walker);
     93  Walker = World::getInstance().createAtom();
     94  Walker->type = carbon;
     95  *Walker->node = Vector(0., 4., 4. );
     96  TestSurfaceMolecule->AddAtom(Walker);
     97  Walker = World::getInstance().createAtom();
     98  Walker->type = carbon;
     99  *Walker->node = Vector(4., 4., 0. );
     100  TestSurfaceMolecule->AddAtom(Walker);
    108101  // add inner atoms
    109   Walker = new atom();
    110   Walker->type = carbon;
    111   Walker->node->Init(0.5, 0.5, 0.5 );
    112   TestMolecule->AddAtom(Walker);
     102  Walker = World::getInstance().createAtom();
     103  Walker->type = carbon;
     104  *Walker->node = Vector(0.5, 0.5, 0.5 );
     105  TestSurfaceMolecule->AddAtom(Walker);
     106  TestSurfaceMolecule->ActiveFlag = true;
     107  TestList->insert(TestSurfaceMolecule);
    113108
    114109  // init maps
     
    126121    delete(binmap);
    127122
    128   // remove
    129   delete(TestList);
    130123  delete(Surface);
    131124  // note that all the atoms are cleaned by TestMolecule
    132125  delete(LC);
    133   delete(tafel);
    134   // note that element is cleaned by periodentafel
    135 };
    136 
     126  World::purgeInstance();
     127  MemoryUsageObserver::purgeInstance();
     128  logger::purgeInstance();
     129};
     130
     131
     132/** Checks whether setup() does the right thing.
     133 */
     134void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
     135{
     136  CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
     137  CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
     138  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
     139  CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
     140  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
     141};
    137142
    138143void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
     
    140145  // do the pair correlation
    141146  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     147//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    142148  CPPUNIT_ASSERT( surfacemap != NULL );
    143149  CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
     
    149155  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
    150156  // put pair correlation into bins and check with no range
     157//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    151158  binmap = BinData( surfacemap, 0.5, 0., 0. );
    152159  CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
    153   //OutputCorrelation ( binmap );
     160  OutputCorrelation ( (ofstream *)&cout, binmap );
    154161  tester = binmap->begin();
    155162  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    162169  BinPairMap::iterator tester;
    163170  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     171//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    164172  // ... and check with [0., 2.] range
    165173  binmap = BinData( surfacemap, 0.5, 0., 2. );
    166174  CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
    167   //OutputCorrelation ( binmap );
     175//  OutputCorrelation ( (ofstream *)&cout, binmap );
    168176  tester = binmap->begin();
    169177  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    179187  BinPairMap::iterator tester;
    180188  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     189//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    181190  // put pair correlation into bins and check with no range
    182191  binmap = BinData( surfacemap, 0.5, 0., 0. );
    183   OutputCorrelation ( (ofstream *)&cout, binmap );
     192  //OutputCorrelation ( (ofstream *)&cout, binmap );
    184193  CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
    185194  // inside point is first and must have negative value
    186   tester = binmap->lower_bound(2.95); // start depends on the min value and
     195  tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
    187196  CPPUNIT_ASSERT( tester != binmap->end() );
    188197  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    189198  // inner point
    190   tester = binmap->lower_bound(-0.5);
     199  tester = binmap->lower_bound(0.);
    191200  CPPUNIT_ASSERT( tester != binmap->end() );
    192201  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
     
    197206  BinPairMap::iterator tester;
    198207  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     208//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    199209  // ... and check with [0., 2.] range
    200210  binmap = BinData( surfacemap, 0.5, -2., 4. );
    201   OutputCorrelation ( (ofstream *)&cout, binmap );
     211  //OutputCorrelation ( (ofstream *)&cout, binmap );
    202212  CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
    203213  // three outside points
    204   tester = binmap->lower_bound(3.);
     214  tester = binmap->lower_bound(4.25-0.5);
    205215  CPPUNIT_ASSERT( tester != binmap->end() );
    206216  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    207217  // inner point
    208   tester = binmap->lower_bound(-0.5);
     218  tester = binmap->lower_bound(0.);
    209219  CPPUNIT_ASSERT( tester != binmap->end() );
    210220  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
    211 
    212 };
    213 
    214 /********************************************** Main routine **************************************/
    215 
    216 int main(int argc, char **argv)
    217 {
    218   // Get the top level suite from the registry
    219   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    220 
    221   // Adds the test to the list of test to run
    222   CppUnit::TextUi::TestRunner runner;
    223   runner.addTest( suite );
    224 
    225   // Change the default outputter to a compiler error format outputter
    226   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    227                                                        std::cerr ) );
    228   // Run the tests.
    229   bool wasSucessful = runner.run();
    230 
    231   // Return error code 1 if the one of test failed.
    232   return wasSucessful ? 0 : 1;
    233 };
     221};
Note: See TracChangeset for help on using the changeset viewer.