source: src/Fragmentation/Exporters/unittests/HydrogenPoolUnitTest.cpp@ 0983e6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 0983e6 was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * HydrogenPoolUnitTest.cpp
26 *
27 * Created on: Mar 03, 2013
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36using namespace std;
37
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41
42// include headers that implement a archive in simple text format
43#include <boost/archive/text_oarchive.hpp>
44#include <boost/archive/text_iarchive.hpp>
45
46#include "HydrogenPoolUnitTest.hpp"
47
48#include "CodePatterns/Assert.hpp"
49
50#include "Fragmentation/Exporters/HydrogenPool.hpp"
51#include "World.hpp"
52
53#ifdef HAVE_TESTRUNNER
54#include "UnitTestMain.hpp"
55#endif /*HAVE_TESTRUNNER*/
56
57/********************************************** Test classes **************************************/
58
59// Registers the fixture into the 'registry'
60CPPUNIT_TEST_SUITE_REGISTRATION( HydrogenPoolTest );
61
62
63void HydrogenPoolTest::setUp()
64{
65 // failing asserts should be thrown
66 ASSERT_DO(Assert::Throw);
67
68 pool = new HydrogenPool();
69}
70
71
72void HydrogenPoolTest::tearDown()
73{
74 delete pool;
75
76 World::purgeInstance();
77}
78
79/** UnitTest for leaseHydrogen() and releaseHydrogen.
80 */
81void HydrogenPoolTest::lease_releaseHydrogen_Test()
82{
83 // check simple test
84 {
85 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
86 atom * const Walker = pool->leaseHydrogen();
87 CPPUNIT_ASSERT( pool->HydrogenQueue.empty() );
88 CPPUNIT_ASSERT( !pool->HydrogenInUse.empty() );
89 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
90 pool->releaseHydrogen(Walker);
91 CPPUNIT_ASSERT( !pool->HydrogenQueue.empty() );
92 CPPUNIT_ASSERT( pool->HydrogenInUse.empty() );
93 pool->cleanup();
94 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
95 }
96 // check via id test
97 {
98 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
99 atom * const Walker = pool->leaseHydrogen();
100 CPPUNIT_ASSERT( pool->HydrogenQueue.empty() );
101 CPPUNIT_ASSERT( !pool->HydrogenInUse.empty() );
102 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
103 pool->releaseHydrogen(Walker->getId());
104 CPPUNIT_ASSERT( !pool->HydrogenQueue.empty() );
105 CPPUNIT_ASSERT( pool->HydrogenInUse.empty() );
106 pool->cleanup();
107 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
108 }
109 // check that can't cleanup with leased atoms
110 {
111 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
112 atom * const Walker = pool->leaseHydrogen();
113 std::cerr << "The following assertion is intended and does not entail a failure of the test." << std::endl;
114#ifndef NDEBUG
115 CPPUNIT_ASSERT_THROW(pool->cleanup(), Assert::AssertionFailure );
116#else
117 pool->cleanup();
118#endif
119 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
120 pool->releaseHydrogen(Walker);
121 pool->cleanup();
122 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
123 }
124 // check returning from atom
125 {
126 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
127 atom * const Walker = pool->leaseHydrogen();
128 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
129 atom * const InvalidWalker = NULL;
130 std::cerr << "The following assertion is intended and does not entail a failure of the test." << std::endl;
131#ifndef NDEBUG
132 CPPUNIT_ASSERT_THROW(pool->releaseHydrogen(InvalidWalker), Assert::AssertionFailure );
133#else
134 pool->releaseHydrogen(InvalidWalker);
135#endif
136 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
137 pool->releaseHydrogen(Walker);
138 pool->cleanup();
139 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
140 }
141}
142
143/** UnitTest for requestHydrogen().
144 */
145void HydrogenPoolTest::requestHydrogen_Test()
146{
147 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
148 pool->requestHydrogenIntoPool();
149 CPPUNIT_ASSERT( !pool->HydrogenQueue.empty() );
150 CPPUNIT_ASSERT_EQUAL( 1, World::getInstance().numAtoms() );
151 pool->cleanup();
152 CPPUNIT_ASSERT_EQUAL( 0, World::getInstance().numAtoms() );
153}
Note: See TracBrowser for help on using the repository browser.