source: src/unittests/MoleculeDescriptorTest.cpp@ bd58fb

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 bd58fb was 57adc7, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added methods to query Molecules by ID

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