source: src/unittests/AtomDescriptorTest.cpp@ 9cd807

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 9cd807 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * DescriptorUnittest.cpp
3 *
4 * Created on: Feb 9, 2010
5 * Author: crueger
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "AtomDescriptorTest.hpp"
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18#include <iostream>
19
20#include <Descriptors/AtomDescriptor.hpp>
21#include <Descriptors/AtomIdDescriptor.hpp>
22
23#include "World.hpp"
24#include "atom.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31// Registers the fixture into the 'registry'
32CPPUNIT_TEST_SUITE_REGISTRATION( AtomDescriptorTest );
33
34// set up and tear down
35void AtomDescriptorTest::setUp(){
36 World::getInstance();
37 for(int i=0;i<ATOM_COUNT;++i){
38 atoms[i]= World::getInstance().createAtom();
39 atomIds[i]= atoms[i]->getId();
40 }
41}
42
43void AtomDescriptorTest::tearDown(){
44 World::purgeInstance();
45}
46
47// some helper functions
48static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){
49 for(int i=0;i<ATOM_COUNT;++i){
50 atomId_t id = ids[i];
51 if(!excluded.count(id)){
52 std::vector<atom*>::iterator iter;
53 bool res=false;
54 for(iter=atoms.begin();iter!=atoms.end();++iter){
55 res |= (*iter)->getId() == id;
56 }
57 if(!res) {
58 cout << "Atom " << id << " missing in returned list" << endl;
59 return false;
60 }
61 }
62 }
63 return true;
64}
65
66static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){
67 std::set<atomId_t> found;
68 std::vector<atom*>::iterator iter;
69 for(iter=atoms.begin();iter!=atoms.end();++iter){
70 int id = (*iter)->getId();
71 if(found.count(id))
72 return false;
73 found.insert(id);
74 }
75 return true;
76}
77
78
79void AtomDescriptorTest::AtomBaseSetsTest(){
80 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
81 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
82 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
83
84 std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
85 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
86}
87void AtomDescriptorTest::AtomIdTest(){
88 // test Atoms from boundaries and middle of the set
89 atom* testAtom;
90 testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
91 CPPUNIT_ASSERT(testAtom);
92 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
93 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT/2]));
94 CPPUNIT_ASSERT(testAtom);
95 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
96 testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT-1]));
97 CPPUNIT_ASSERT(testAtom);
98 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
99
100 // find some ID that has not been created
101 atomId_t outsideId=0;
102 bool res = false;
103 for(outsideId=0;!res;++outsideId) {
104 res = true;
105 for(int i = 0; i < ATOM_COUNT; ++i){
106 res &= atomIds[i]!=outsideId;
107 }
108 }
109 // test from outside of set
110 testAtom = World::getInstance().getAtom(AtomById(outsideId));
111 CPPUNIT_ASSERT(!testAtom);
112}
113void AtomDescriptorTest::AtomCalcTest(){
114 // test some elementary set operations
115 {
116 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
117 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
118 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
119 }
120
121 {
122 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
123 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
124 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
125 }
126
127 {
128 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
129 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
130 }
131
132 {
133 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
134 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
135 }
136
137 {
138 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
139 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
140 }
141
142 {
143 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
144 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
145 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
146 }
147 // exclude and include some atoms
148 {
149 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
150 std::set<atomId_t> excluded;
151 excluded.insert(atomIds[ATOM_COUNT/2]);
152 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds,excluded));
153 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
154 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
155 }
156
157 {
158 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
159 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
160 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
161 }
162}
Note: See TracBrowser for help on using the repository browser.