Changeset 4415da for src/unittests


Ignore:
Timestamp:
Apr 1, 2010, 12:16:29 PM (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:
b8d4a3
Parents:
9131f3 (diff), f9352d (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 Till's structure refactoring

Merge commit 'till/StructureRefactoring' into StateAndFormatParser

Conflicts:

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

Location:
src/unittests
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ActionSequenceTest.cpp

    r9131f3 r4415da  
    3535  virtual ~canUndoActionStub(){}
    3636
    37   virtual void call(){}
    38   virtual void undo(){}
     37  virtual Action::state_ptr performCall(){
     38    return Action::success;
     39  }
     40  virtual Action::state_ptr performUndo(Action::state_ptr){
     41    return Action::success;
     42  }
     43  virtual Action::state_ptr performRedo(Action::state_ptr){
     44    return Action::success;
     45  }
    3946  virtual bool canUndo(){
     47    return true;
     48  }
     49  virtual bool shouldUndo(){
    4050    return true;
    4151  }
     
    4858  virtual ~cannotUndoActionStub(){}
    4959
    50   virtual void call(){}
    51   virtual void undo(){}
     60  virtual Action::state_ptr performCall(){
     61    return Action::success;
     62  }
     63  virtual Action::state_ptr performUndo(Action::state_ptr){
     64    return Action::success;
     65  }
     66  virtual Action::state_ptr performRedo(Action::state_ptr){
     67    return Action::success;
     68  }
    5269  virtual bool canUndo(){
    5370    return false;
     71  }
     72  virtual bool shouldUndo(){
     73   return true;
    5474  }
    5575};
     
    6484  virtual ~wasCalledActionStub(){}
    6585
    66   virtual void call(){
     86  virtual Action::state_ptr performCall(){
    6787    called = true;
    68   }
    69   virtual void undo(){
     88    return Action::success;
     89  }
     90  virtual Action::state_ptr performUndo(Action::state_ptr){
    7091    called = false;
     92    return Action::success;
     93  }
     94  virtual Action::state_ptr performRedo(Action::state_ptr){
     95    called = true;
     96    return Action::success;
    7197  }
    7298  virtual bool canUndo(){
     99    return true;
     100  }
     101  virtual bool shouldUndo(){
    73102    return true;
    74103  }
     
    185214  sequence->addAction(shouldCall2);
    186215
    187   sequence->callAll();
    188 
    189   sequence->removeLastAction();
    190   sequence->removeLastAction();
    191 
    192   sequence->undoAll();
     216  ActionSequence::stateSet states = sequence->callAll();
     217
     218  sequence->removeLastAction();
     219  sequence->removeLastAction();
     220
     221  sequence->undoAll(states);
    193222
    194223  CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r9131f3 r4415da  
    5757
    5858  // construct periodentafel
    59   tafel = World::get()->getPeriode();
     59  tafel = World::getInstance().getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161
    6262  // construct molecule (tetraeder of hydrogens)
    63   TestMolecule = World::get()->createMolecule();
    64   Walker = World::get()->createAtom();
     63  TestMolecule = World::getInstance().createMolecule();
     64  Walker = World::getInstance().createAtom();
    6565  Walker->type = hydrogen;
    6666  Walker->node->Init(1., 0., 1. );
    6767  TestMolecule->AddAtom(Walker);
    68   Walker = World::get()->createAtom();
     68  Walker = World::getInstance().createAtom();
    6969  Walker->type = hydrogen;
    7070  Walker->node->Init(0., 1., 1. );
    7171  TestMolecule->AddAtom(Walker);
    72   Walker = World::get()->createAtom();
     72  Walker = World::getInstance().createAtom();
    7373  Walker->type = hydrogen;
    7474  Walker->node->Init(1., 1., 0. );
    7575  TestMolecule->AddAtom(Walker);
    76   Walker = World::get()->createAtom();
     76  Walker = World::getInstance().createAtom();
    7777  Walker->type = hydrogen;
    7878  Walker->node->Init(0., 0., 0. );
     
    8282  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8383
    84   TestList = World::get()->getMolecules();
     84  TestList = World::getInstance().getMolecules();
    8585  TestMolecule->ActiveFlag = true;
    8686  TestList->insert(TestMolecule);
     
    104104
    105105  delete(point);
    106   World::destroy();
     106  World::purgeInstance();
    107107  MemoryUsageObserver::purgeInstance();
    108108  logger::purgeInstance();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r9131f3 r4415da  
    2727#include "World.hpp"
    2828
     29#include "Helpers/Assert.hpp"
     30
    2931#ifdef HAVE_TESTRUNNER
    3032#include "UnitTestMain.hpp"
     
    3840void AnalysisCorrelationToSurfaceUnitTest::setUp()
    3941{
     42  ASSERT_DO(Assert::Throw);
     43
    4044  atom *Walker = NULL;
    4145
     
    6165
    6266  // construct periodentafel
    63   tafel = World::get()->getPeriode();
     67  tafel = World::getInstance().getPeriode();
    6468  tafel->AddElement(hydrogen);
    6569  tafel->AddElement(carbon);
    6670
    6771  // construct molecule (tetraeder of hydrogens) base
    68   TestMolecule = World::get()->createMolecule();
    69   Walker = World::get()->createAtom();
     72  TestMolecule = World::getInstance().createMolecule();
     73  Walker = World::getInstance().createAtom();
    7074  Walker->type = hydrogen;
    7175  Walker->node->Init(1., 0., 1. );
    7276  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7478  Walker->type = hydrogen;
    7579  Walker->node->Init(0., 1., 1. );
    7680  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     81  Walker = World::getInstance().createAtom();
    7882  Walker->type = hydrogen;
    7983  Walker->node->Init(1., 1., 0. );
    8084  TestMolecule->AddAtom(Walker);
    81   Walker = World::get()->createAtom();
     85  Walker = World::getInstance().createAtom();
    8286  Walker->type = hydrogen;
    8387  Walker->node->Init(0., 0., 0. );
     
    8791  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8892
    89   TestList = World::get()->getMolecules();
     93  TestList = World::getInstance().getMolecules();
    9094  TestMolecule->ActiveFlag = true;
    9195  TestList->insert(TestMolecule);
     
    100104
    101105  // add outer atoms
    102   Walker = World::get()->createAtom();
     106  Walker = World::getInstance().createAtom();
    103107  Walker->type = carbon;
    104108  Walker->node->Init(4., 0., 4. );
    105109  TestMolecule->AddAtom(Walker);
    106   Walker = World::get()->createAtom();
     110  Walker = World::getInstance().createAtom();
    107111  Walker->type = carbon;
    108112  Walker->node->Init(0., 4., 4. );
    109113  TestMolecule->AddAtom(Walker);
    110   Walker = World::get()->createAtom();
     114  Walker = World::getInstance().createAtom();
    111115  Walker->type = carbon;
    112116  Walker->node->Init(4., 4., 0. );
    113117  TestMolecule->AddAtom(Walker);
    114118  // add inner atoms
    115   Walker = World::get()->createAtom();
     119  Walker = World::getInstance().createAtom();
    116120  Walker->type = carbon;
    117121  Walker->node->Init(0.5, 0.5, 0.5 );
     
    135139  // note that all the atoms are cleaned by TestMolecule
    136140  delete(LC);
    137   World::destroy();
     141  World::purgeInstance();
    138142  MemoryUsageObserver::purgeInstance();
    139143  logger::purgeInstance();
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r9131f3 r4415da  
    5656
    5757  // construct periodentafel
    58   tafel = World::get()->getPeriode();
     58  tafel = World::getInstance().getPeriode();
    5959  tafel->AddElement(hydrogen);
    6060
    6161  // construct molecule (tetraeder of hydrogens)
    62   TestMolecule = World::get()->createMolecule();
    63   Walker = World::get()->createAtom();
     62  TestMolecule = World::getInstance().createMolecule();
     63  Walker = World::getInstance().createAtom();
    6464  Walker->type = hydrogen;
    6565  Walker->node->Init(1., 0., 1. );
    6666  TestMolecule->AddAtom(Walker);
    67   Walker = World::get()->createAtom();
     67  Walker = World::getInstance().createAtom();
    6868  Walker->type = hydrogen;
    6969  Walker->node->Init(0., 1., 1. );
    7070  TestMolecule->AddAtom(Walker);
    71   Walker = World::get()->createAtom();
     71  Walker = World::getInstance().createAtom();
    7272  Walker->type = hydrogen;
    7373  Walker->node->Init(1., 1., 0. );
    7474  TestMolecule->AddAtom(Walker);
    75   Walker = World::get()->createAtom();
     75  Walker = World::getInstance().createAtom();
    7676  Walker->type = hydrogen;
    7777  Walker->node->Init(0., 0., 0. );
     
    8181  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8282
    83   TestList = World::get()->getMolecules();
     83  TestList = World::getInstance().getMolecules();
    8484  TestMolecule->ActiveFlag = true;
    8585  TestList->insert(TestMolecule);
     
    100100
    101101  // note that all the atoms are cleaned by TestMolecule
    102   World::destroy();
     102  World::purgeInstance();
    103103  MemoryUsageObserver::purgeInstance();
    104104  logger::purgeInstance();
  • src/unittests/AtomDescriptorTest.cpp

    r9131f3 r4415da  
    2929// set up and tear down
    3030void AtomDescriptorTest::setUp(){
    31   World::get();
     31  World::getInstance();
    3232  for(int i=0;i<ATOM_COUNT;++i){
    33     atoms[i]= World::get()->createAtom();
     33    atoms[i]= World::getInstance().createAtom();
    3434    atomIds[i]= atoms[i]->getId();
    3535  }
     
    3737
    3838void AtomDescriptorTest::tearDown(){
    39   World::destroy();
     39  World::purgeInstance();
    4040}
    4141
     
    7373
    7474void AtomDescriptorTest::AtomBaseSetsTest(){
    75   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     75  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
    7878
    79   std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms());
     79  std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
    8080  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    8181}
     
    8383  // test Atoms from boundaries and middle of the set
    8484  atom* testAtom;
    85   testAtom = World::get()->getAtom(AtomById(atomIds[0]));
     85  testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
    8686  CPPUNIT_ASSERT(testAtom);
    8787  CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
    88   testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));
     88  testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT/2]));
    8989  CPPUNIT_ASSERT(testAtom);
    9090  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
    91   testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));
     91  testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT-1]));
    9292  CPPUNIT_ASSERT(testAtom);
    9393  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
     
    103103  }
    104104  // test from outside of set
    105   testAtom = World::get()->getAtom(AtomById(outsideId));
     105  testAtom = World::getInstance().getAtom(AtomById(outsideId));
    106106  CPPUNIT_ASSERT(!testAtom);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
     111    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    115115
    116116  {
    117     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
     117    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    121121
    122122  {
    123     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()&&AllAtoms());
     123    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
    124124    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    125125  }
    126126
    127127  {
    128     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&NoAtoms());
     128    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
    129129    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    130130  }
    131131
    132132  {
    133     std::vector<atom*> testAtoms = World::get()->getAllAtoms(!AllAtoms());
     133    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
    134134    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    135135  }
    136136
    137137  {
    138     std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
     138    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    141141  }
    142 
    143142  // exclude and include some atoms
    144143  {
    145     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
     144    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    146145    std::set<atomId_t> excluded;
    147146    excluded.insert(atomIds[ATOM_COUNT/2]);
     
    152151
    153152  {
    154     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
     153    std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    155154    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    156155    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
  • src/unittests/AtomDescriptorTest.hpp

    r9131f3 r4415da  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define ATOM_COUNT (10)
  • src/unittests/CacheableTest.cpp

    r9131f3 r4415da  
    2727class threeNumbers : public Observable {
    2828public:
    29   bool hasRecalced;
    3029  int x;
    3130  int y;
    3231  int z;
     32  Cacheable<int> sum;
     33  bool hasRecalced;
    3334
    3435  void setX(int _x){
     
    5455
    5556  threeNumbers(int _x,int _y, int _z) :
     57    x(_x),y(_y),z(_z),
    5658    sum(this,boost::bind(&threeNumbers::calcSum,this)),
    57     x(_x),y(_y),z(_z),
    5859    hasRecalced(false)
    5960  {}
    60 
    61   Cacheable<int> sum;
    6261};
    6362
  • src/unittests/Makefile.am

    r9131f3 r4415da  
    2929  ObserverTest \
    3030  ParserUnitTest \
     31  SingletonTest \
    3132  StackClassUnitTest \
    3233  TesselationUnitTest \
     
    6869  ObserverTest.cpp \
    6970  ParserUnitTest.cpp \
     71  SingletonTest.cpp \
    7072  stackclassunittest.cpp \
    7173  tesselationunittest.cpp \
     
    9193AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    9294AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS}
     95
     96atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     97atomsCalculationTest_LDADD = ${ALLLIBS}
    9398
    9499BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
     
    125130MoleculeDescriptorTest_LDADD = ${ALLLIBS}
    126131
     132SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
     133SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB}
     134
    127135StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
    128136StackClassUnitTest_LDADD = ${ALLLIBS}
     
    158166manipulateAtomsTest_LDADD = ${ALLLIBS}
    159167
    160 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
    161 atomsCalculationTest_LDADD = ${ALLLIBS}
    162 
    163168TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    164169TestRunner_LDADD = ${ALLLIBS}
  • src/unittests/MoleculeDescriptorTest.cpp

    r9131f3 r4415da  
    2929// set up and tear down
    3030void MoleculeDescriptorTest::setUp(){
    31   World::get();
     31  World::getInstance();
    3232  for(int i=0;i<MOLECULE_COUNT;++i){
    33     molecules[i]= World::get()->createMolecule();
     33    molecules[i]= World::getInstance().createMolecule();
    3434    moleculeIds[i]= molecules[i]->getId();
    3535  }
     
    3737
    3838void MoleculeDescriptorTest::tearDown(){
    39   World::destroy();
     39  World::purgeInstance();
    4040}
    4141
     
    7373
    7474void MoleculeDescriptorTest::MoleculeBaseSetsTest(){
    75   std::vector<molecule*> allMolecules = World::get()->getAllMolecules(AllMolecules());
     75  std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules));
    7878
    79   std::vector<molecule*> noMolecules = World::get()->getAllMolecules(NoMolecules());
     79  std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules());
    8080  CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty());
    8181}
     
    8383  // test Molecules from boundaries and middle of the set
    8484  molecule* testMolecule;
    85   testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[0]));
     85  testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0]));
    8686  CPPUNIT_ASSERT(testMolecule);
    8787  CPPUNIT_ASSERT_EQUAL( moleculeIds[0], testMolecule->getId());
    88   testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
     88  testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
    8989  CPPUNIT_ASSERT(testMolecule);
    9090  CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecule->getId());
    91   testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
     91  testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
    9292  CPPUNIT_ASSERT(testMolecule);
    9393  CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId());
     
    103103  }
    104104  // test from outside of set
    105   testMolecule = World::get()->getMolecule(MoleculeById(outsideId));
     105  testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId));
    106106  CPPUNIT_ASSERT(!testMolecule);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()||NoMolecules());
     111    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    115115
    116116  {
    117     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()||AllMolecules());
     117    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    121121
    122122  {
    123     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()&&AllMolecules());
     123    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules());
    124124    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    125125  }
    126126
    127127  {
    128     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()&&NoMolecules());
     128    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules());
    129129    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    130130  }
    131131
    132132  {
    133     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!AllMolecules());
     133    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules());
    134134    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    135135  }
    136136
    137137  {
    138     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!NoMolecules());
     138    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    143143  // exclude and include some molecules
    144144  {
    145     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
     145    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
    146146    std::set<moleculeId_t> excluded;
    147147    excluded.insert(moleculeIds[MOLECULE_COUNT/2]);
     
    152152
    153153  {
    154     std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
     154    std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
    155155    CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size());
    156156    CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId());
  • src/unittests/MoleculeDescriptorTest.hpp

    r9131f3 r4415da  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "defs.hpp"
     13#include "types.hpp"
    1414
    1515#define MOLECULE_COUNT (10)
  • src/unittests/ObserverTest.cpp

    r9131f3 r4415da  
    1313
    1414#include "Patterns/Observer.hpp"
     15#include "Helpers/Assert.hpp"
    1516
    1617#include <iostream>
     
    6566};
    6667
     68class BlockObservable : public Observable {
     69public:
     70  void changeMethod1(){
     71    OBSERVE;
     72    // test if we report correctly as blocked
     73    CPPUNIT_ASSERT(isBlocked());
     74  }
     75
     76  void changeMethod2(){
     77    OBSERVE;
     78    internalMethod1();
     79    internalMethod2();
     80  }
     81
     82  void internalMethod1(){
     83    // we did not block, but our caller did...
     84    // see if this is found
     85    CPPUNIT_ASSERT(isBlocked());
     86  }
     87
     88  void internalMethod2(){
     89    OBSERVE;
     90    // Both this method and the caller do block
     91    // Does the reporting still work as expected?
     92    CPPUNIT_ASSERT(isBlocked());
     93  }
     94
     95  void noChangeMethod(){
     96    // No Block introduced here
     97    // reported correctely?
     98    CPPUNIT_ASSERT(!isBlocked());
     99  }
     100};
     101
    67102class SuperObservable : public Observable {
    68103public:
     
    86121
    87122void ObserverTest::setUp() {
     123  ASSERT_DO(Assert::Throw);
    88124  simpleObservable1 = new SimpleObservable();
    89125  simpleObservable2 = new SimpleObservable();
    90126  callObservable = new CallObservable();
    91127  superObservable = new SuperObservable();
     128  blockObservable = new BlockObservable();
    92129
    93130  observer1 = new UpdateCountObserver();
     
    163200}
    164201
     202void ObserverTest::doesReportTest(){
     203  // Actual checks are in the Stub-methods for this
     204  blockObservable->changeMethod1();
     205  blockObservable->changeMethod2();
     206  blockObservable->noChangeMethod();
     207}
    165208
    166209void ObserverTest::CircleDetectionTest() {
     
    174217  // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE
    175218  simpleObservable1->signOn(simpleObservable1);
    176   simpleObservable1->changeMethod();
     219  CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
    177220
    178221  // more complex test
     
    180223  simpleObservable1->signOn(simpleObservable2);
    181224  simpleObservable2->signOn(simpleObservable1);
    182   simpleObservable1->changeMethod();
     225  CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure);
    183226  simpleObservable1->signOff(simpleObservable2);
    184227  simpleObservable2->signOff(simpleObservable1);
  • src/unittests/ObserverTest.hpp

    r9131f3 r4415da  
    1616class CallObservable;
    1717class SuperObservable;
     18class BlockObservable;
    1819
    1920
     
    2425  CPPUNIT_TEST ( doesBlockUpdateTest );
    2526  CPPUNIT_TEST ( doesSubObservableTest );
     27  CPPUNIT_TEST ( doesReportTest );
    2628  CPPUNIT_TEST ( CircleDetectionTest );
    2729  CPPUNIT_TEST_SUITE_END();
     
    3436  void doesBlockUpdateTest();
    3537  void doesSubObservableTest();
     38  void doesReportTest();
    3639  void CircleDetectionTest();
    3740
     
    4548  SimpleObservable *simpleObservable2;
    4649  CallObservable *callObservable;
     50  BlockObservable *blockObservable;
    4751  SuperObservable *superObservable;
    4852};
  • src/unittests/ParserUnitTest.cpp

    r9131f3 r4415da  
    3232  oxygen->symbol[0] = 'O';
    3333  oxygen->Z = 8;
    34   World::get()->getPeriode()->AddElement(oxygen);
     34  World::getInstance().getPeriode()->AddElement(oxygen);
    3535
    3636  element* hydrogen = new element();
    3737  hydrogen->symbol[0] = 'H';
    3838  hydrogen->Z = 1;
    39   World::get()->getPeriode()->AddElement(hydrogen);
     39  World::getInstance().getPeriode()->AddElement(hydrogen);
    4040}
    4141
     
    5353  testParser->load(&input);
    5454
    55   CPPUNIT_ASSERT_EQUAL(3, World::get()->numAtoms());
     55  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    5656
    5757  string newWaterXyz = "";
     
    6666  cout << "Testing the tremolo parser." << endl;
    6767  TremoloParser* testParser = new TremoloParser();
     68  stringstream input;
     69
     70  // Atomdata beginning with "# ATOMDATA"
    6871  string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n";
    69   stringstream input;
    7072  input << waterTremolo;
    7173  testParser->load(&input);
     74  input.clear();
     75
     76  // Atomdata beginning with "#ATOMDATA"
    7277  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
    73   input.clear();
    7478  input << waterTremolo;
    7579  testParser->load(&input);
     80  input.clear();
     81
     82  // One simple data line
     83  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
     84  input << waterTremolo;
     85  testParser->load(&input);
     86  input.clear();
     87
     88  // Invalid key in Atomdata line
     89  waterTremolo = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
     90  input << waterTremolo;
     91  testParser->load(&input);
     92  input.clear();
     93
    7694  cout << "testing the tremolo parser is done" << endl;
    7795}
  • src/unittests/analysisbondsunittest.cpp

    r9131f3 r4415da  
    5353  strcpy(hydrogen->symbol, "H");
    5454  carbon = new element;
    55   carbon->Z = 1;
     55  carbon->Z = 2;
    5656  carbon->Valence = 4;
    5757  carbon->NoValenceOrbitals = 4;
     
    6161
    6262  // construct periodentafel
    63   tafel = World::get()->getPeriode();
     63  tafel = World::getInstance().getPeriode();
    6464  tafel->AddElement(hydrogen);
    6565  tafel->AddElement(carbon);
    6666
    6767  // construct molecule (tetraeder of hydrogens)
    68   TestMolecule = World::get()->createMolecule();
    69   Walker = World::get()->createAtom();
     68  TestMolecule = World::getInstance().createMolecule();
     69  Walker = World::getInstance().createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(1.5, 0., 1.5 );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     73  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(0., 1.5, 1.5 );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(1.5, 1.5, 0. );
    8080  TestMolecule->AddAtom(Walker);
    81   Walker = World::get()->createAtom();
     81  Walker = World::getInstance().createAtom();
    8282  Walker->type = hydrogen;
    8383  Walker->node->Init(0., 0., 0. );
    8484  TestMolecule->AddAtom(Walker);
    85   Walker = World::get()->createAtom();
     85  Walker = World::getInstance().createAtom();
    8686  Walker->type = carbon;
    8787  Walker->node->Init(0.5, 0.5, 0.5 );
     
    117117
    118118  // remove molecule
    119   World::get()->destroyMolecule(TestMolecule);
     119  World::getInstance().destroyMolecule(TestMolecule);
    120120  // note that all the atoms are cleaned by TestMolecule
    121   World::destroy();
     121  World::purgeInstance();
    122122};
    123123
  • src/unittests/atomsCalculationTest.cpp

    r9131f3 r4415da  
    2424#include "atom.hpp"
    2525
     26#ifdef HAVE_TESTRUNNER
     27#include "UnitTestMain.hpp"
     28#endif /*HAVE_TESTRUNNER*/
     29
    2630// Registers the fixture into the 'registry'
    2731CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest );
    2832
    29 // some stubs
    30 class AtomStub : public atom {
    31 public:
    32   AtomStub(atomId_t _id) :
    33   atom(),
    34   id(_id),
    35   manipulated(false)
    36   {}
    37 
    38   virtual atomId_t getId(){
    39     return id;
    40   }
    41 
    42   virtual void doSomething(){
    43     manipulated = true;
    44   }
    45 
    46   bool manipulated;
    47 private:
    48   atomId_t id;
    49 };
    50 
    5133// set up and tear down
    5234void atomsCalculationTest::setUp(){
    53   World::get();
     35  World::getInstance();
    5436  for(int i=0;i<ATOM_COUNT;++i){
    55     atoms[i]= new AtomStub(i);
    56     World::get()->registerAtom(atoms[i]);
     37    atoms[i]= World::getInstance().createAtom();
     38    atomIds[i]= atoms[i]->getId();
    5739  }
    5840}
    5941void atomsCalculationTest::tearDown(){
    60   World::destroy();
    61   ActionRegistry::purgeRegistry();
     42  World::purgeInstance();
     43  ActionRegistry::purgeInstance();
    6244}
    6345
    6446// some helper functions
    65 static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){
    66   for(int i=min;i<max;++i){
    67     if(!excluded.count(i)){
    68       std::vector<int>::iterator iter;
     47static bool hasAllIds(std::vector<atomId_t> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){
     48  for(int i=0;i<ATOM_COUNT;++i){
     49    atomId_t id = ids[i];
     50    if(!excluded.count(id)){
     51      std::vector<atomId_t>::iterator iter;
    6952      bool res=false;
    70       for(iter=ids.begin();iter!=ids.end();++iter){
    71         res |= (*iter) == i;
     53      for(iter=atoms.begin();iter!=atoms.end();++iter){
     54        res |= (*iter) == id;
    7255      }
    7356      if(!res) {
    74         cout << "Atom " << i << " missing in returned list" << endl;
     57        cout << "Atom " << id << " missing in returned list" << endl;
    7558        return false;
    7659      }
     
    8063}
    8164
    82 static bool hasNoDuplicates(std::vector<int> ids){
    83   std::set<int> found;
    84   std::vector<int>::iterator iter;
     65static bool hasNoDuplicates(std::vector<atomId_t> ids){
     66  std::set<atomId_t> found;
     67  std::vector<atomId_t>::iterator iter;
    8568  for(iter=ids.begin();iter!=ids.end();++iter){
    8669    int id = (*iter);
     
    9275}
    9376
    94 static void operation(atom* _atom){
    95   AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
    96   assert(atom);
    97   atom->doSomething();
    98 }
    99 
    100 
    10177void atomsCalculationTest::testCalculateSimple(){
    102   AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
    103   std::vector<int> allIds = (*calc)();
    104   CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT));
     78  AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
     79  std::vector<atomId_t> allIds = (*calc)();
     80  CPPUNIT_ASSERT(hasAllIds(allIds,atomIds));
    10581  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    10682}
    10783
    10884void atomsCalculationTest::testCalculateExcluded(){
    109   int excluded = ATOM_COUNT/2;
    110   AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
    111   std::vector<int> allIds = (*calc)();
    112   std::set<int> excluded_set;
     85  atomId_t excluded = atomIds[ATOM_COUNT/2];
     86  AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
     87  std::vector<atomId_t> allIds = (*calc)();
     88  std::set<atomId_t> excluded_set;
    11389  excluded_set.insert(excluded);
    114   CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT,excluded_set));
     90  CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set));
    11591  CPPUNIT_ASSERT(hasNoDuplicates(allIds));
    11692  CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
  • src/unittests/atomsCalculationTest.hpp

    r9131f3 r4415da  
    1212
    1313#define ATOM_COUNT (10)
     14
     15#include "types.hpp"
    1416
    1517class atom;
     
    3133private:
    3234  atom *atoms [ATOM_COUNT];
    33   int atomIds [ATOM_COUNT];
     35  atomId_t atomIds [ATOM_COUNT];
    3436};
    3537
  • src/unittests/bondgraphunittest.cpp

    r9131f3 r4415da  
    5151  strcpy(hydrogen->symbol, "H");
    5252  carbon = new element;
    53   carbon->Z = 1;
     53  carbon->Z = 2;
    5454  strcpy(carbon->name, "carbon");
    5555  strcpy(carbon->symbol, "C");
     
    5757
    5858  // construct periodentafel
    59   tafel = World::get()->getPeriode();
     59  tafel = World::getInstance().getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161  tafel->AddElement(carbon);
    6262
    6363  // construct molecule (tetraeder of hydrogens)
    64   TestMolecule = World::get()->createMolecule();
    65   Walker = World::get()->createAtom();
     64  TestMolecule = World::getInstance().createMolecule();
     65  Walker = World::getInstance().createAtom();
    6666  Walker->type = hydrogen;
    6767  Walker->node->Init(1., 0., 1. );
    6868  TestMolecule->AddAtom(Walker);
    69   Walker = World::get()->createAtom();
     69  Walker = World::getInstance().createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(0., 1., 1. );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::get()->createAtom();
     73  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(1., 1., 0. );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::get()->createAtom();
     77  Walker = World::getInstance().createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(0., 0., 0. );
     
    102102
    103103  // remove molecule
    104   World::get()->destroyMolecule(TestMolecule);
     104  World::getInstance().destroyMolecule(TestMolecule);
    105105  // note that all the atoms, molecules, the tafel and the elements
    106106  // are all cleaned when the world is destroyed
    107   World::destroy();
     107  World::purgeInstance();
    108108  MemoryUsageObserver::purgeInstance();
    109109  logger::purgeInstance();
  • src/unittests/listofbondsunittest.cpp

    r9131f3 r4415da  
    5151
    5252  // construct periodentafel
    53   tafel = World::get()->getPeriode();
     53  tafel = World::getInstance().getPeriode();
    5454  tafel->AddElement(hydrogen);
    5555
    5656  // construct molecule (tetraeder of hydrogens)
    57   TestMolecule = World::get()->createMolecule();
    58   Walker = World::get()->createAtom();
     57  TestMolecule = World::getInstance().createMolecule();
     58  Walker = World::getInstance().createAtom();
    5959  Walker->type = hydrogen;
    6060  Walker->node->Init(1., 0., 1. );
    6161  TestMolecule->AddAtom(Walker);
    62   Walker = World::get()->createAtom();
     62  Walker = World::getInstance().createAtom();
    6363  Walker->type = hydrogen;
    6464  Walker->node->Init(0., 1., 1. );
    6565  TestMolecule->AddAtom(Walker);
    66   Walker = World::get()->createAtom();
     66  Walker = World::getInstance().createAtom();
    6767  Walker->type = hydrogen;
    6868  Walker->node->Init(1., 1., 0. );
    6969  TestMolecule->AddAtom(Walker);
    70   Walker = World::get()->createAtom();
     70  Walker = World::getInstance().createAtom();
    7171  Walker->type = hydrogen;
    7272  Walker->node->Init(0., 0., 0. );
     
    8282{
    8383  // remove
    84   World::get()->destroyMolecule(TestMolecule);
     84  World::getInstance().destroyMolecule(TestMolecule);
    8585  // note that all the atoms, molecules, the tafel and the elements
    8686  // are all cleaned when the world is destroyed
    87   World::destroy();
     87  World::purgeInstance();
    8888  MemoryUsageObserver::purgeInstance();
    8989  logger::purgeInstance();
     
    250250
    251251  // remove atom2
    252   World::get()->destroyAtom(atom2);
     252  World::getInstance().destroyAtom(atom2);
    253253
    254254  // check bond if removed from other atom
  • src/unittests/logunittest.cpp

    r9131f3 r4415da  
    4040void LogTest::logTest()
    4141{
    42   logger::getInstance()->setVerbosity(2);
     42  logger::getInstance().setVerbosity(2);
    4343  Log() << Verbose(0) << "Verbosity level is set to 2." << endl;
    4444  Log() << Verbose(0) << "Test level 0" << endl;
  • src/unittests/manipulateAtomsTest.cpp

    r9131f3 r4415da  
    1818#include "Actions/ManipulateAtomsProcess.hpp"
    1919#include "Actions/ActionRegistry.hpp"
     20#include "Actions/ActionHistory.hpp"
    2021
    2122#include "World.hpp"
    2223#include "atom.hpp"
     24
     25#ifdef HAVE_TESTRUNNER
     26#include "UnitTestMain.hpp"
     27#endif /*HAVE_TESTRUNNER*/
    2328
    2429// Registers the fixture into the 'registry'
     
    3035  AtomStub(int _id) :
    3136  atom(),
    32   id(_id),
    33   manipulated(false)
     37  manipulated(false),
     38  id(_id)
    3439  {}
    3540
     
    6671// set up and tear down
    6772void manipulateAtomsTest::setUp(){
    68   World::get();
     73  ActionHistory::init();
     74  World::getInstance();
    6975  for(int i=0;i<ATOM_COUNT;++i){
    7076    atoms[i]= new AtomStub(i);
    71     World::get()->registerAtom(atoms[i]);
     77    World::getInstance().registerAtom(atoms[i]);
    7278  }
    7379}
    7480void manipulateAtomsTest::tearDown(){
    75   World::destroy();
    76   ActionRegistry::purgeRegistry();
    77 }
    78 
    79 // some helper functions
    80 static bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
    81   for(int i=min;i<max;++i){
    82     if(!excluded.count(i)){
    83       std::vector<atom*>::iterator iter;
    84       bool res=false;
    85       for(iter=atoms.begin();iter!=atoms.end();++iter){
    86         res |= (*iter)->getId() == i;
    87       }
    88       if(!res) {
    89         cout << "Atom " << i << " missing in returned list" << endl;
    90         return false;
    91       }
    92     }
    93   }
    94   return true;
    95 }
    96 
    97 static bool hasNoDuplicates(std::vector<atom*> atoms){
    98   std::set<int> found;
    99   std::vector<atom*>::iterator iter;
    100   for(iter=atoms.begin();iter!=atoms.end();++iter){
    101     int id = (*iter)->getId();
    102     if(found.count(id))
    103       return false;
    104     found.insert(id);
    105   }
    106   return true;
     81  World::purgeInstance();
     82  ActionRegistry::purgeInstance();
     83  ActionHistory::purgeInstance();
    10784}
    10885
     
    11592
    11693void manipulateAtomsTest::testManipulateSimple(){
    117   ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
     94  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
    11895  proc->call();
    119   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     96  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    12097  std::vector<atom*>::iterator iter;
    12198  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    128105
    129106void manipulateAtomsTest::testManipulateExcluded(){
    130   ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     107
     108  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
    131109  proc->call();
    132   std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
     110  std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
    133111  std::vector<atom*>::iterator iter;
    134112  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    145123void manipulateAtomsTest::testObserver(){
    146124  countObserver *obs = new countObserver();
    147   World::get()->signOn(obs);
    148   ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     125  World::getInstance().signOn(obs);
     126  ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
    149127  proc->call();
    150128
    151129  CPPUNIT_ASSERT_EQUAL(1,obs->count);
    152   World::get()->signOff(obs);
     130  World::getInstance().signOff(obs);
    153131  delete obs;
    154132}
Note: See TracChangeset for help on using the changeset viewer.