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::containsTest()
|
---|
106 | {
|
---|
107 | // search for atom
|
---|
108 | atoms.insert(atomVector[0]);
|
---|
109 | CPPUNIT_ASSERT( atoms.contains(atomVector[0]) );
|
---|
110 | atoms.erase(atomVector[0]);
|
---|
111 | CPPUNIT_ASSERT( !atoms.contains(atomVector[0]) );
|
---|
112 |
|
---|
113 | // search for key
|
---|
114 | atoms.insert(atomVector[0]->getId());
|
---|
115 | CPPUNIT_ASSERT( atoms.contains(atomVector[0]->getId()) );
|
---|
116 | atoms.erase(atomVector[0]->getId());
|
---|
117 | CPPUNIT_ASSERT( !atoms.contains(atomVector[0]->getId()) );
|
---|
118 | }
|
---|
119 |
|
---|
120 | void AtomIdSetUnittest::findTest()
|
---|
121 | {
|
---|
122 | // search for atom
|
---|
123 | atoms.insert(atomVector[0]);
|
---|
124 | CPPUNIT_ASSERT( atoms.find(atomVector[0]) == atoms.begin() );
|
---|
125 | CPPUNIT_ASSERT( atoms.find(atomVector[0]) != atoms.end() );
|
---|
126 | atoms.erase(atomVector[0]);
|
---|
127 |
|
---|
128 | // search for key
|
---|
129 | atoms.insert(atomVector[0]->getId());
|
---|
130 | CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) == atoms.begin() );
|
---|
131 | CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) != atoms.end() );
|
---|
132 | atoms.erase(atomVector[0]->getId());
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | void AtomIdSetUnittest::emptyTest()
|
---|
137 | {
|
---|
138 | // initially empty
|
---|
139 | CPPUNIT_ASSERT( atoms.empty() );
|
---|
140 |
|
---|
141 | // filled with one then no more
|
---|
142 | atoms.insert(atomVector[0]);
|
---|
143 | CPPUNIT_ASSERT( !atoms.empty() );
|
---|
144 |
|
---|
145 | // erase and again empty
|
---|
146 | atoms.erase(atomVector[0]);
|
---|
147 | CPPUNIT_ASSERT( atoms.empty() );
|
---|
148 | }
|
---|
149 |
|
---|
150 | void AtomIdSetUnittest::sizeTest()
|
---|
151 | {
|
---|
152 | // initially empty
|
---|
153 | CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
|
---|
154 |
|
---|
155 | // filled with one, then no more
|
---|
156 | atoms.insert(atomVector[0]);
|
---|
157 | CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
|
---|
158 |
|
---|
159 | // erase and again empty
|
---|
160 | atoms.erase(atomVector[0]);
|
---|
161 | CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
|
---|
162 | }
|
---|
163 |
|
---|