source: src/Fragmentation/Homology/unittests/HomologyGraphUnitTest.cpp@ 2bde72

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 2bde72 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: 5.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 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 * HomologyGraphUnitTest.cpp
26 *
27 * Created on: Sep 25, 2012
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 "Fragmentation/Homology/HomologyGraph.hpp"
47#include "Fragmentation/Graph.hpp"
48
49#include "HomologyGraphUnitTest.hpp"
50
51#include "CodePatterns/Assert.hpp"
52
53#include <boost/assign.hpp>
54#include <sstream>
55
56using namespace boost::assign;
57
58#ifdef HAVE_TESTRUNNER
59#include "UnitTestMain.hpp"
60#endif /*HAVE_TESTRUNNER*/
61
62/********************************************** Test classes **************************************/
63
64// Registers the fixture into the 'registry'
65CPPUNIT_TEST_SUITE_REGISTRATION( HomologyGraphTest );
66
67
68void HomologyGraphTest::setUp()
69{
70 // failing asserts should be thrown
71 ASSERT_DO(Assert::Throw);
72
73 // add nodes
74 nodes +=
75 std::make_pair(FragmentNode(1,1),1),
76 std::make_pair(FragmentNode(1,4),1),
77 std::make_pair(FragmentNode(2,2),1),
78 std::make_pair(FragmentNode(2,4),1);
79 othernodes +=
80 std::make_pair(FragmentNode(1,1),1),
81 std::make_pair(FragmentNode(1,4),1);
82
83 // add edges
84 edges +=
85 std::make_pair(FragmentEdge(1,1),1),
86 std::make_pair(FragmentEdge(1,4),1),
87 std::make_pair(FragmentEdge(2,2),1),
88 std::make_pair(FragmentEdge(2,4),1);
89 otheredges +=
90 std::make_pair(FragmentEdge(1,4),1),
91 std::make_pair(FragmentEdge(2,2),1);
92
93 // construct graph
94 graph = new HomologyGraph(nodes, edges);
95}
96
97
98void HomologyGraphTest::tearDown()
99{
100 delete graph;
101}
102
103/** UnitTest for whether homologies are correctly recognized
104 */
105void HomologyGraphTest::comparatorTest()
106{
107 // construct other graphs
108 HomologyGraph samegraph(nodes, edges);
109 HomologyGraph othergraph(nodes, otheredges);
110 HomologyGraph anothergraph(othernodes, edges);
111 HomologyGraph yetanothergraph(othernodes, otheredges);
112
113 // sort them (order is: anothergraph, yetanothergraph, graph/samegraph, othergraph)
114 CPPUNIT_ASSERT( !(*graph < samegraph) );
115 CPPUNIT_ASSERT( othergraph > *graph );
116 CPPUNIT_ASSERT( anothergraph < *graph );
117 CPPUNIT_ASSERT( yetanothergraph < *graph );
118 CPPUNIT_ASSERT( anothergraph < othergraph );
119 CPPUNIT_ASSERT( yetanothergraph < othergraph );
120 CPPUNIT_ASSERT( yetanothergraph > anothergraph );
121
122 CPPUNIT_ASSERT( !(*graph > samegraph) );
123 CPPUNIT_ASSERT( *graph < othergraph );
124 CPPUNIT_ASSERT( *graph > anothergraph );
125 CPPUNIT_ASSERT( *graph > yetanothergraph );
126 CPPUNIT_ASSERT( othergraph > anothergraph );
127 CPPUNIT_ASSERT( othergraph > yetanothergraph );
128 CPPUNIT_ASSERT( anothergraph < yetanothergraph );
129
130 // compare them
131 CPPUNIT_ASSERT( *graph == samegraph );
132 CPPUNIT_ASSERT( *graph != othergraph );
133 CPPUNIT_ASSERT( *graph != anothergraph );
134 CPPUNIT_ASSERT( *graph != yetanothergraph );
135 CPPUNIT_ASSERT( othergraph != anothergraph );
136 CPPUNIT_ASSERT( othergraph != yetanothergraph );
137 CPPUNIT_ASSERT( anothergraph != yetanothergraph );
138}
139
140/** UnitTest for operator=()
141 */
142void HomologyGraphTest::assigmentTest()
143{
144 HomologyGraph samegraph(nodes, edges);
145 HomologyGraph othergraph(othernodes, otheredges);
146
147 // check initial status
148 CPPUNIT_ASSERT( *graph == samegraph);
149 CPPUNIT_ASSERT( *graph != othergraph);
150
151 // now assign
152 samegraph = othergraph;
153 othergraph = *graph;
154
155 // and check again
156 CPPUNIT_ASSERT( *graph != samegraph);
157 CPPUNIT_ASSERT( *graph == othergraph);
158
159 // also self-assign
160 *graph = *graph;
161 CPPUNIT_ASSERT( *graph == *graph);
162}
163
164
165/** UnitTest for serialization
166 */
167void HomologyGraphTest::serializeTest()
168{
169 // serialize
170 std::stringstream outputstream;
171 boost::archive::text_oarchive oa(outputstream);
172 oa << graph;
173
174 // deserialize
175 HomologyGraph *samegraph;
176 std::stringstream returnstream(outputstream.str());
177 boost::archive::text_iarchive ia(returnstream);
178 ia >> samegraph;
179
180 CPPUNIT_ASSERT( *graph == *samegraph );
181
182 delete samegraph;
183}
Note: See TracBrowser for help on using the repository browser.