| [063fab] | 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 | * IndexSetContainerUnitTest.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Jul 3, 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 "Fragmentation/Summation/IndexSetContainer.hpp" | 
|---|
|  | 42 |  | 
|---|
|  | 43 | #include "IndexSetContainerUnitTest.hpp" | 
|---|
|  | 44 |  | 
|---|
|  | 45 | #include <boost/assign.hpp> | 
|---|
|  | 46 | #include <boost/foreach.hpp> | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 49 | #include "UnitTestMain.hpp" | 
|---|
|  | 50 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 51 |  | 
|---|
|  | 52 | using namespace boost::assign; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | /********************************************** Test classes **************************************/ | 
|---|
|  | 55 |  | 
|---|
|  | 56 | // Registers the fixture into the 'registry' | 
|---|
|  | 57 | CPPUNIT_TEST_SUITE_REGISTRATION( IndexSetContainerTest ); | 
|---|
|  | 58 |  | 
|---|
|  | 59 |  | 
|---|
|  | 60 | void IndexSetContainerTest::setUp() | 
|---|
|  | 61 | { | 
|---|
|  | 62 | allsets.reserve(5); | 
|---|
|  | 63 | IndexSet tempset; | 
|---|
|  | 64 | tempset += 1; | 
|---|
|  | 65 | allsets += tempset; | 
|---|
|  | 66 | tempset += 2; | 
|---|
|  | 67 | allsets += tempset; | 
|---|
|  | 68 | tempset.clear(); | 
|---|
|  | 69 | tempset += 3; | 
|---|
|  | 70 | allsets += tempset; | 
|---|
|  | 71 | tempset += 2; | 
|---|
|  | 72 | allsets += tempset; | 
|---|
|  | 73 | tempset += 4; | 
|---|
|  | 74 | allsets += tempset; | 
|---|
|  | 75 | tempset += 1; | 
|---|
|  | 76 | allsets += tempset; | 
|---|
|  | 77 | CPPUNIT_ASSERT_EQUAL( (size_t)6, allsets.size() ); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | SV = NULL; | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 |  | 
|---|
|  | 83 | void IndexSetContainerTest::tearDown() | 
|---|
|  | 84 | { | 
|---|
|  | 85 | allsets.clear(); | 
|---|
|  | 86 | delete SV; | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | /** UnitTest for constructor | 
|---|
|  | 90 | */ | 
|---|
|  | 91 | void IndexSetContainerTest::constructorTest() | 
|---|
|  | 92 | { | 
|---|
|  | 93 | SV = new IndexSetContainer(allsets); | 
|---|
|  | 94 | // check that container is sorted | 
|---|
|  | 95 | const IndexSetContainer::Container_t &container = SV->getContainer(); | 
|---|
|  | 96 | //  BOOST_FOREACH( IndexSet_ptr a, container) { | 
|---|
|  | 97 | //    std::cout << *a << "\t"; | 
|---|
|  | 98 | //  } | 
|---|
|  | 99 | //  std::cout << endl; | 
|---|
|  | 100 | CPPUNIT_ASSERT_EQUAL( (size_t)6, container.size() ); | 
|---|
|  | 101 | } | 
|---|
|  | 102 |  | 
|---|
|  | 103 |  | 
|---|
|  | 104 | /** UnitTest for operator==,!=,<,>() | 
|---|
|  | 105 | */ | 
|---|
|  | 106 | void IndexSetContainerTest::comparatorTest() | 
|---|
|  | 107 | { | 
|---|
|  | 108 | SV = new IndexSetContainer(allsets); | 
|---|
|  | 109 | // check that container is sorted | 
|---|
|  | 110 | typedef IndexSetContainer::Container_t::const_iterator iterator; | 
|---|
|  | 111 | const IndexSetContainer::Container_t &container = SV->getContainer(); | 
|---|
|  | 112 | iterator frontiter = ++(container.begin()); | 
|---|
|  | 113 | for (iterator backiter = container.begin(); | 
|---|
|  | 114 | frontiter != container.end(); ++backiter, ++frontiter) { | 
|---|
|  | 115 | //std::cout << **backiter << " < " << **frontiter << std::endl; | 
|---|
|  | 116 | CPPUNIT_ASSERT( **backiter < **frontiter ); | 
|---|
|  | 117 | } | 
|---|
|  | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 | /** Unit tests for insert() | 
|---|
|  | 121 | * | 
|---|
|  | 122 | */ | 
|---|
|  | 123 | void IndexSetContainerTest::insertTest() | 
|---|
|  | 124 | { | 
|---|
|  | 125 | SV = new IndexSetContainer(allsets); | 
|---|
|  | 126 | IndexSet_ptr tempset(new IndexSet); | 
|---|
|  | 127 | (*tempset) += 1,2,3,4; | 
|---|
|  | 128 |  | 
|---|
|  | 129 | // insert present set and check that it is still sorted | 
|---|
|  | 130 | CPPUNIT_ASSERT( SV->ContainerSorted ); | 
|---|
|  | 131 | SV->insert(tempset); | 
|---|
|  | 132 | CPPUNIT_ASSERT( SV->ContainerSorted ); | 
|---|
|  | 133 |  | 
|---|
|  | 134 | // insert new set and check that it is now unsorted | 
|---|
|  | 135 | (*tempset) += 5; | 
|---|
|  | 136 | CPPUNIT_ASSERT( SV->ContainerSorted ); | 
|---|
|  | 137 | SV->insert(tempset); | 
|---|
|  | 138 | CPPUNIT_ASSERT( !SV->ContainerSorted ); | 
|---|
|  | 139 | } | 
|---|