| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | * This file is part of MoleCuilder.
|
|---|
| 8 | *
|
|---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 10 | * it under the terms of the GNU General Public License as published by
|
|---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 12 | * (at your option) any later version.
|
|---|
| 13 | *
|
|---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | * GNU General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | * HomologyGraphUnitTest.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: Sep 25, 2012
|
|---|
| 27 | * Author: heber
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | using namespace std;
|
|---|
| 36 |
|
|---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
|---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
|---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
|---|
| 40 |
|
|---|
| 41 | // include headers that implement a archive in simple text format
|
|---|
| 42 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 44 |
|
|---|
| 45 | #include "Fragmentation/Homology/HomologyGraph.hpp"
|
|---|
| 46 | #include "Fragmentation/Graph.hpp"
|
|---|
| 47 |
|
|---|
| 48 | #include "HomologyGraphUnitTest.hpp"
|
|---|
| 49 |
|
|---|
| 50 | #include "CodePatterns/Assert.hpp"
|
|---|
| 51 |
|
|---|
| 52 | #include <boost/assign.hpp>
|
|---|
| 53 |
|
|---|
| 54 | using namespace boost::assign;
|
|---|
| 55 |
|
|---|
| 56 | #ifdef HAVE_TESTRUNNER
|
|---|
| 57 | #include "UnitTestMain.hpp"
|
|---|
| 58 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 59 |
|
|---|
| 60 | /********************************************** Test classes **************************************/
|
|---|
| 61 |
|
|---|
| 62 | // Registers the fixture into the 'registry'
|
|---|
| 63 | CPPUNIT_TEST_SUITE_REGISTRATION( HomologyGraphTest );
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | void HomologyGraphTest::setUp()
|
|---|
| 67 | {
|
|---|
| 68 | // failing asserts should be thrown
|
|---|
| 69 | ASSERT_DO(Assert::Throw);
|
|---|
| 70 |
|
|---|
| 71 | // add nodes
|
|---|
| 72 | nodes += FragmentNode(1,1),FragmentNode(1,4), FragmentNode(2,2), FragmentNode(2,4);
|
|---|
| 73 | othernodes += FragmentNode(1,1),FragmentNode(1,4);
|
|---|
| 74 |
|
|---|
| 75 | // add edges
|
|---|
| 76 | edges += FragmentEdge(1,1),FragmentEdge(1,4), FragmentEdge(2,2), FragmentEdge(2,4);
|
|---|
| 77 | otheredges += FragmentEdge(1,4),FragmentEdge(2,2);
|
|---|
| 78 |
|
|---|
| 79 | // construct graph
|
|---|
| 80 | graph = new HomologyGraph(nodes, edges);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | void HomologyGraphTest::tearDown()
|
|---|
| 85 | {
|
|---|
| 86 | delete graph;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | /** UnitTest for whether homologies are correctly recognized
|
|---|
| 90 | */
|
|---|
| 91 | void HomologyGraphTest::comparatorTest()
|
|---|
| 92 | {
|
|---|
| 93 | // construct other graphs
|
|---|
| 94 | HomologyGraph samegraph(nodes, edges);
|
|---|
| 95 | HomologyGraph othergraph(nodes, otheredges);
|
|---|
| 96 | HomologyGraph anothergraph(othernodes, edges);
|
|---|
| 97 | HomologyGraph yetanothergraph(othernodes, otheredges);
|
|---|
| 98 |
|
|---|
| 99 | // sort them (order is: anothergraph, yetanothergraph, graph/samegraph, othergraph)
|
|---|
| 100 | CPPUNIT_ASSERT( !(*graph < samegraph) );
|
|---|
| 101 | CPPUNIT_ASSERT( othergraph > *graph );
|
|---|
| 102 | CPPUNIT_ASSERT( anothergraph < *graph );
|
|---|
| 103 | CPPUNIT_ASSERT( yetanothergraph < *graph );
|
|---|
| 104 | CPPUNIT_ASSERT( anothergraph < othergraph );
|
|---|
| 105 | CPPUNIT_ASSERT( yetanothergraph < othergraph );
|
|---|
| 106 | CPPUNIT_ASSERT( yetanothergraph > anothergraph );
|
|---|
| 107 |
|
|---|
| 108 | CPPUNIT_ASSERT( !(*graph > samegraph) );
|
|---|
| 109 | CPPUNIT_ASSERT( *graph < othergraph );
|
|---|
| 110 | CPPUNIT_ASSERT( *graph > anothergraph );
|
|---|
| 111 | CPPUNIT_ASSERT( *graph > yetanothergraph );
|
|---|
| 112 | CPPUNIT_ASSERT( othergraph > anothergraph );
|
|---|
| 113 | CPPUNIT_ASSERT( othergraph > yetanothergraph );
|
|---|
| 114 | CPPUNIT_ASSERT( anothergraph < yetanothergraph );
|
|---|
| 115 |
|
|---|
| 116 | // compare them
|
|---|
| 117 | CPPUNIT_ASSERT( *graph == samegraph );
|
|---|
| 118 | CPPUNIT_ASSERT( *graph != othergraph );
|
|---|
| 119 | CPPUNIT_ASSERT( *graph != anothergraph );
|
|---|
| 120 | CPPUNIT_ASSERT( *graph != yetanothergraph );
|
|---|
| 121 | CPPUNIT_ASSERT( othergraph != anothergraph );
|
|---|
| 122 | CPPUNIT_ASSERT( othergraph != yetanothergraph );
|
|---|
| 123 | CPPUNIT_ASSERT( anothergraph != yetanothergraph );
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /** UnitTest for operator=()
|
|---|
| 127 | */
|
|---|
| 128 | void HomologyGraphTest::assigmentTest()
|
|---|
| 129 | {
|
|---|
| 130 | HomologyGraph samegraph(nodes, edges);
|
|---|
| 131 | HomologyGraph othergraph(othernodes, otheredges);
|
|---|
| 132 |
|
|---|
| 133 | // check initial status
|
|---|
| 134 | CPPUNIT_ASSERT( *graph == samegraph);
|
|---|
| 135 | CPPUNIT_ASSERT( *graph != othergraph);
|
|---|
| 136 |
|
|---|
| 137 | // now assign
|
|---|
| 138 | samegraph = othergraph;
|
|---|
| 139 | othergraph = *graph;
|
|---|
| 140 |
|
|---|
| 141 | // and check again
|
|---|
| 142 | CPPUNIT_ASSERT( *graph != samegraph);
|
|---|
| 143 | CPPUNIT_ASSERT( *graph == othergraph);
|
|---|
| 144 |
|
|---|
| 145 | // also self-assign
|
|---|
| 146 | *graph = *graph;
|
|---|
| 147 | CPPUNIT_ASSERT( *graph == *graph);
|
|---|
| 148 | }
|
|---|