Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/CountBondsUnitTest.cpp

    rbfd839 rfe238c  
    2424#include "molecule.hpp"
    2525#include "periodentafel.hpp"
    26 #include "World.hpp"
    2726#include "CountBondsUnitTest.hpp"
    28 
    29 #ifdef HAVE_TESTRUNNER
    30 #include "UnitTestMain.hpp"
    31 #endif /*HAVE_TESTRUNNER*/
    3227
    3328/********************************************** Test classes **************************************/
     
    4035{
    4136  atom *Walker = NULL;
    42   BG = NULL;
    43   filename = NULL;
    4437
    4538  // init private all pointers to zero
     
    6457
    6558  // construct periodentafel
    66   tafel = World::getInstance().getPeriode();
     59  tafel = new periodentafel;
    6760  tafel->AddElement(hydrogen);
    6861  tafel->AddElement(oxygen);
    6962
    7063  // construct molecule (water molecule)
    71   TestMolecule1 = World::getInstance().createMolecule();
    72   Walker = World::getInstance().createAtom();
    73   Walker->type = hydrogen;
    74   *Walker->node = Vector(-0.2418, 0.9350, 0. );
     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. );
    7569  TestMolecule1->AddAtom(Walker);
    76   Walker = World::getInstance().createAtom();
    77   Walker->type = hydrogen;
    78   *Walker->node = Vector(0.9658, 0., 0. );
     70  Walker = new atom();
     71  Walker->type = hydrogen;
     72  Walker->node->Init(0.9658, 0., 0. );
    7973  TestMolecule1->AddAtom(Walker);
    80   Walker = World::getInstance().createAtom();
     74  Walker = new atom();
    8175  Walker->type = oxygen;
    82   *Walker->node = Vector(0., 0., 0. );
     76  Walker->node->Init(0., 0., 0. );
    8377  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. );
     78  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. );
    8984  TestMolecule2->AddAtom(Walker);
    90   Walker = World::getInstance().createAtom();
    91   Walker->type = hydrogen;
    92   *Walker->node = Vector(0.9658, 0., 0. );
     85  Walker = new atom();
     86  Walker->type = hydrogen;
     87  Walker->node->Init(0.9658, 0., 0. );
    9388  TestMolecule2->AddAtom(Walker);
    94   Walker = World::getInstance().createAtom();
     89  Walker = new atom();
    9590  Walker->type = oxygen;
    96   *Walker->node = Vector(0., 0., 0. );
     91  Walker->node->Init(0., 0., 0. );
    9792  TestMolecule2->AddAtom(Walker);
    98 
    99   molecules = World::getInstance().getMolecules();
    100   molecules->insert(TestMolecule1);
    10193  molecules->insert(TestMolecule2);
    10294
     
    125117  delete(BG);
    126118
    127   World::purgeInstance();
    128   MemoryUsageObserver::purgeInstance();
     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
    129124};
    130125
     
    165160
    166161  cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
    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) );
     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) );
    171166  //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
    172   Translator = Vector(-3,0,0);
     167  Translator.Init(-3,0,0);
    173168  TestMolecule2->Translate(&Translator);
    174169
    175170  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;
    176   Translator = Vector(0,3,0);
    177   TestMolecule2->Translate(&Translator);
    178   CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
     171  Translator.Init(0,3,0);
     172  TestMolecule2->Translate(&Translator);
     173  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    179174  //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
    180   Translator = Vector(0,-3,0);
     175  Translator.Init(0,-3,0);
    181176  TestMolecule2->Translate(&Translator);
    182177
    183178  cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
    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) );
     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) );
    188183  //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
    189   Translator = Vector(0,3,0);
     184  Translator.Init(0,3,0);
    190185  TestMolecule2->Translate(&Translator);
    191186  TestMolecule2->Scale((const double ** const)&mirror);
    192187
    193188  cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
    194   Translator = Vector(2,1,0);
    195   TestMolecule2->Translate(&Translator);
    196   CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
     189  Translator.Init(2,1,0);
     190  TestMolecule2->Translate(&Translator);
     191  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    197192  //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
    198   Translator = Vector(-2,-1,0);
     193  Translator.Init(-2,-1,0);
    199194  TestMolecule2->Translate(&Translator);
    200195
    201196  cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
    202   Translator = Vector(0,0,3);
    203   TestMolecule2->Translate(&Translator);
    204   CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
     197  Translator.Init(0,0,3);
     198  TestMolecule2->Translate(&Translator);
     199  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    205200  //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
    206   Translator = Vector(0,0,-3);
     201  Translator.Init(0,0,-3);
    207202  TestMolecule2->Translate(&Translator);
    208203
    209204  cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
    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) );
     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) );
    214209  //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
    215   Translator = Vector(3,0,0);
     210  Translator.Init(3,0,0);
    216211  TestMolecule2->Translate(&Translator);
    217212  TestMolecule2->Scale((const double ** const)&mirror);
    218213
    219214  cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
    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) );
     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) );
    224219  //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
    225   Translator = Vector(-3,0,0);
     220  Translator.Init(-3,0,0);
    226221  TestMolecule2->Translate(&Translator);
    227222  TestMolecule2->Scale((const double ** const)&mirror);
    228223
    229224  cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
    230   Translator = Vector(0,3,0);
     225  Translator.Init(0,3,0);
    231226  TestMolecule2->Scale((const double ** const)&mirror);
    232227  TestMolecule2->Translate(&Translator);
    233228  //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
    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 };
     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
     240int 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};
Note: See TracChangeset for help on using the changeset viewer.