Ignore:
Timestamp:
Mar 4, 2010, 9:49:45 AM (16 years ago)
Author:
Saskia Metzler <metzler@…>
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.
Message:

Merge commit 'till/StructureRefactoring' into StateAndFormatParser

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/unittests/Makefile.am

SOURCE and HEADER are both one long line and thus could not be merged automatically.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/DescriptorUnittest.cpp

    r6bc51d r57f5cf  
    2727CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2828
    29 // some stubs
    30 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 
    4629// set up and tear down
    4730void DescriptorUnittest::setUp(){
    4831  World::get();
    4932  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();
    5135  }
    5236}
    5337void DescriptorUnittest::tearDown(){
    5438  World::destroy();
    55   for(int i=0;i<ATOM_COUNT;++i){
    56     delete atoms[i];
    57   }
    5839}
    5940
    6041// 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)){
     42bool 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)){
    6446      std::vector<atom*>::iterator iter;
    6547      bool res=false;
    6648      for(iter=atoms.begin();iter!=atoms.end();++iter){
    67         res |= (*iter)->getId() == i;
     49        res |= (*iter)->getId() == id;
    6850      }
    6951      if(!res) {
    70         cout << "Atom " << i << " missing in returned list" << endl;
     52        cout << "Atom " << id << " missing in returned list" << endl;
    7153        return false;
    7254      }
     
    9173void DescriptorUnittest::AtomBaseSetsTest(){
    9274  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));
    9476  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    9577
     
    10082  // test Atoms from boundaries and middle of the set
    10183  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());
    10893
     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  }
    109104  // test from outside of set
    110   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
     105  testAtom = World::get()->getAtom(AtomById(outsideId));
    111106  CPPUNIT_ASSERT(!testAtom);
    112107}
     
    115110  {
    116111    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));
    118113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    119114  }
     
    121116  {
    122117    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));
    124119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    125120  }
     
    142137  {
    143138    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));
    145140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    146141  }
     
    148143  // exclude and include some atoms
    149144  {
    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])));
    151146    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));
    154149    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    155150    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    157152
    158153  {
    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])));
    160155    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());
    162157  }
    163158}
Note: See TracChangeset for help on using the changeset viewer.