[5e6534] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * AtomIdSetUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Feb 21, 2012
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include <cppunit/CompilerOutputter.h>
|
---|
| 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 22 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 23 |
|
---|
| 24 | #include <algorithm>
|
---|
| 25 |
|
---|
| 26 | #include "Atom/atom.hpp"
|
---|
| 27 | #include "AtomIdSet.hpp"
|
---|
| 28 | #include "CodePatterns/Assert.hpp"
|
---|
| 29 | #include "World.hpp"
|
---|
| 30 |
|
---|
| 31 | #include "AtomIdSetUnitTest.hpp"
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | #ifdef HAVE_TESTRUNNER
|
---|
| 35 | #include "UnitTestMain.hpp"
|
---|
| 36 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 37 |
|
---|
| 38 | /********************************************** Test classes **************************************/
|
---|
| 39 |
|
---|
| 40 | // Registers the fixture into the 'registry'
|
---|
| 41 | CPPUNIT_TEST_SUITE_REGISTRATION( AtomIdSetUnittest );
|
---|
| 42 |
|
---|
| 43 | size_t AtomIdSetUnittest::MaxAtoms = 6;
|
---|
| 44 |
|
---|
| 45 | void AtomIdSetUnittest::setUp(){
|
---|
| 46 | // failing asserts should be thrown
|
---|
| 47 | ASSERT_DO(Assert::Throw);
|
---|
| 48 |
|
---|
| 49 | atomVector.resize((size_t)MaxAtoms);
|
---|
| 50 | std::generate_n(atomVector.begin(), MaxAtoms,
|
---|
| 51 | boost::bind(&World::createAtom, boost::ref(World::getInstance())));
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void AtomIdSetUnittest::tearDown()
|
---|
| 55 | {
|
---|
| 56 | World::purgeInstance();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void AtomIdSetUnittest::inserteraseTest()
|
---|
| 60 | {
|
---|
| 61 | // insert all
|
---|
| 62 | for (size_t i=0; i< MaxAtoms; ++i) {
|
---|
| 63 | atoms.insert(atomVector[i]);
|
---|
| 64 | }
|
---|
| 65 | CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, atoms.size() );
|
---|
| 66 |
|
---|
| 67 | // erase them again
|
---|
| 68 | for (size_t i=0; i< MaxAtoms; ++i) {
|
---|
| 69 | atoms.erase(atomVector[i]);
|
---|
| 70 | }
|
---|
| 71 | CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
|
---|
| 72 |
|
---|
| 73 | {
|
---|
| 74 | // use atomVector in cstor
|
---|
| 75 | AtomIdSet otherAtoms(atomVector);
|
---|
| 76 | CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, otherAtoms.size() );
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void AtomIdSetUnittest::positionTest()
|
---|
| 81 | {
|
---|
| 82 | // non-const iterators
|
---|
| 83 | CPPUNIT_ASSERT( atoms.begin() == atoms.end() );
|
---|
| 84 |
|
---|
| 85 | // const iterators
|
---|
| 86 | {
|
---|
| 87 | AtomIdSet::const_iterator beg_iter = atoms.begin();
|
---|
| 88 | AtomIdSet::const_iterator end_iter = atoms.end();
|
---|
| 89 | CPPUNIT_ASSERT( beg_iter == end_iter );
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | // insert an element
|
---|
| 93 | atoms.insert(atomVector[0]);
|
---|
| 94 | CPPUNIT_ASSERT( atoms.begin() != atoms.end() );
|
---|
| 95 |
|
---|
| 96 | {
|
---|
| 97 | AtomIdSet::const_iterator beg_iter = atoms.begin();
|
---|
| 98 | AtomIdSet::const_iterator end_iter = atoms.end();
|
---|
| 99 | CPPUNIT_ASSERT( beg_iter != end_iter );
|
---|
| 100 | ++beg_iter;
|
---|
| 101 | CPPUNIT_ASSERT( beg_iter == end_iter );
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void AtomIdSetUnittest::findTest()
|
---|
| 106 | {
|
---|
| 107 | // search for atom
|
---|
| 108 | atoms.insert(atomVector[0]);
|
---|
| 109 | CPPUNIT_ASSERT( atoms.find(atomVector[0]) == atoms.begin() );
|
---|
| 110 | CPPUNIT_ASSERT( atoms.find(atomVector[0]) != atoms.end() );
|
---|
| 111 | atoms.erase(atomVector[0]);
|
---|
| 112 |
|
---|
| 113 | // search for key
|
---|
| 114 | atoms.insert(atomVector[0]->getId());
|
---|
| 115 | CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) == atoms.begin() );
|
---|
| 116 | CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) != atoms.end() );
|
---|
| 117 | atoms.erase(atomVector[0]->getId());
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | void AtomIdSetUnittest::emptyTest()
|
---|
| 122 | {
|
---|
| 123 | // initially empty
|
---|
| 124 | CPPUNIT_ASSERT( atoms.empty() );
|
---|
| 125 |
|
---|
| 126 | // filled with one then no more
|
---|
| 127 | atoms.insert(atomVector[0]);
|
---|
| 128 | CPPUNIT_ASSERT( !atoms.empty() );
|
---|
| 129 |
|
---|
| 130 | // erase and again empty
|
---|
| 131 | atoms.erase(atomVector[0]);
|
---|
| 132 | CPPUNIT_ASSERT( atoms.empty() );
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | void AtomIdSetUnittest::sizeTest()
|
---|
| 136 | {
|
---|
| 137 | // initially empty
|
---|
| 138 | CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
|
---|
| 139 |
|
---|
| 140 | // filled with one, then no more
|
---|
| 141 | atoms.insert(atomVector[0]);
|
---|
| 142 | CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
|
---|
| 143 |
|
---|
| 144 | // erase and again empty
|
---|
| 145 | atoms.erase(atomVector[0]);
|
---|
| 146 | CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
|
---|
| 147 | }
|
---|
| 148 |
|
---|