Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/listofbondsunittest.cpp

    r1bd79e re08c46  
    3838  atom *Walker = NULL;
    3939
    40   // init private all pointers to zero
    41   TestMolecule = NULL;
    42   hydrogen = NULL;
    43   tafel = NULL;
    44 
    4540  // 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");
    5543
    5644  // construct molecule (tetraeder of hydrogens)
    5745  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");
    5949  Walker->type = hydrogen;
    6050  *Walker->node = Vector(1., 0., 1. );
    6151  TestMolecule->AddAtom(Walker);
    6252  Walker = World::getInstance().createAtom();
     53  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6354  Walker->type = hydrogen;
    6455  *Walker->node = Vector(0., 1., 1. );
    6556  TestMolecule->AddAtom(Walker);
    6657  Walker = World::getInstance().createAtom();
     58  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6759  Walker->type = hydrogen;
    6860  *Walker->node = Vector(1., 1., 0. );
    6961  TestMolecule->AddAtom(Walker);
    7062  Walker = World::getInstance().createAtom();
     63  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7164  Walker->type = hydrogen;
    7265  *Walker->node = Vector(0., 0., 0. );
     
    7467
    7568  // check that TestMolecule was correctly constructed
    76   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    77 
     69  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    7870};
    7971
     
    8678  // are all cleaned when the world is destroyed
    8779  World::purgeInstance();
    88   MemoryUsageObserver::purgeInstance();
    8980  logger::purgeInstance();
    9081};
    9182
     83/** Tests whether setup worked correctly.
     84 *
     85 */
     86void ListOfBondsTest::SetupTest()
     87{
     88  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
     89  CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
     90};
     91
    9292/** Unit Test of molecule::AddBond()
    9393 *
     
    9696{
    9797  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() );
    108109
    109110  // check that bond contains the two atoms
     
    124125{
    125126  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;
    128131  CPPUNIT_ASSERT( atom1 != NULL );
    129132  CPPUNIT_ASSERT( atom2 != NULL );
     
    141144
    142145  // check if removed from molecule
    143   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     146  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    144147};
    145148
     
    150153{
    151154  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;
    155161  CPPUNIT_ASSERT( atom1 != NULL );
    156162  CPPUNIT_ASSERT( atom2 != NULL );
     
    179185
    180186  // 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() );
    183189};
    184190
     
    189195{
    190196  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;
    193201  CPPUNIT_ASSERT( atom1 != NULL );
    194202  CPPUNIT_ASSERT( atom2 != NULL );
     
    206214
    207215  // check if removed from molecule
    208   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     216  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    209217};
    210218
     
    215223{
    216224  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;
    219229  CPPUNIT_ASSERT( atom1 != NULL );
    220230  CPPUNIT_ASSERT( atom2 != NULL );
     
    231241
    232242  // check if removed from molecule
    233   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     243  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    234244};
    235245
     
    240250{
    241251  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;
    244256  CPPUNIT_ASSERT( atom1 != NULL );
    245257  CPPUNIT_ASSERT( atom2 != NULL );
     
    256268
    257269  // 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.