- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/listofbondsunittest.cpp
r1bd79e re08c46 38 38 atom *Walker = NULL; 39 39 40 // init private all pointers to zero41 TestMolecule = NULL;42 hydrogen = NULL;43 tafel = NULL;44 45 40 // construct element 46 hydrogen = new element; 47 hydrogen->Z = 1; 48 strcpy(hydrogen->name, "hydrogen"); 49 strcpy(hydrogen->symbol, "H"); 50 51 52 // construct periodentafel 53 tafel = World::getInstance().getPeriode(); 54 tafel->AddElement(hydrogen); 41 hydrogen = World::getInstance().getPeriode()->FindElement(1); 42 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen"); 55 43 56 44 // construct molecule (tetraeder of hydrogens) 57 45 TestMolecule = World::getInstance().createMolecule(); 58 Walker = World::getInstance().createAtom(); 46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 47 Walker = World::getInstance().createAtom(); 48 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 59 49 Walker->type = hydrogen; 60 50 *Walker->node = Vector(1., 0., 1. ); 61 51 TestMolecule->AddAtom(Walker); 62 52 Walker = World::getInstance().createAtom(); 53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 63 54 Walker->type = hydrogen; 64 55 *Walker->node = Vector(0., 1., 1. ); 65 56 TestMolecule->AddAtom(Walker); 66 57 Walker = World::getInstance().createAtom(); 58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 67 59 Walker->type = hydrogen; 68 60 *Walker->node = Vector(1., 1., 0. ); 69 61 TestMolecule->AddAtom(Walker); 70 62 Walker = World::getInstance().createAtom(); 63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 71 64 Walker->type = hydrogen; 72 65 *Walker->node = Vector(0., 0., 0. ); … … 74 67 75 68 // check that TestMolecule was correctly constructed 76 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 77 69 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 78 70 }; 79 71 … … 86 78 // are all cleaned when the world is destroyed 87 79 World::purgeInstance(); 88 MemoryUsageObserver::purgeInstance();89 80 logger::purgeInstance(); 90 81 }; 91 82 83 /** Tests whether setup worked correctly. 84 * 85 */ 86 void ListOfBondsTest::SetupTest() 87 { 88 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() ); 89 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() ); 90 }; 91 92 92 /** Unit Test of molecule::AddBond() 93 93 * … … 96 96 { 97 97 bond *Binder = NULL; 98 atom *atom1 = TestMolecule->start->next; 99 atom *atom2 = atom1->next; 100 CPPUNIT_ASSERT( atom1 != NULL ); 101 CPPUNIT_ASSERT( atom2 != NULL ); 102 103 // add bond 104 Binder = TestMolecule->AddBond(atom1, atom2, 1); 105 CPPUNIT_ASSERT( Binder != NULL ); 106 bond *TestBond = TestMolecule->first->next; 107 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder ); 98 molecule::iterator iter = TestMolecule->begin(); 99 atom *atom1 = *iter; 100 iter++; 101 atom *atom2 = *iter; 102 CPPUNIT_ASSERT( atom1 != NULL ); 103 CPPUNIT_ASSERT( atom2 != NULL ); 104 105 // add bond 106 Binder = TestMolecule->AddBond(atom1, atom2, 1); 107 CPPUNIT_ASSERT( Binder != NULL ); 108 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() ); 108 109 109 110 // check that bond contains the two atoms … … 124 125 { 125 126 bond *Binder = NULL; 126 atom *atom1 = TestMolecule->start->next; 127 atom *atom2 = atom1->next; 127 molecule::iterator iter = TestMolecule->begin(); 128 atom *atom1 = *iter; 129 iter++; 130 atom *atom2 = *iter; 128 131 CPPUNIT_ASSERT( atom1 != NULL ); 129 132 CPPUNIT_ASSERT( atom2 != NULL ); … … 141 144 142 145 // check if removed from molecule 143 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);146 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 144 147 }; 145 148 … … 150 153 { 151 154 bond *Binder = NULL; 152 atom *atom1 = TestMolecule->start->next; 153 atom *atom2 = atom1->next; 154 atom *atom3 = atom2->next; 155 molecule::iterator iter = TestMolecule->begin(); 156 atom *atom1 = *iter; 157 iter++; 158 atom *atom2 = *iter; 159 iter++; 160 atom *atom3 = *iter; 155 161 CPPUNIT_ASSERT( atom1 != NULL ); 156 162 CPPUNIT_ASSERT( atom2 != NULL ); … … 179 185 180 186 // check if removed from molecule 181 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder);182 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last);187 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() ); 188 CPPUNIT_ASSERT_EQUAL( (unsigned int)1, TestMolecule->CountBonds() ); 183 189 }; 184 190 … … 189 195 { 190 196 bond *Binder = NULL; 191 atom *atom1 = TestMolecule->start->next; 192 atom *atom2 = atom1->next; 197 molecule::iterator iter = TestMolecule->begin(); 198 atom *atom1 = *iter; 199 iter++; 200 atom *atom2 = *iter; 193 201 CPPUNIT_ASSERT( atom1 != NULL ); 194 202 CPPUNIT_ASSERT( atom2 != NULL ); … … 206 214 207 215 // check if removed from molecule 208 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);216 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 209 217 }; 210 218 … … 215 223 { 216 224 bond *Binder = NULL; 217 atom *atom1 = TestMolecule->start->next; 218 atom *atom2 = atom1->next; 225 molecule::iterator iter = TestMolecule->begin(); 226 atom *atom1 = *iter; 227 iter++; 228 atom *atom2 = *iter; 219 229 CPPUNIT_ASSERT( atom1 != NULL ); 220 230 CPPUNIT_ASSERT( atom2 != NULL ); … … 231 241 232 242 // check if removed from molecule 233 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);243 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 234 244 }; 235 245 … … 240 250 { 241 251 bond *Binder = NULL; 242 atom *atom1 = TestMolecule->start->next; 243 atom *atom2 = atom1->next; 252 molecule::iterator iter = TestMolecule->begin(); 253 atom *atom1 = *iter; 254 iter++; 255 atom *atom2 = *iter; 244 256 CPPUNIT_ASSERT( atom1 != NULL ); 245 257 CPPUNIT_ASSERT( atom2 != NULL ); … … 256 268 257 269 // check if removed from molecule 258 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);259 }; 270 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() ); 271 };
Note:
See TracChangeset
for help on using the changeset viewer.