Changeset 57f5cf for src/unittests/DescriptorUnittest.cpp
- Timestamp:
- Mar 4, 2010, 9:49:45 AM (16 years ago)
- Branches:
- 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, Candidate_v1.7.0, 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
- Children:
- ab4b55
- Parents:
- 6bc51d (diff), 88d586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/unittests/DescriptorUnittest.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/DescriptorUnittest.cpp
r6bc51d r57f5cf 27 27 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 28 28 29 // some stubs30 class AtomStub : public atom {31 public:32 AtomStub(int _id) :33 atom(),34 id(_id)35 {}36 37 virtual int getId(){38 return id;39 }40 41 private:42 int id;43 };44 45 46 29 // set up and tear down 47 30 void DescriptorUnittest::setUp(){ 48 31 World::get(); 49 32 for(int i=0;i<ATOM_COUNT;++i){ 50 atoms[i]= new AtomStub(i); 33 atoms[i]= World::get()->createAtom(); 34 atomIds[i] = atoms[i]->getId(); 51 35 } 52 36 } 53 37 void DescriptorUnittest::tearDown(){ 54 38 World::destroy(); 55 for(int i=0;i<ATOM_COUNT;++i){56 delete atoms[i];57 }58 39 } 59 40 60 41 // some helper functions 61 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 62 for(int i=min;i<max;++i){ 63 if(!excluded.count(i)){ 42 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){ 43 for(int i=0;i<ATOM_COUNT;++i){ 44 int id = ids[i]; 45 if(!excluded.count(id)){ 64 46 std::vector<atom*>::iterator iter; 65 47 bool res=false; 66 48 for(iter=atoms.begin();iter!=atoms.end();++iter){ 67 res |= (*iter)->getId() == i ;49 res |= (*iter)->getId() == id; 68 50 } 69 51 if(!res) { 70 cout << "Atom " << i << " missing in returned list" << endl;52 cout << "Atom " << id << " missing in returned list" << endl; 71 53 return false; 72 54 } … … 91 73 void DescriptorUnittest::AtomBaseSetsTest(){ 92 74 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 93 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms, 0,ATOM_COUNT));75 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds)); 94 76 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 95 77 … … 100 82 // test Atoms from boundaries and middle of the set 101 83 atom* testAtom; 102 testAtom = World::get()->getAtom(AtomById(0)); 103 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId()); 104 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2)); 105 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId()); 106 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1)); 107 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId()); 84 testAtom = World::get()->getAtom(AtomById(atomIds[0])); 85 CPPUNIT_ASSERT(testAtom); 86 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId()); 87 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2])); 88 CPPUNIT_ASSERT(testAtom); 89 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId()); 90 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1])); 91 CPPUNIT_ASSERT(testAtom); 92 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); 108 93 94 // find some ID that has not been created 95 int outsideId =-1; 96 bool res = false; 97 while(!res) { 98 ++outsideId; 99 res = true; 100 for(int i = 0; i < ATOM_COUNT; ++i){ 101 res &= atomIds[i]!=outsideId; 102 } 103 } 109 104 // test from outside of set 110 testAtom = World::get()->getAtom(AtomById( ATOM_COUNT));105 testAtom = World::get()->getAtom(AtomById(outsideId)); 111 106 CPPUNIT_ASSERT(!testAtom); 112 107 } … … 115 110 { 116 111 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 117 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));112 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 118 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 119 114 } … … 121 116 { 122 117 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 123 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));118 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 124 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 125 120 } … … 142 137 { 143 138 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 144 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));139 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 145 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 146 141 } … … 148 143 // exclude and include some atoms 149 144 { 150 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById( ATOM_COUNT/2)));145 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 151 146 std::set<int> excluded; 152 excluded.insert( ATOM_COUNT/2);153 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT,excluded));147 excluded.insert(atomIds[ATOM_COUNT/2]); 148 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded)); 154 149 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 155 150 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 157 152 158 153 { 159 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById( ATOM_COUNT/2)));154 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2]))); 160 155 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 161 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());156 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); 162 157 } 163 158 }
Note:
See TracChangeset
for help on using the changeset viewer.
