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