source: src/unittests/AtomIdSetUnitTest.cpp@ 57f743

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 57f743 was 5e6534, checked in by Frederik Heber <heber@…>, 13 years ago

Refactored transform_iterator out of class molecule as AtomIdSet.

  • also added unit test.
  • Property mode set to 100644
File size: 3.5 KB
Line 
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'
41CPPUNIT_TEST_SUITE_REGISTRATION( AtomIdSetUnittest );
42
43size_t AtomIdSetUnittest::MaxAtoms = 6;
44
45void 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
54void AtomIdSetUnittest::tearDown()
55{
56 World::purgeInstance();
57}
58
59void 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
80void 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
105void 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
121void 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
135void 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
Note: See TracBrowser for help on using the repository browser.