source: src/Fragmentation/Automation/unittests/FragmentQueueUnitTest.cpp@ f0834d

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since f0834d was 78ad7d, checked in by Frederik Heber <heber@…>, 13 years ago

FragmentJob is now passed inside boost::shared_ptr.

  • FragmentJob is to become just an abstract interface to a variety of jobs and we cannot instantiate this interface. We can only pass it around via ptrs. Therefore, we need this switch to shared_ptrs.
  • We now require CodePatterns 1.2.2 due to boost/archive/iserializer.hpp fix.
  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[b5ebb5]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * FragmentQueueUnitTest.cpp
10 *
11 * Created on: Oct 23, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include "FragmentQueueUnitTest.hpp"
25
[9875cc]26#include <vector>
27
[02f346]28#include "CodePatterns/Assert.hpp"
[9875cc]29#include "FragmentQueue.hpp"
30
[02f346]31
[b5ebb5]32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36/********************************************** Test classes **************************************/
37
38// Registers the fixture into the 'registry'
39CPPUNIT_TEST_SUITE_REGISTRATION( FragmentQueueTest );
40
41
42void FragmentQueueTest::setUp()
43{
[02f346]44 // Throw assertions
45 ASSERT_DO(Assert::Throw);
46
[b5ebb5]47 queue = new FragmentQueue();
48}
49
50
51void FragmentQueueTest::tearDown()
52{
53 delete queue;
54}
55
56/** UnitTest for working JobQueue
57 */
[9875cc]58void FragmentQueueTest::JobTest()
[b5ebb5]59{
[78ad7d]60 FragmentJob::ptr testJob(new FragmentJob);
[02f346]61 /// check for illegal id
62#ifndef NDEBUG
63 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
64 CPPUNIT_ASSERT_THROW( queue->pushJob(testJob), Assert::AssertionFailure );
65#endif
66 // set to valid id
[78ad7d]67 testJob->setId(1);
68 testJob->outputfile = std::string("do something");
[02f346]69
[12d15a]70 CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
71
[02f346]72#ifndef NDEBUG
73 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
74#else
75 queue->pushJob(testJob);
76#endif
77
78 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
[12d15a]79 CPPUNIT_ASSERT_EQUAL(true, queue->isJobPresent() );
80 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
[9875cc]81 {
82 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
83 CPPUNIT_ASSERT( iter != queue->results.end() );
84 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
85 }
[02f346]86
87 // push same id again
88#ifndef NDEBUG
89 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
90 CPPUNIT_ASSERT_THROW( queue->pushJob(testJob), Assert::AssertionFailure );
91#endif
92
93 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
[12d15a]94 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
95
[78ad7d]96 FragmentJob::ptr poppedJob;
[12d15a]97#ifndef NDEBUG
98 CPPUNIT_ASSERT_NO_THROW( poppedJob = queue->popJob() );
99#else
100 poppedJob = queue->popJob();
101#endif
102 CPPUNIT_ASSERT( poppedJob == testJob );
103
104 CPPUNIT_ASSERT_EQUAL((size_t)0, queue->jobs.size());
105 CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
106 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
[9875cc]107 {
108 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
109 CPPUNIT_ASSERT( iter != queue->results.end() );
110 CPPUNIT_ASSERT( FragmentQueue::NoResultQueued == iter->second );
111 }
[12d15a]112
113#ifndef NDEBUG
114 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
115 CPPUNIT_ASSERT_THROW( queue->popJob(), Assert::AssertionFailure );
116#endif
[b5ebb5]117}
118
[9875cc]119/** UnitTest for adding multiple jobs at a time.
120 */
121void FragmentQueueTest::JobsTest()
122{
123 // prepare some jobs
[78ad7d]124 FragmentJob::ptr testJob(new FragmentJob);
125 testJob->setId((JobId_t)1);
126 testJob->outputfile = std::string("do something");
127 FragmentJob::ptr anothertestJob(new FragmentJob);
128 anothertestJob->setId((JobId_t)2);
129 anothertestJob->outputfile = std::string("do something else");
[9875cc]130
131 // prepare a vector of them
[78ad7d]132 std::vector<FragmentJob::ptr> testjobs;
[9875cc]133 testjobs.push_back(testJob);
134 testjobs.push_back(anothertestJob);
135
136 // prepare another vector of them
[78ad7d]137 std::vector<FragmentJob::ptr> sametestjobs;
[9875cc]138 sametestjobs.push_back(testJob);
139 sametestjobs.push_back(anothertestJob);
140
141 // push the vector
142 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->jobs.size() );
143#ifndef NDEBUG
144 CPPUNIT_ASSERT_NO_THROW( queue->pushJobs(testjobs) );
145#else
146 queue->pushJobs(testjobs);
147#endif
148 CPPUNIT_ASSERT_EQUAL( (size_t)2, queue->jobs.size() );
149 CPPUNIT_ASSERT_EQUAL((size_t)2, queue->results.size());
150 {
151 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
152 CPPUNIT_ASSERT( iter != queue->results.end() );
153 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
154 }
155 {
156 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)2);
157 CPPUNIT_ASSERT( iter != queue->results.end() );
158 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
159 }
160 // push again
161#ifndef NDEBUG
162 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
163 CPPUNIT_ASSERT_THROW( queue->pushJobs(testjobs), Assert::AssertionFailure );
164#endif
165
166 CPPUNIT_ASSERT_EQUAL( (size_t)2, queue->jobs.size() );
167 CPPUNIT_ASSERT_EQUAL((size_t)2, queue->results.size());
168}
169
[b5ebb5]170/** UnitTest for working ResultMap
171 */
172void FragmentQueueTest::ResultsTest()
173{
[02f346]174 // prepare a job
[78ad7d]175 FragmentJob::ptr testJob(new FragmentJob);
176 testJob->setId(1);
177 testJob->outputfile = std::string("do something");
[12d15a]178#ifndef NDEBUG
179 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
180#else
[02f346]181 queue->pushJob(testJob);
[12d15a]182#endif
183#ifndef NDEBUG
184 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
185#else
186 queue->popJob();
187#endif
188
[02f346]189
190 // prepare a result
191 FragmentResult testResult(1);
192 FragmentResult wrongIdResult(2);
193
[b0b64c]194 // check that none are present and we can't get result yet
[8ee5ac]195 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->getDoneJobs() );
[02f346]196 CPPUNIT_ASSERT( !queue->isResultPresent(1) );
197 CPPUNIT_ASSERT( !queue->isResultPresent(2) );
198#ifndef NDEBUG
199 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
200 CPPUNIT_ASSERT_THROW( queue->getResult(1), Assert::AssertionFailure );
201#endif
202
[b0b64c]203 /// check for admonishing wrong id
[02f346]204#ifndef NDEBUG
205 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
206 CPPUNIT_ASSERT_THROW( queue->pushResult(wrongIdResult), Assert::AssertionFailure );
207#endif
[b0b64c]208
209 // push correct result
[02f346]210#ifndef NDEBUG
211 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(testResult) );
212#else
213 queue->pushResult(testResult);
214#endif
215
216 // check presence again
217 CPPUNIT_ASSERT( queue->isResultPresent(1) );
[8ee5ac]218 CPPUNIT_ASSERT_EQUAL( (size_t)1, queue->getDoneJobs() );
[02f346]219
[b0b64c]220 // obtain result again
[02f346]221#ifndef NDEBUG
222 CPPUNIT_ASSERT_NO_THROW( queue->getResult(1) );
223#else
224 queue->getResult(1);
225#endif
226
227 // check presence one more time
[8ee5ac]228 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->getDoneJobs() );
[02f346]229 CPPUNIT_ASSERT( !queue->isResultPresent(1) );
230 CPPUNIT_ASSERT( !queue->isResultPresent(2) );
231#ifndef NDEBUG
232 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
233 CPPUNIT_ASSERT_THROW( queue->getResult(1), Assert::AssertionFailure );
234#endif
[b5ebb5]235}
[b9c486]236
237/** UnitTest for working ResultMap
238 */
239void FragmentQueueTest::AllResultsTest()
240{
241 // prepare a job
[78ad7d]242 FragmentJob::ptr testJob( new FragmentJob );
243 testJob->setId(1);
244 testJob->outputfile = std::string("do something");
245 FragmentJob::ptr anothertestJob( new FragmentJob );
246 anothertestJob->setId(2);
247 anothertestJob->outputfile = std::string("do something else");
[b9c486]248
249#ifndef NDEBUG
250 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
251 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(anothertestJob) );
252#else
253 queue->pushJob(testJob);
254 queue->pushJob(anothertestJob);
255#endif
256
257 // check that no results are returned.
258 {
259 const std::vector<FragmentResult> results = queue->getAllResults();
260 CPPUNIT_ASSERT_EQUAL( (size_t)0, results.size() );
261 }
262
263 // pop both as if some work was being done
264#ifndef NDEBUG
265 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
266 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
267#else
268 queue->popJob();
269 queue->popJob();
270#endif
271
272 // prepare a result
273 FragmentResult testResult(1);
274 FragmentResult anothertestResult(2);
275
276 // push correct result
277#ifndef NDEBUG
278 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(testResult) );
279 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(anothertestResult) );
280#else
281 queue->pushResult(testResult);
282 queue->pushResult(anothertestResult);
283#endif
284
285 // check that two results are returned.
286 {
287 const std::vector<FragmentResult> results = queue->getAllResults();
288 CPPUNIT_ASSERT_EQUAL( (size_t)2, results.size() );
289 }
290}
291
Note: See TracBrowser for help on using the repository browser.