source: src/unittests/AtomIdSetUnitTest.cpp@ e4b9d5

Candidate_v1.7.1 stable
Last change on this file since e4b9d5 was 25aa214, checked in by Frederik Heber <frederik.heber@…>, 11 days ago

FIX: fragmentation hydrogens do not trigger AtomInserted.

  • we had already switched off position and element changes. However, the fragmentation hydrogens could still be briefly seen on creation because the AtomInserted notification is still triggered. The World::createAtom allows now to suppress the notifcation. The switch options are put into an enum to make them very verbose in the code. This should really only be used by the HydrogenPool.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * AtomIdSetUnitTest.cpp
25 *
26 * Created on: Feb 21, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include <algorithm>
40
41#include "Atom/atom.hpp"
42#include "AtomIdSet.hpp"
43#include "CodePatterns/Assert.hpp"
44#include "World.hpp"
45
46#include "AtomIdSetUnitTest.hpp"
47
48
49#ifdef HAVE_TESTRUNNER
50#include "UnitTestMain.hpp"
51#endif /*HAVE_TESTRUNNER*/
52
53/********************************************** Test classes **************************************/
54
55// Registers the fixture into the 'registry'
56CPPUNIT_TEST_SUITE_REGISTRATION( AtomIdSetUnittest );
57
58size_t AtomIdSetUnittest::MaxAtoms = 6;
59
60void AtomIdSetUnittest::setUp(){
61 // failing asserts should be thrown
62 ASSERT_DO(Assert::Throw);
63
64 atomVector.resize((size_t)MaxAtoms);
65 std::generate_n(atomVector.begin(), MaxAtoms, boost::bind(
66 static_cast<atom* (World::*)(World::CreateAtomNotificationType)>(&World::createAtom),
67 World::getPointer(),
68 World::CreateAtomNotificationType::NOTIFY_ON_CREATE_ATOM)
69 );
70}
71
72void AtomIdSetUnittest::tearDown()
73{
74 World::purgeInstance();
75}
76
77void AtomIdSetUnittest::inserteraseTest()
78{
79 // insert all
80 for (size_t i=0; i< MaxAtoms; ++i) {
81 atoms.insert(atomVector[i]);
82 }
83 CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, atoms.size() );
84
85 // erase them again
86 for (size_t i=0; i< MaxAtoms; ++i) {
87 atoms.erase(atomVector[i]);
88 }
89 CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
90
91 {
92 // use atomVector in cstor
93 AtomIdSet otherAtoms(atomVector);
94 CPPUNIT_ASSERT_EQUAL( (size_t)MaxAtoms, otherAtoms.size() );
95 }
96}
97
98void AtomIdSetUnittest::positionTest()
99{
100 // non-const iterators
101 CPPUNIT_ASSERT( atoms.begin() == atoms.end() );
102
103 // const iterators
104 {
105 AtomIdSet::const_iterator beg_iter = const_cast<const AtomIdSet &>(atoms).begin();
106 AtomIdSet::const_iterator end_iter = const_cast<const AtomIdSet &>(atoms).end();
107 CPPUNIT_ASSERT( beg_iter == end_iter );
108 }
109
110 // insert an element
111 atoms.insert(atomVector[0]);
112 CPPUNIT_ASSERT( atoms.begin() != atoms.end() );
113
114 {
115 AtomIdSet::const_iterator beg_iter = const_cast<const AtomIdSet &>(atoms).begin();
116 AtomIdSet::const_iterator end_iter = const_cast<const AtomIdSet &>(atoms).end();
117 CPPUNIT_ASSERT( beg_iter != end_iter );
118 ++beg_iter;
119 CPPUNIT_ASSERT( beg_iter == end_iter );
120 }
121}
122
123void AtomIdSetUnittest::containsTest()
124{
125 // search for atom
126 atoms.insert(atomVector[0]);
127 CPPUNIT_ASSERT( atoms.contains(atomVector[0]) );
128 atoms.erase(atomVector[0]);
129 CPPUNIT_ASSERT( !atoms.contains(atomVector[0]) );
130
131 // search for key
132 atoms.insert(atomVector[0]->getId());
133 CPPUNIT_ASSERT( atoms.contains(atomVector[0]->getId()) );
134 atoms.erase(atomVector[0]->getId());
135 CPPUNIT_ASSERT( !atoms.contains(atomVector[0]->getId()) );
136}
137
138void AtomIdSetUnittest::findTest()
139{
140 // search for atom
141 atoms.insert(atomVector[0]);
142 CPPUNIT_ASSERT( atoms.find(atomVector[0]) == const_cast<const AtomIdSet &>(atoms).begin() );
143 CPPUNIT_ASSERT( atoms.find(atomVector[0]) != const_cast<const AtomIdSet &>(atoms).end() );
144 atoms.erase(atomVector[0]);
145
146 // search for key
147 atoms.insert(atomVector[0]->getId());
148 CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) == const_cast<const AtomIdSet &>(atoms).begin() );
149 CPPUNIT_ASSERT( atoms.find(atomVector[0]->getId()) != const_cast<const AtomIdSet &>(atoms).end() );
150 atoms.erase(atomVector[0]->getId());
151}
152
153
154void AtomIdSetUnittest::emptyTest()
155{
156 // initially empty
157 CPPUNIT_ASSERT( atoms.empty() );
158
159 // filled with one then no more
160 atoms.insert(atomVector[0]);
161 CPPUNIT_ASSERT( !atoms.empty() );
162
163 // erase and again empty
164 atoms.erase(atomVector[0]);
165 CPPUNIT_ASSERT( atoms.empty() );
166}
167
168void AtomIdSetUnittest::sizeTest()
169{
170 // initially empty
171 CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
172
173 // filled with one, then no more
174 atoms.insert(atomVector[0]);
175 CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
176
177 // erase and again empty
178 atoms.erase(atomVector[0]);
179 CPPUNIT_ASSERT_EQUAL( (size_t)0, atoms.size() );
180}
181
Note: See TracBrowser for help on using the repository browser.