Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/CountBondsUnitTest.cpp

    rfe238c rbfd839  
    2424#include "molecule.hpp"
    2525#include "periodentafel.hpp"
     26#include "World.hpp"
    2627#include "CountBondsUnitTest.hpp"
     28
     29#ifdef HAVE_TESTRUNNER
     30#include "UnitTestMain.hpp"
     31#endif /*HAVE_TESTRUNNER*/
    2732
    2833/********************************************** Test classes **************************************/
     
    3540{
    3641  atom *Walker = NULL;
     42  BG = NULL;
     43  filename = NULL;
    3744
    3845  // init private all pointers to zero
     
    5764
    5865  // construct periodentafel
    59   tafel = new periodentafel;
     66  tafel = World::getInstance().getPeriode();
    6067  tafel->AddElement(hydrogen);
    6168  tafel->AddElement(oxygen);
    6269
    6370  // construct molecule (water molecule)
    64   molecules = new MoleculeListClass;
    65   TestMolecule1 = new molecule(tafel);
    66   Walker = new atom();
    67   Walker->type = hydrogen;
    68   Walker->node->Init(-0.2418, 0.9350, 0. );
     71  TestMolecule1 = World::getInstance().createMolecule();
     72  Walker = World::getInstance().createAtom();
     73  Walker->type = hydrogen;
     74  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    6975  TestMolecule1->AddAtom(Walker);
    70   Walker = new atom();
    71   Walker->type = hydrogen;
    72   Walker->node->Init(0.9658, 0., 0. );
     76  Walker = World::getInstance().createAtom();
     77  Walker->type = hydrogen;
     78  *Walker->node = Vector(0.9658, 0., 0. );
    7379  TestMolecule1->AddAtom(Walker);
    74   Walker = new atom();
     80  Walker = World::getInstance().createAtom();
    7581  Walker->type = oxygen;
    76   Walker->node->Init(0., 0., 0. );
     82  *Walker->node = Vector(0., 0., 0. );
    7783  TestMolecule1->AddAtom(Walker);
     84
     85  TestMolecule2 = World::getInstance().createMolecule();
     86  Walker = World::getInstance().createAtom();
     87  Walker->type = hydrogen;
     88  *Walker->node = Vector(-0.2418, 0.9350, 0. );
     89  TestMolecule2->AddAtom(Walker);
     90  Walker = World::getInstance().createAtom();
     91  Walker->type = hydrogen;
     92  *Walker->node = Vector(0.9658, 0., 0. );
     93  TestMolecule2->AddAtom(Walker);
     94  Walker = World::getInstance().createAtom();
     95  Walker->type = oxygen;
     96  *Walker->node = Vector(0., 0., 0. );
     97  TestMolecule2->AddAtom(Walker);
     98
     99  molecules = World::getInstance().getMolecules();
    78100  molecules->insert(TestMolecule1);
    79 
    80   TestMolecule2 = new molecule(tafel);
    81   Walker = new atom();
    82   Walker->type = hydrogen;
    83   Walker->node->Init(-0.2418, 0.9350, 0. );
    84   TestMolecule2->AddAtom(Walker);
    85   Walker = new atom();
    86   Walker->type = hydrogen;
    87   Walker->node->Init(0.9658, 0., 0. );
    88   TestMolecule2->AddAtom(Walker);
    89   Walker = new atom();
    90   Walker->type = oxygen;
    91   Walker->node->Init(0., 0., 0. );
    92   TestMolecule2->AddAtom(Walker);
    93101  molecules->insert(TestMolecule2);
    94102
     
    117125  delete(BG);
    118126
    119   // remove molecule
    120   delete(molecules);
    121   // note that all the atoms are cleaned by TestMolecule
    122   delete(tafel);
    123   // note that element is cleaned by periodentafel
     127  World::purgeInstance();
     128  MemoryUsageObserver::purgeInstance();
    124129};
    125130
     
    160165
    161166  cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
    162   Translator.Init(3,0,0);
    163   TestMolecule2->Translate(&Translator);
    164   CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    165   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
     167  Translator  = Vector(3,0,0);
     168  TestMolecule2->Translate(&Translator);
     169  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
     170  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen, NULL) );
    166171  //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
    167   Translator.Init(-3,0,0);
     172  Translator = Vector(-3,0,0);
    168173  TestMolecule2->Translate(&Translator);
    169174
    170175  cout << "Case 2: offset of (0,3,0), hence angle are (14.5, 165.5, 90) < 30 (only three, because other 90 is missing due to first H01 only fulfilling H-bond criteria)." << endl;
    171   Translator.Init(0,3,0);
    172   TestMolecule2->Translate(&Translator);
    173   CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
     176  Translator = Vector(0,3,0);
     177  TestMolecule2->Translate(&Translator);
     178  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    174179  //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
    175   Translator.Init(0,-3,0);
     180  Translator = Vector(0,-3,0);
    176181  TestMolecule2->Translate(&Translator);
    177182
    178183  cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
    179   Translator.Init(0,-3,0);
    180   TestMolecule2->Scale((const double ** const)&mirror);
    181   TestMolecule2->Translate(&Translator);
    182   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
     184  Translator = Vector(0,-3,0);
     185  TestMolecule2->Scale((const double ** const)&mirror);
     186  TestMolecule2->Translate(&Translator);
     187  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    183188  //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
    184   Translator.Init(0,3,0);
     189  Translator = Vector(0,3,0);
    185190  TestMolecule2->Translate(&Translator);
    186191  TestMolecule2->Scale((const double ** const)&mirror);
    187192
    188193  cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
    189   Translator.Init(2,1,0);
    190   TestMolecule2->Translate(&Translator);
    191   CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
     194  Translator = Vector(2,1,0);
     195  TestMolecule2->Translate(&Translator);
     196  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    192197  //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
    193   Translator.Init(-2,-1,0);
     198  Translator = Vector(-2,-1,0);
    194199  TestMolecule2->Translate(&Translator);
    195200
    196201  cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
    197   Translator.Init(0,0,3);
    198   TestMolecule2->Translate(&Translator);
    199   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
     202  Translator = Vector(0,0,3);
     203  TestMolecule2->Translate(&Translator);
     204  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    200205  //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
    201   Translator.Init(0,0,-3);
     206  Translator = Vector(0,0,-3);
    202207  TestMolecule2->Translate(&Translator);
    203208
    204209  cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
    205   Translator.Init(-3,0,0);
    206   TestMolecule2->Scale((const double ** const)&mirror);
    207   TestMolecule2->Translate(&Translator);
    208   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
     210  Translator = Vector(-3,0,0);
     211  TestMolecule2->Scale((const double ** const)&mirror);
     212  TestMolecule2->Translate(&Translator);
     213  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    209214  //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
    210   Translator.Init(3,0,0);
     215  Translator = Vector(3,0,0);
    211216  TestMolecule2->Translate(&Translator);
    212217  TestMolecule2->Scale((const double ** const)&mirror);
    213218
    214219  cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
    215   Translator.Init(3,0,0);
    216   TestMolecule2->Scale((const double ** const)&mirror);
    217   TestMolecule2->Translate(&Translator);
    218   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
     220  Translator = Vector(3,0,0);
     221  TestMolecule2->Scale((const double ** const)&mirror);
     222  TestMolecule2->Translate(&Translator);
     223  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    219224  //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
    220   Translator.Init(-3,0,0);
     225  Translator = Vector(-3,0,0);
    221226  TestMolecule2->Translate(&Translator);
    222227  TestMolecule2->Scale((const double ** const)&mirror);
    223228
    224229  cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
    225   Translator.Init(0,3,0);
     230  Translator = Vector(0,3,0);
    226231  TestMolecule2->Scale((const double ** const)&mirror);
    227232  TestMolecule2->Translate(&Translator);
    228233  //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
    229   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    230   Translator.Init(0,-3,0);
    231   TestMolecule2->Translate(&Translator);
    232   TestMolecule2->Scale((const double ** const)&mirror);
    233 
    234   delete(mirror);
    235 };
    236 
    237 
    238 /********************************************** Main routine **************************************/
    239 
    240 int main(int argc, char **argv)
    241 {
    242   // Get the top level suite from the registry
    243   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    244 
    245   // Adds the test to the list of test to run
    246   CppUnit::TextUi::TestRunner runner;
    247   runner.addTest( suite );
    248 
    249   // Change the default outputter to a compiler error format outputter
    250   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    251                                                        std::cerr ) );
    252   // Run the tests.
    253   bool wasSucessful = runner.run();
    254 
    255   // Return error code 1 if the one of test failed.
    256   return wasSucessful ? 0 : 1;
    257 };
     234  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
     235  Translator = Vector(0,-3,0);
     236  TestMolecule2->Translate(&Translator);
     237  TestMolecule2->Scale((const double ** const)&mirror);
     238
     239  delete[](mirror);
     240};
Note: See TracChangeset for help on using the changeset viewer.