- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/CountBondsUnitTest.cpp
rbfd839 rfe238c 24 24 #include "molecule.hpp" 25 25 #include "periodentafel.hpp" 26 #include "World.hpp"27 26 #include "CountBondsUnitTest.hpp" 28 29 #ifdef HAVE_TESTRUNNER30 #include "UnitTestMain.hpp"31 #endif /*HAVE_TESTRUNNER*/32 27 33 28 /********************************************** Test classes **************************************/ … … 40 35 { 41 36 atom *Walker = NULL; 42 BG = NULL;43 filename = NULL;44 37 45 38 // init private all pointers to zero … … 64 57 65 58 // construct periodentafel 66 tafel = World::getInstance().getPeriode();59 tafel = new periodentafel; 67 60 tafel->AddElement(hydrogen); 68 61 tafel->AddElement(oxygen); 69 62 70 63 // 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. ); 75 69 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. ); 79 73 TestMolecule1->AddAtom(Walker); 80 Walker = World::getInstance().createAtom();74 Walker = new atom(); 81 75 Walker->type = oxygen; 82 *Walker->node = Vector(0., 0., 0. );76 Walker->node->Init(0., 0., 0. ); 83 77 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. ); 89 84 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. ); 93 88 TestMolecule2->AddAtom(Walker); 94 Walker = World::getInstance().createAtom();89 Walker = new atom(); 95 90 Walker->type = oxygen; 96 *Walker->node = Vector(0., 0., 0. );91 Walker->node->Init(0., 0., 0. ); 97 92 TestMolecule2->AddAtom(Walker); 98 99 molecules = World::getInstance().getMolecules();100 molecules->insert(TestMolecule1);101 93 molecules->insert(TestMolecule2); 102 94 … … 125 117 delete(BG); 126 118 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 129 124 }; 130 125 … … 165 160 166 161 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) ); 171 166 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz"); 172 Translator = Vector(-3,0,0);167 Translator.Init(-3,0,0); 173 168 TestMolecule2->Translate(&Translator); 174 169 175 170 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) ); 179 174 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz"); 180 Translator = Vector(0,-3,0);175 Translator.Init(0,-3,0); 181 176 TestMolecule2->Translate(&Translator); 182 177 183 178 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) ); 188 183 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz"); 189 Translator = Vector(0,3,0);184 Translator.Init(0,3,0); 190 185 TestMolecule2->Translate(&Translator); 191 186 TestMolecule2->Scale((const double ** const)&mirror); 192 187 193 188 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) ); 197 192 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz"); 198 Translator = Vector(-2,-1,0);193 Translator.Init(-2,-1,0); 199 194 TestMolecule2->Translate(&Translator); 200 195 201 196 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) ); 205 200 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz"); 206 Translator = Vector(0,0,-3);201 Translator.Init(0,0,-3); 207 202 TestMolecule2->Translate(&Translator); 208 203 209 204 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) ); 214 209 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz"); 215 Translator = Vector(3,0,0);210 Translator.Init(3,0,0); 216 211 TestMolecule2->Translate(&Translator); 217 212 TestMolecule2->Scale((const double ** const)&mirror); 218 213 219 214 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) ); 224 219 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz"); 225 Translator = Vector(-3,0,0);220 Translator.Init(-3,0,0); 226 221 TestMolecule2->Translate(&Translator); 227 222 TestMolecule2->Scale((const double ** const)&mirror); 228 223 229 224 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); 231 226 TestMolecule2->Scale((const double ** const)&mirror); 232 227 TestMolecule2->Translate(&Translator); 233 228 //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 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 };
Note:
See TracChangeset
for help on using the changeset viewer.