Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r4eb4fe rc6394d  
    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*/
    3326
    3427/********************************************** Test classes **************************************/
     
    3932void AnalysisCorrelationToSurfaceUnitTest::setUp()
    4033{
    41   //ASSERT_DO(Assert::Throw);
    42 
    4334  atom *Walker = NULL;
    4435
    4536  // init private all pointers to zero
    4637  TestList = NULL;
    47   TestSurfaceMolecule = NULL;
     38  TestMolecule = NULL;
     39  hydrogen = NULL;
     40  tafel = NULL;
    4841  surfacemap = NULL;
    4942  binmap = NULL;
     
    5144  LC = NULL;
    5245
     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
    5361  // construct molecule (tetraeder of hydrogens) base
    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);
     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);
    7379
    7480  // check that TestMolecule was correctly constructed
    75   CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
    76 
    77   TestList = World::getInstance().getMolecules();
    78   TestSurfaceMolecule->ActiveFlag = true;
    79   TestList->insert(TestSurfaceMolecule);
     81  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     82
     83  TestList = new MoleculeListClass;
     84  TestMolecule->ActiveFlag = true;
     85  TestList->insert(TestMolecule);
    8086
    8187  // init tesselation and linked cell
    8288  Surface = new Tesselation;
    83   LC = new LinkedCell(TestSurfaceMolecule, 5.);
    84   FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
     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() );
    8594
    8695  // add outer atoms
    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);
     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);
    101108  // add inner atoms
    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);
     109  Walker = new atom();
     110  Walker->type = carbon;
     111  Walker->node->Init(0.5, 0.5, 0.5 );
     112  TestMolecule->AddAtom(Walker);
    108113
    109114  // init maps
     
    121126    delete(binmap);
    122127
     128  // remove
     129  delete(TestList);
    123130  delete(Surface);
    124131  // note that all the atoms are cleaned by TestMolecule
    125132  delete(LC);
    126   World::purgeInstance();
    127   MemoryUsageObserver::purgeInstance();
    128   logger::purgeInstance();
    129 };
    130 
    131 
    132 /** Checks whether setup() does the right thing.
    133  */
    134 void 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 };
     133  delete(tafel);
     134  // note that element is cleaned by periodentafel
     135};
     136
    142137
    143138void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
     
    145140  // do the pair correlation
    146141  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
    147 //  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    148142  CPPUNIT_ASSERT( surfacemap != NULL );
    149143  CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
     
    155149  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
    156150  // put pair correlation into bins and check with no range
    157 //  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    158151  binmap = BinData( surfacemap, 0.5, 0., 0. );
    159152  CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
    160   OutputCorrelation ( (ofstream *)&cout, binmap );
     153  //OutputCorrelation ( binmap );
    161154  tester = binmap->begin();
    162155  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    169162  BinPairMap::iterator tester;
    170163  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
    171 //  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    172164  // ... and check with [0., 2.] range
    173165  binmap = BinData( surfacemap, 0.5, 0., 2. );
    174166  CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
    175 //  OutputCorrelation ( (ofstream *)&cout, binmap );
     167  //OutputCorrelation ( binmap );
    176168  tester = binmap->begin();
    177169  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    187179  BinPairMap::iterator tester;
    188180  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
    189 //  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    190181  // put pair correlation into bins and check with no range
    191182  binmap = BinData( surfacemap, 0.5, 0., 0. );
    192   //OutputCorrelation ( (ofstream *)&cout, binmap );
     183  OutputCorrelation ( (ofstream *)&cout, binmap );
    193184  CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
    194185  // inside point is first and must have negative value
    195   tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
     186  tester = binmap->lower_bound(2.95); // start depends on the min value and
    196187  CPPUNIT_ASSERT( tester != binmap->end() );
    197188  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    198189  // inner point
    199   tester = binmap->lower_bound(0.);
     190  tester = binmap->lower_bound(-0.5);
    200191  CPPUNIT_ASSERT( tester != binmap->end() );
    201192  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
     
    206197  BinPairMap::iterator tester;
    207198  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
    208 //  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    209199  // ... and check with [0., 2.] range
    210200  binmap = BinData( surfacemap, 0.5, -2., 4. );
    211   //OutputCorrelation ( (ofstream *)&cout, binmap );
     201  OutputCorrelation ( (ofstream *)&cout, binmap );
    212202  CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
    213203  // three outside points
    214   tester = binmap->lower_bound(4.25-0.5);
     204  tester = binmap->lower_bound(3.);
    215205  CPPUNIT_ASSERT( tester != binmap->end() );
    216206  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    217207  // inner point
    218   tester = binmap->lower_bound(0.);
     208  tester = binmap->lower_bound(-0.5);
    219209  CPPUNIT_ASSERT( tester != binmap->end() );
    220210  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
    221 };
     211
     212};
     213
     214/********************************************** Main routine **************************************/
     215
     216int 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};
Note: See TracChangeset for help on using the changeset viewer.