Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/CountBondsUnitTest.cpp

    rfe238c r4eb4fe  
    1616#include <stdio.h>
    1717#include <cstring>
     18
     19#include "Helpers/Assert.hpp"
    1820
    1921#include "analysis_bonds.hpp"
     
    2426#include "molecule.hpp"
    2527#include "periodentafel.hpp"
     28#include "World.hpp"
    2629#include "CountBondsUnitTest.hpp"
     30
     31#ifdef HAVE_TESTRUNNER
     32#include "UnitTestMain.hpp"
     33#endif /*HAVE_TESTRUNNER*/
    2734
    2835/********************************************** Test classes **************************************/
     
    3643  atom *Walker = NULL;
    3744
    38   // init private all pointers to zero
    39   molecules = NULL;
    40   TestMolecule1 = NULL;
    41   TestMolecule2 = NULL;
    42   hydrogen = NULL;
    43   oxygen = NULL;
    44   tafel = NULL;
    45 
    4645  // construct element
    47   hydrogen = new element;
    48   hydrogen->Z = 1;
    49   hydrogen->CovalentRadius = 0.23;
    50   strcpy(hydrogen->name, "hydrogen");
    51   strcpy(hydrogen->symbol, "H");
    52   oxygen = new element;
    53   oxygen->Z = 8;
    54   oxygen->CovalentRadius = 0.68;
    55   strcpy(oxygen->name, "oxygen");
    56   strcpy(oxygen->symbol, "O");
    57 
    58   // construct periodentafel
    59   tafel = new periodentafel;
    60   tafel->AddElement(hydrogen);
    61   tafel->AddElement(oxygen);
     46  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     47  oxygen = World::getInstance().getPeriode()->FindElement(8);
     48  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     49  CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
    6250
    6351  // 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. );
     52  TestMolecule1 = World::getInstance().createMolecule();
     53  CPPUNIT_ASSERT(TestMolecule1 != NULL && "could not create first molecule");
     54  Walker = World::getInstance().createAtom();
     55  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     56  Walker->type = hydrogen;
     57  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    6958  TestMolecule1->AddAtom(Walker);
    70   Walker = new atom();
    71   Walker->type = hydrogen;
    72   Walker->node->Init(0.9658, 0., 0. );
     59  Walker = World::getInstance().createAtom();
     60  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     61  Walker->type = hydrogen;
     62  *Walker->node = Vector(0.9658, 0., 0. );
    7363  TestMolecule1->AddAtom(Walker);
    74   Walker = new atom();
     64  Walker = World::getInstance().createAtom();
     65  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7566  Walker->type = oxygen;
    76   Walker->node->Init(0., 0., 0. );
     67  *Walker->node = Vector(0., 0., 0. );
    7768  TestMolecule1->AddAtom(Walker);
     69
     70  TestMolecule2 = World::getInstance().createMolecule();
     71  CPPUNIT_ASSERT(TestMolecule2 != NULL && "could not create second molecule");
     72  Walker = World::getInstance().createAtom();
     73  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     74  Walker->type = hydrogen;
     75  *Walker->node = Vector(-0.2418, 0.9350, 0. );
     76  TestMolecule2->AddAtom(Walker);
     77  Walker = World::getInstance().createAtom();
     78  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     79  Walker->type = hydrogen;
     80  *Walker->node = Vector(0.9658, 0., 0. );
     81  TestMolecule2->AddAtom(Walker);
     82  Walker = World::getInstance().createAtom();
     83  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     84  Walker->type = oxygen;
     85  *Walker->node = Vector(0., 0., 0. );
     86  TestMolecule2->AddAtom(Walker);
     87
     88  molecules = World::getInstance().getMolecules();
     89  CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules");
    7890  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);
    9391  molecules->insert(TestMolecule2);
    9492
     
    103101  // create a small file with table
    104102  BG = new BondGraph(true);
     103  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    105104
    106105  // construct bond graphs
     
    117116  delete(BG);
    118117
    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
     118  World::purgeInstance();
     119  MemoryUsageObserver::purgeInstance();
    124120};
    125121
     
    153149{
    154150  double *mirror = new double[3];
     151  CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
    155152  for (int i=0;i<3;i++)
    156153    mirror[i] = -1.;
     
    160157
    161158  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);
     159  Translator  = Vector(3,0,0);
    163160  TestMolecule2->Translate(&Translator);
    164161  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    165162  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
    166163  //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
    167   Translator.Init(-3,0,0);
     164  Translator = Vector(-3,0,0);
    168165  TestMolecule2->Translate(&Translator);
    169166
    170167  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);
     168  Translator = Vector(0,3,0);
    172169  TestMolecule2->Translate(&Translator);
    173170  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    174171  //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
    175   Translator.Init(0,-3,0);
     172  Translator = Vector(0,-3,0);
    176173  TestMolecule2->Translate(&Translator);
    177174
    178175  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);
     176  Translator = Vector(0,-3,0);
    180177  TestMolecule2->Scale((const double ** const)&mirror);
    181178  TestMolecule2->Translate(&Translator);
    182179  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    183180  //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
    184   Translator.Init(0,3,0);
     181  Translator = Vector(0,3,0);
    185182  TestMolecule2->Translate(&Translator);
    186183  TestMolecule2->Scale((const double ** const)&mirror);
    187184
    188185  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);
     186  Translator = Vector(2,1,0);
    190187  TestMolecule2->Translate(&Translator);
    191188  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    192189  //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
    193   Translator.Init(-2,-1,0);
     190  Translator = Vector(-2,-1,0);
    194191  TestMolecule2->Translate(&Translator);
    195192
    196193  cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
    197   Translator.Init(0,0,3);
     194  Translator = Vector(0,0,3);
    198195  TestMolecule2->Translate(&Translator);
    199196  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    200197  //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
    201   Translator.Init(0,0,-3);
     198  Translator = Vector(0,0,-3);
    202199  TestMolecule2->Translate(&Translator);
    203200
    204201  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);
     202  Translator = Vector(-3,0,0);
    206203  TestMolecule2->Scale((const double ** const)&mirror);
    207204  TestMolecule2->Translate(&Translator);
    208205  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    209206  //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
    210   Translator.Init(3,0,0);
     207  Translator = Vector(3,0,0);
    211208  TestMolecule2->Translate(&Translator);
    212209  TestMolecule2->Scale((const double ** const)&mirror);
    213210
    214211  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);
     212  Translator = Vector(3,0,0);
    216213  TestMolecule2->Scale((const double ** const)&mirror);
    217214  TestMolecule2->Translate(&Translator);
    218215  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    219216  //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
    220   Translator.Init(-3,0,0);
     217  Translator = Vector(-3,0,0);
    221218  TestMolecule2->Translate(&Translator);
    222219  TestMolecule2->Scale((const double ** const)&mirror);
    223220
    224221  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);
     222  Translator = Vector(0,3,0);
    226223  TestMolecule2->Scale((const double ** const)&mirror);
    227224  TestMolecule2->Translate(&Translator);
    228225  //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
    229226  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 };
     227  Translator = Vector(0,-3,0);
     228  TestMolecule2->Translate(&Translator);
     229  TestMolecule2->Scale((const double ** const)&mirror);
     230
     231  delete[](mirror);
     232};
Note: See TracChangeset for help on using the changeset viewer.