Changeset 4415da for src/unittests
- Timestamp:
- Apr 1, 2010, 12:16:29 PM (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:
- 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. - Location:
- src/unittests
- Files:
-
- 2 added
- 20 edited
-
ActionSequenceTest.cpp (modified) (4 diffs)
-
AnalysisCorrelationToPointUnitTest.cpp (modified) (3 diffs)
-
AnalysisCorrelationToSurfaceUnitTest.cpp (modified) (6 diffs)
-
AnalysisPairCorrelationUnitTest.cpp (modified) (3 diffs)
-
AtomDescriptorTest.cpp (modified) (9 diffs)
-
AtomDescriptorTest.hpp (modified) (1 diff)
-
CacheableTest.cpp (modified) (2 diffs)
-
Makefile.am (modified) (5 diffs)
-
MoleculeDescriptorTest.cpp (modified) (10 diffs)
-
MoleculeDescriptorTest.hpp (modified) (1 diff)
-
ObserverTest.cpp (modified) (6 diffs)
-
ObserverTest.hpp (modified) (4 diffs)
-
ParserUnitTest.cpp (modified) (3 diffs)
-
SingletonTest.cpp (added)
-
SingletonTest.hpp (added)
-
analysisbondsunittest.cpp (modified) (3 diffs)
-
atomsCalculationTest.cpp (modified) (3 diffs)
-
atomsCalculationTest.hpp (modified) (2 diffs)
-
bondgraphunittest.cpp (modified) (3 diffs)
-
listofbondsunittest.cpp (modified) (3 diffs)
-
logunittest.cpp (modified) (1 diff)
-
manipulateAtomsTest.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/ActionSequenceTest.cpp
r9131f3 r4415da 35 35 virtual ~canUndoActionStub(){} 36 36 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 } 39 46 virtual bool canUndo(){ 47 return true; 48 } 49 virtual bool shouldUndo(){ 40 50 return true; 41 51 } … … 48 58 virtual ~cannotUndoActionStub(){} 49 59 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 } 52 69 virtual bool canUndo(){ 53 70 return false; 71 } 72 virtual bool shouldUndo(){ 73 return true; 54 74 } 55 75 }; … … 64 84 virtual ~wasCalledActionStub(){} 65 85 66 virtual void call(){86 virtual Action::state_ptr performCall(){ 67 87 called = true; 68 } 69 virtual void undo(){ 88 return Action::success; 89 } 90 virtual Action::state_ptr performUndo(Action::state_ptr){ 70 91 called = false; 92 return Action::success; 93 } 94 virtual Action::state_ptr performRedo(Action::state_ptr){ 95 called = true; 96 return Action::success; 71 97 } 72 98 virtual bool canUndo(){ 99 return true; 100 } 101 virtual bool shouldUndo(){ 73 102 return true; 74 103 } … … 185 214 sequence->addAction(shouldCall2); 186 215 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); 193 222 194 223 CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled()); -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r9131f3 r4415da 57 57 58 58 // construct periodentafel 59 tafel = World::get ()->getPeriode();59 tafel = World::getInstance().getPeriode(); 60 60 tafel->AddElement(hydrogen); 61 61 62 62 // 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(); 65 65 Walker->type = hydrogen; 66 66 Walker->node->Init(1., 0., 1. ); 67 67 TestMolecule->AddAtom(Walker); 68 Walker = World::get ()->createAtom();68 Walker = World::getInstance().createAtom(); 69 69 Walker->type = hydrogen; 70 70 Walker->node->Init(0., 1., 1. ); 71 71 TestMolecule->AddAtom(Walker); 72 Walker = World::get ()->createAtom();72 Walker = World::getInstance().createAtom(); 73 73 Walker->type = hydrogen; 74 74 Walker->node->Init(1., 1., 0. ); 75 75 TestMolecule->AddAtom(Walker); 76 Walker = World::get ()->createAtom();76 Walker = World::getInstance().createAtom(); 77 77 Walker->type = hydrogen; 78 78 Walker->node->Init(0., 0., 0. ); … … 82 82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 83 83 84 TestList = World::get ()->getMolecules();84 TestList = World::getInstance().getMolecules(); 85 85 TestMolecule->ActiveFlag = true; 86 86 TestList->insert(TestMolecule); … … 104 104 105 105 delete(point); 106 World:: destroy();106 World::purgeInstance(); 107 107 MemoryUsageObserver::purgeInstance(); 108 108 logger::purgeInstance(); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r9131f3 r4415da 27 27 #include "World.hpp" 28 28 29 #include "Helpers/Assert.hpp" 30 29 31 #ifdef HAVE_TESTRUNNER 30 32 #include "UnitTestMain.hpp" … … 38 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 39 41 { 42 ASSERT_DO(Assert::Throw); 43 40 44 atom *Walker = NULL; 41 45 … … 61 65 62 66 // construct periodentafel 63 tafel = World::get ()->getPeriode();67 tafel = World::getInstance().getPeriode(); 64 68 tafel->AddElement(hydrogen); 65 69 tafel->AddElement(carbon); 66 70 67 71 // 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(); 70 74 Walker->type = hydrogen; 71 75 Walker->node->Init(1., 0., 1. ); 72 76 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 74 78 Walker->type = hydrogen; 75 79 Walker->node->Init(0., 1., 1. ); 76 80 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();81 Walker = World::getInstance().createAtom(); 78 82 Walker->type = hydrogen; 79 83 Walker->node->Init(1., 1., 0. ); 80 84 TestMolecule->AddAtom(Walker); 81 Walker = World::get ()->createAtom();85 Walker = World::getInstance().createAtom(); 82 86 Walker->type = hydrogen; 83 87 Walker->node->Init(0., 0., 0. ); … … 87 91 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 88 92 89 TestList = World::get ()->getMolecules();93 TestList = World::getInstance().getMolecules(); 90 94 TestMolecule->ActiveFlag = true; 91 95 TestList->insert(TestMolecule); … … 100 104 101 105 // add outer atoms 102 Walker = World::get ()->createAtom();106 Walker = World::getInstance().createAtom(); 103 107 Walker->type = carbon; 104 108 Walker->node->Init(4., 0., 4. ); 105 109 TestMolecule->AddAtom(Walker); 106 Walker = World::get ()->createAtom();110 Walker = World::getInstance().createAtom(); 107 111 Walker->type = carbon; 108 112 Walker->node->Init(0., 4., 4. ); 109 113 TestMolecule->AddAtom(Walker); 110 Walker = World::get ()->createAtom();114 Walker = World::getInstance().createAtom(); 111 115 Walker->type = carbon; 112 116 Walker->node->Init(4., 4., 0. ); 113 117 TestMolecule->AddAtom(Walker); 114 118 // add inner atoms 115 Walker = World::get ()->createAtom();119 Walker = World::getInstance().createAtom(); 116 120 Walker->type = carbon; 117 121 Walker->node->Init(0.5, 0.5, 0.5 ); … … 135 139 // note that all the atoms are cleaned by TestMolecule 136 140 delete(LC); 137 World:: destroy();141 World::purgeInstance(); 138 142 MemoryUsageObserver::purgeInstance(); 139 143 logger::purgeInstance(); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r9131f3 r4415da 56 56 57 57 // construct periodentafel 58 tafel = World::get ()->getPeriode();58 tafel = World::getInstance().getPeriode(); 59 59 tafel->AddElement(hydrogen); 60 60 61 61 // 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(); 64 64 Walker->type = hydrogen; 65 65 Walker->node->Init(1., 0., 1. ); 66 66 TestMolecule->AddAtom(Walker); 67 Walker = World::get ()->createAtom();67 Walker = World::getInstance().createAtom(); 68 68 Walker->type = hydrogen; 69 69 Walker->node->Init(0., 1., 1. ); 70 70 TestMolecule->AddAtom(Walker); 71 Walker = World::get ()->createAtom();71 Walker = World::getInstance().createAtom(); 72 72 Walker->type = hydrogen; 73 73 Walker->node->Init(1., 1., 0. ); 74 74 TestMolecule->AddAtom(Walker); 75 Walker = World::get ()->createAtom();75 Walker = World::getInstance().createAtom(); 76 76 Walker->type = hydrogen; 77 77 Walker->node->Init(0., 0., 0. ); … … 81 81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 82 82 83 TestList = World::get ()->getMolecules();83 TestList = World::getInstance().getMolecules(); 84 84 TestMolecule->ActiveFlag = true; 85 85 TestList->insert(TestMolecule); … … 100 100 101 101 // note that all the atoms are cleaned by TestMolecule 102 World:: destroy();102 World::purgeInstance(); 103 103 MemoryUsageObserver::purgeInstance(); 104 104 logger::purgeInstance(); -
src/unittests/AtomDescriptorTest.cpp
r9131f3 r4415da 29 29 // set up and tear down 30 30 void AtomDescriptorTest::setUp(){ 31 World::get ();31 World::getInstance(); 32 32 for(int i=0;i<ATOM_COUNT;++i){ 33 atoms[i]= World::get ()->createAtom();33 atoms[i]= World::getInstance().createAtom(); 34 34 atomIds[i]= atoms[i]->getId(); 35 35 } … … 37 37 38 38 void AtomDescriptorTest::tearDown(){ 39 World:: destroy();39 World::purgeInstance(); 40 40 } 41 41 … … 73 73 74 74 void AtomDescriptorTest::AtomBaseSetsTest(){ 75 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());75 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 76 76 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds)); 77 77 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms)); 78 78 79 std::vector<atom*> noAtoms = World::get ()->getAllAtoms(NoAtoms());79 std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms()); 80 80 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty()); 81 81 } … … 83 83 // test Atoms from boundaries and middle of the set 84 84 atom* testAtom; 85 testAtom = World::get ()->getAtom(AtomById(atomIds[0]));85 testAtom = World::getInstance().getAtom(AtomById(atomIds[0])); 86 86 CPPUNIT_ASSERT(testAtom); 87 87 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])); 89 89 CPPUNIT_ASSERT(testAtom); 90 90 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])); 92 92 CPPUNIT_ASSERT(testAtom); 93 93 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); … … 103 103 } 104 104 // test from outside of set 105 testAtom = World::get ()->getAtom(AtomById(outsideId));105 testAtom = World::getInstance().getAtom(AtomById(outsideId)); 106 106 CPPUNIT_ASSERT(!testAtom); 107 107 } … … 109 109 // test some elementary set operations 110 110 { 111 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()||NoAtoms());111 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms()); 112 112 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 113 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); … … 115 115 116 116 { 117 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()||AllAtoms());117 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms()); 118 118 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 119 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); … … 121 121 122 122 { 123 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(NoAtoms()&&AllAtoms());123 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms()); 124 124 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 125 125 } 126 126 127 127 { 128 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(AllAtoms()&&NoAtoms());128 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms()); 129 129 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 130 130 } 131 131 132 132 { 133 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(!AllAtoms());133 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms()); 134 134 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty()); 135 135 } 136 136 137 137 { 138 std::vector<atom*> testAtoms = World::get ()->getAllAtoms(!NoAtoms());138 std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms()); 139 139 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 140 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); 141 141 } 142 143 142 // exclude and include some atoms 144 143 { 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]))); 146 145 std::set<atomId_t> excluded; 147 146 excluded.insert(atomIds[ATOM_COUNT/2]); … … 152 151 153 152 { 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]))); 155 154 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 156 155 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); -
src/unittests/AtomDescriptorTest.hpp
r9131f3 r4415da 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define ATOM_COUNT (10) -
src/unittests/CacheableTest.cpp
r9131f3 r4415da 27 27 class threeNumbers : public Observable { 28 28 public: 29 bool hasRecalced;30 29 int x; 31 30 int y; 32 31 int z; 32 Cacheable<int> sum; 33 bool hasRecalced; 33 34 34 35 void setX(int _x){ … … 54 55 55 56 threeNumbers(int _x,int _y, int _z) : 57 x(_x),y(_y),z(_z), 56 58 sum(this,boost::bind(&threeNumbers::calcSum,this)), 57 x(_x),y(_y),z(_z),58 59 hasRecalced(false) 59 60 {} 60 61 Cacheable<int> sum;62 61 }; 63 62 -
src/unittests/Makefile.am
r9131f3 r4415da 29 29 ObserverTest \ 30 30 ParserUnitTest \ 31 SingletonTest \ 31 32 StackClassUnitTest \ 32 33 TesselationUnitTest \ … … 68 69 ObserverTest.cpp \ 69 70 ParserUnitTest.cpp \ 71 SingletonTest.cpp \ 70 72 stackclassunittest.cpp \ 71 73 tesselationunittest.cpp \ … … 91 93 AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp 92 94 AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS} 95 96 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp 97 atomsCalculationTest_LDADD = ${ALLLIBS} 93 98 94 99 BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp … … 125 130 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 126 131 132 SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp 133 SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB} 134 127 135 StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp 128 136 StackClassUnitTest_LDADD = ${ALLLIBS} … … 158 166 manipulateAtomsTest_LDADD = ${ALLLIBS} 159 167 160 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp161 atomsCalculationTest_LDADD = ${ALLLIBS}162 163 168 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS) 164 169 TestRunner_LDADD = ${ALLLIBS} -
src/unittests/MoleculeDescriptorTest.cpp
r9131f3 r4415da 29 29 // set up and tear down 30 30 void MoleculeDescriptorTest::setUp(){ 31 World::get ();31 World::getInstance(); 32 32 for(int i=0;i<MOLECULE_COUNT;++i){ 33 molecules[i]= World::get ()->createMolecule();33 molecules[i]= World::getInstance().createMolecule(); 34 34 moleculeIds[i]= molecules[i]->getId(); 35 35 } … … 37 37 38 38 void MoleculeDescriptorTest::tearDown(){ 39 World:: destroy();39 World::purgeInstance(); 40 40 } 41 41 … … 73 73 74 74 void MoleculeDescriptorTest::MoleculeBaseSetsTest(){ 75 std::vector<molecule*> allMolecules = World::get ()->getAllMolecules(AllMolecules());75 std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules()); 76 76 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds)); 77 77 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules)); 78 78 79 std::vector<molecule*> noMolecules = World::get ()->getAllMolecules(NoMolecules());79 std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules()); 80 80 CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty()); 81 81 } … … 83 83 // test Molecules from boundaries and middle of the set 84 84 molecule* testMolecule; 85 testMolecule = World::get ()->getMolecule(MoleculeById(moleculeIds[0]));85 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0])); 86 86 CPPUNIT_ASSERT(testMolecule); 87 87 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])); 89 89 CPPUNIT_ASSERT(testMolecule); 90 90 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])); 92 92 CPPUNIT_ASSERT(testMolecule); 93 93 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId()); … … 103 103 } 104 104 // test from outside of set 105 testMolecule = World::get ()->getMolecule(MoleculeById(outsideId));105 testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId)); 106 106 CPPUNIT_ASSERT(!testMolecule); 107 107 } … … 109 109 // test some elementary set operations 110 110 { 111 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(AllMolecules()||NoMolecules());111 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules()); 112 112 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 113 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 115 115 116 116 { 117 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(NoMolecules()||AllMolecules());117 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules()); 118 118 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 119 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 121 121 122 122 { 123 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(NoMolecules()&&AllMolecules());123 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules()); 124 124 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 125 125 } 126 126 127 127 { 128 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(AllMolecules()&&NoMolecules());128 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules()); 129 129 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 130 130 } 131 131 132 132 { 133 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(!AllMolecules());133 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules()); 134 134 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty()); 135 135 } 136 136 137 137 { 138 std::vector<molecule*> testMolecules = World::get ()->getAllMolecules(!NoMolecules());138 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules()); 139 139 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds)); 140 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules)); … … 143 143 // exclude and include some molecules 144 144 { 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]))); 146 146 std::set<moleculeId_t> excluded; 147 147 excluded.insert(moleculeIds[MOLECULE_COUNT/2]); … … 152 152 153 153 { 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]))); 155 155 CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size()); 156 156 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId()); -
src/unittests/MoleculeDescriptorTest.hpp
r9131f3 r4415da 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include " defs.hpp"13 #include "types.hpp" 14 14 15 15 #define MOLECULE_COUNT (10) -
src/unittests/ObserverTest.cpp
r9131f3 r4415da 13 13 14 14 #include "Patterns/Observer.hpp" 15 #include "Helpers/Assert.hpp" 15 16 16 17 #include <iostream> … … 65 66 }; 66 67 68 class BlockObservable : public Observable { 69 public: 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 67 102 class SuperObservable : public Observable { 68 103 public: … … 86 121 87 122 void ObserverTest::setUp() { 123 ASSERT_DO(Assert::Throw); 88 124 simpleObservable1 = new SimpleObservable(); 89 125 simpleObservable2 = new SimpleObservable(); 90 126 callObservable = new CallObservable(); 91 127 superObservable = new SuperObservable(); 128 blockObservable = new BlockObservable(); 92 129 93 130 observer1 = new UpdateCountObserver(); … … 163 200 } 164 201 202 void ObserverTest::doesReportTest(){ 203 // Actual checks are in the Stub-methods for this 204 blockObservable->changeMethod1(); 205 blockObservable->changeMethod2(); 206 blockObservable->noChangeMethod(); 207 } 165 208 166 209 void ObserverTest::CircleDetectionTest() { … … 174 217 // make this Observable its own subject. NEVER DO THIS IN ACTUAL CODE 175 218 simpleObservable1->signOn(simpleObservable1); 176 simpleObservable1->changeMethod();219 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 177 220 178 221 // more complex test … … 180 223 simpleObservable1->signOn(simpleObservable2); 181 224 simpleObservable2->signOn(simpleObservable1); 182 simpleObservable1->changeMethod();225 CPPUNIT_ASSERT_THROW(simpleObservable1->changeMethod(),Assert::AssertionFailure); 183 226 simpleObservable1->signOff(simpleObservable2); 184 227 simpleObservable2->signOff(simpleObservable1); -
src/unittests/ObserverTest.hpp
r9131f3 r4415da 16 16 class CallObservable; 17 17 class SuperObservable; 18 class BlockObservable; 18 19 19 20 … … 24 25 CPPUNIT_TEST ( doesBlockUpdateTest ); 25 26 CPPUNIT_TEST ( doesSubObservableTest ); 27 CPPUNIT_TEST ( doesReportTest ); 26 28 CPPUNIT_TEST ( CircleDetectionTest ); 27 29 CPPUNIT_TEST_SUITE_END(); … … 34 36 void doesBlockUpdateTest(); 35 37 void doesSubObservableTest(); 38 void doesReportTest(); 36 39 void CircleDetectionTest(); 37 40 … … 45 48 SimpleObservable *simpleObservable2; 46 49 CallObservable *callObservable; 50 BlockObservable *blockObservable; 47 51 SuperObservable *superObservable; 48 52 }; -
src/unittests/ParserUnitTest.cpp
r9131f3 r4415da 32 32 oxygen->symbol[0] = 'O'; 33 33 oxygen->Z = 8; 34 World::get ()->getPeriode()->AddElement(oxygen);34 World::getInstance().getPeriode()->AddElement(oxygen); 35 35 36 36 element* hydrogen = new element(); 37 37 hydrogen->symbol[0] = 'H'; 38 38 hydrogen->Z = 1; 39 World::get ()->getPeriode()->AddElement(hydrogen);39 World::getInstance().getPeriode()->AddElement(hydrogen); 40 40 } 41 41 … … 53 53 testParser->load(&input); 54 54 55 CPPUNIT_ASSERT_EQUAL(3, World::get ()->numAtoms());55 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 56 56 57 57 string newWaterXyz = ""; … … 66 66 cout << "Testing the tremolo parser." << endl; 67 67 TremoloParser* testParser = new TremoloParser(); 68 stringstream input; 69 70 // Atomdata beginning with "# ATOMDATA" 68 71 string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n"; 69 stringstream input;70 72 input << waterTremolo; 71 73 testParser->load(&input); 74 input.clear(); 75 76 // Atomdata beginning with "#ATOMDATA" 72 77 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n"; 73 input.clear();74 78 input << waterTremolo; 75 79 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 76 94 cout << "testing the tremolo parser is done" << endl; 77 95 } -
src/unittests/analysisbondsunittest.cpp
r9131f3 r4415da 53 53 strcpy(hydrogen->symbol, "H"); 54 54 carbon = new element; 55 carbon->Z = 1;55 carbon->Z = 2; 56 56 carbon->Valence = 4; 57 57 carbon->NoValenceOrbitals = 4; … … 61 61 62 62 // construct periodentafel 63 tafel = World::get ()->getPeriode();63 tafel = World::getInstance().getPeriode(); 64 64 tafel->AddElement(hydrogen); 65 65 tafel->AddElement(carbon); 66 66 67 67 // 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(); 70 70 Walker->type = hydrogen; 71 71 Walker->node->Init(1.5, 0., 1.5 ); 72 72 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 75 Walker->node->Init(0., 1.5, 1.5 ); 76 76 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 79 Walker->node->Init(1.5, 1.5, 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 Walker = World::get ()->createAtom();81 Walker = World::getInstance().createAtom(); 82 82 Walker->type = hydrogen; 83 83 Walker->node->Init(0., 0., 0. ); 84 84 TestMolecule->AddAtom(Walker); 85 Walker = World::get ()->createAtom();85 Walker = World::getInstance().createAtom(); 86 86 Walker->type = carbon; 87 87 Walker->node->Init(0.5, 0.5, 0.5 ); … … 117 117 118 118 // remove molecule 119 World::get ()->destroyMolecule(TestMolecule);119 World::getInstance().destroyMolecule(TestMolecule); 120 120 // note that all the atoms are cleaned by TestMolecule 121 World:: destroy();121 World::purgeInstance(); 122 122 }; 123 123 -
src/unittests/atomsCalculationTest.cpp
r9131f3 r4415da 24 24 #include "atom.hpp" 25 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 29 26 30 // Registers the fixture into the 'registry' 27 31 CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest ); 28 32 29 // some stubs30 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 51 33 // set up and tear down 52 34 void atomsCalculationTest::setUp(){ 53 World::get ();35 World::getInstance(); 54 36 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(); 57 39 } 58 40 } 59 41 void atomsCalculationTest::tearDown(){ 60 World:: destroy();61 ActionRegistry::purge Registry();42 World::purgeInstance(); 43 ActionRegistry::purgeInstance(); 62 44 } 63 45 64 46 // 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; 47 static 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; 69 52 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; 72 55 } 73 56 if(!res) { 74 cout << "Atom " << i << " missing in returned list" << endl;57 cout << "Atom " << id << " missing in returned list" << endl; 75 58 return false; 76 59 } … … 80 63 } 81 64 82 static bool hasNoDuplicates(std::vector< int> ids){83 std::set< int> found;84 std::vector< int>::iterator iter;65 static bool hasNoDuplicates(std::vector<atomId_t> ids){ 66 std::set<atomId_t> found; 67 std::vector<atomId_t>::iterator iter; 85 68 for(iter=ids.begin();iter!=ids.end();++iter){ 86 69 int id = (*iter); … … 92 75 } 93 76 94 static void operation(atom* _atom){95 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);96 assert(atom);97 atom->doSomething();98 }99 100 101 77 void 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)); 105 81 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 106 82 } 107 83 108 84 void 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; 113 89 excluded_set.insert(excluded); 114 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT,excluded_set));90 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set)); 115 91 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 116 92 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size()); -
src/unittests/atomsCalculationTest.hpp
r9131f3 r4415da 12 12 13 13 #define ATOM_COUNT (10) 14 15 #include "types.hpp" 14 16 15 17 class atom; … … 31 33 private: 32 34 atom *atoms [ATOM_COUNT]; 33 int atomIds [ATOM_COUNT];35 atomId_t atomIds [ATOM_COUNT]; 34 36 }; 35 37 -
src/unittests/bondgraphunittest.cpp
r9131f3 r4415da 51 51 strcpy(hydrogen->symbol, "H"); 52 52 carbon = new element; 53 carbon->Z = 1;53 carbon->Z = 2; 54 54 strcpy(carbon->name, "carbon"); 55 55 strcpy(carbon->symbol, "C"); … … 57 57 58 58 // construct periodentafel 59 tafel = World::get ()->getPeriode();59 tafel = World::getInstance().getPeriode(); 60 60 tafel->AddElement(hydrogen); 61 61 tafel->AddElement(carbon); 62 62 63 63 // 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(); 66 66 Walker->type = hydrogen; 67 67 Walker->node->Init(1., 0., 1. ); 68 68 TestMolecule->AddAtom(Walker); 69 Walker = World::get ()->createAtom();69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 71 Walker->node->Init(0., 1., 1. ); 72 72 TestMolecule->AddAtom(Walker); 73 Walker = World::get ()->createAtom();73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 75 Walker->node->Init(1., 1., 0. ); 76 76 TestMolecule->AddAtom(Walker); 77 Walker = World::get ()->createAtom();77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 79 Walker->node->Init(0., 0., 0. ); … … 102 102 103 103 // remove molecule 104 World::get ()->destroyMolecule(TestMolecule);104 World::getInstance().destroyMolecule(TestMolecule); 105 105 // note that all the atoms, molecules, the tafel and the elements 106 106 // are all cleaned when the world is destroyed 107 World:: destroy();107 World::purgeInstance(); 108 108 MemoryUsageObserver::purgeInstance(); 109 109 logger::purgeInstance(); -
src/unittests/listofbondsunittest.cpp
r9131f3 r4415da 51 51 52 52 // construct periodentafel 53 tafel = World::get ()->getPeriode();53 tafel = World::getInstance().getPeriode(); 54 54 tafel->AddElement(hydrogen); 55 55 56 56 // 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(); 59 59 Walker->type = hydrogen; 60 60 Walker->node->Init(1., 0., 1. ); 61 61 TestMolecule->AddAtom(Walker); 62 Walker = World::get ()->createAtom();62 Walker = World::getInstance().createAtom(); 63 63 Walker->type = hydrogen; 64 64 Walker->node->Init(0., 1., 1. ); 65 65 TestMolecule->AddAtom(Walker); 66 Walker = World::get ()->createAtom();66 Walker = World::getInstance().createAtom(); 67 67 Walker->type = hydrogen; 68 68 Walker->node->Init(1., 1., 0. ); 69 69 TestMolecule->AddAtom(Walker); 70 Walker = World::get ()->createAtom();70 Walker = World::getInstance().createAtom(); 71 71 Walker->type = hydrogen; 72 72 Walker->node->Init(0., 0., 0. ); … … 82 82 { 83 83 // remove 84 World::get ()->destroyMolecule(TestMolecule);84 World::getInstance().destroyMolecule(TestMolecule); 85 85 // note that all the atoms, molecules, the tafel and the elements 86 86 // are all cleaned when the world is destroyed 87 World:: destroy();87 World::purgeInstance(); 88 88 MemoryUsageObserver::purgeInstance(); 89 89 logger::purgeInstance(); … … 250 250 251 251 // remove atom2 252 World::get ()->destroyAtom(atom2);252 World::getInstance().destroyAtom(atom2); 253 253 254 254 // check bond if removed from other atom -
src/unittests/logunittest.cpp
r9131f3 r4415da 40 40 void LogTest::logTest() 41 41 { 42 logger::getInstance() ->setVerbosity(2);42 logger::getInstance().setVerbosity(2); 43 43 Log() << Verbose(0) << "Verbosity level is set to 2." << endl; 44 44 Log() << Verbose(0) << "Test level 0" << endl; -
src/unittests/manipulateAtomsTest.cpp
r9131f3 r4415da 18 18 #include "Actions/ManipulateAtomsProcess.hpp" 19 19 #include "Actions/ActionRegistry.hpp" 20 #include "Actions/ActionHistory.hpp" 20 21 21 22 #include "World.hpp" 22 23 #include "atom.hpp" 24 25 #ifdef HAVE_TESTRUNNER 26 #include "UnitTestMain.hpp" 27 #endif /*HAVE_TESTRUNNER*/ 23 28 24 29 // Registers the fixture into the 'registry' … … 30 35 AtomStub(int _id) : 31 36 atom(), 32 id(_id),33 manipulated(false)37 manipulated(false), 38 id(_id) 34 39 {} 35 40 … … 66 71 // set up and tear down 67 72 void manipulateAtomsTest::setUp(){ 68 World::get(); 73 ActionHistory::init(); 74 World::getInstance(); 69 75 for(int i=0;i<ATOM_COUNT;++i){ 70 76 atoms[i]= new AtomStub(i); 71 World::get ()->registerAtom(atoms[i]);77 World::getInstance().registerAtom(atoms[i]); 72 78 } 73 79 } 74 80 void 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(); 107 84 } 108 85 … … 115 92 116 93 void 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()); 118 95 proc->call(); 119 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());96 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 120 97 std::vector<atom*>::iterator iter; 121 98 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 128 105 129 106 void 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)); 131 109 proc->call(); 132 std::vector<atom*> allAtoms = World::get ()->getAllAtoms(AllAtoms());110 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms()); 133 111 std::vector<atom*>::iterator iter; 134 112 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){ … … 145 123 void manipulateAtomsTest::testObserver(){ 146 124 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()); 149 127 proc->call(); 150 128 151 129 CPPUNIT_ASSERT_EQUAL(1,obs->count); 152 World::get ()->signOff(obs);130 World::getInstance().signOff(obs); 153 131 delete obs; 154 132 }
Note:
See TracChangeset
for help on using the changeset viewer.
