/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * HistogramUnitTest.cpp * * Created on: Jul 26, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif using namespace std; #include #include #include #include "Fragmentation/Histogram/Histogram.hpp" #include "HistogramUnitTest.hpp" #include #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ using namespace boost::assign; /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( HistogramTest ); void HistogramTest::setUp() { histogram = NULL; } void HistogramTest::tearDown() { delete histogram; } /** UnitTest for checking internal state after given samples */ void HistogramTest::internalState_Test() { // generate non-empty histogramgram Histogram::samples_t sampled_values; sampled_values += 1.,2.,3.,4.; CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); histogram = new Histogram(sampled_values, 4); CPPUNIT_ASSERT_EQUAL( (size_t)4+1, histogram->bins.size() ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->bins.begin() ); CPPUNIT_ASSERT_EQUAL( 1., histogram->bins.begin()->second ); CPPUNIT_ASSERT_EQUAL( 0., (--histogram->bins.end())->second ); } /** UnitTest for getLowerEndBin() */ void HistogramTest::getLowerEndBin_Test() { // generate non-empty histogramgram Histogram::samples_t sampled_values; sampled_values += 1.,2.,3.,4.; CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); histogram = new Histogram(sampled_values, 4); // check values inside CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(1.) ); CPPUNIT_ASSERT_EQUAL( 1., histogram->getLowerEndBin(1.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(2.) ); CPPUNIT_ASSERT_EQUAL( 2., histogram->getLowerEndBin(2.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(3.) ); CPPUNIT_ASSERT_EQUAL( 3., histogram->getLowerEndBin(3.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(4.) ); CPPUNIT_ASSERT_EQUAL( 4., histogram->getLowerEndBin(4.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(1.5) ); CPPUNIT_ASSERT_EQUAL( 1., histogram->getLowerEndBin(1.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(2.5) ); CPPUNIT_ASSERT_EQUAL( 2., histogram->getLowerEndBin(2.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(3.5) ); CPPUNIT_ASSERT_EQUAL( 3., histogram->getLowerEndBin(3.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getLowerEndBin(4.5) ); CPPUNIT_ASSERT_EQUAL( 4., histogram->getLowerEndBin(4.5)->first ); // check values outside CPPUNIT_ASSERT( histogram->bins.end() == histogram->getLowerEndBin(.9) ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getLowerEndBin(5.01) ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getLowerEndBin(5.) ); } /** UnitTest for getHigherEndBin() */ void HistogramTest::getHigherEndBin_Test() { // generate non-empty histogramgram Histogram::samples_t sampled_values; sampled_values += 1.,2.,3.,4.; CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); histogram = new Histogram(sampled_values, 4); // check values inside CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(.5) ); CPPUNIT_ASSERT_EQUAL( 1., histogram->getHigherEndBin(.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(1.) ); CPPUNIT_ASSERT_EQUAL( 2., histogram->getHigherEndBin(1.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(2.) ); CPPUNIT_ASSERT_EQUAL( 3., histogram->getHigherEndBin(2.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(3.) ); CPPUNIT_ASSERT_EQUAL( 4., histogram->getHigherEndBin(3.)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(4.) ); CPPUNIT_ASSERT_EQUAL( 5., histogram->getHigherEndBin(4.)->first ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getHigherEndBin(5.) ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(1.5) ); CPPUNIT_ASSERT_EQUAL( 2., histogram->getHigherEndBin(1.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(2.5) ); CPPUNIT_ASSERT_EQUAL( 3., histogram->getHigherEndBin(2.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(3.5) ); CPPUNIT_ASSERT_EQUAL( 4., histogram->getHigherEndBin(3.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(4.5) ); CPPUNIT_ASSERT_EQUAL( 5., histogram->getHigherEndBin(4.5)->first ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getHigherEndBin(5.5) ); // check values outside CPPUNIT_ASSERT( histogram->bins.end() != histogram->getHigherEndBin(-.1) ); CPPUNIT_ASSERT_EQUAL( 1., histogram->getHigherEndBin(-.1)->first ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getHigherEndBin(5.01) ); CPPUNIT_ASSERT( histogram->bins.end() == histogram->getHigherEndBin(5.) ); } /** UnitTest for isEmpty() */ void HistogramTest::isEmpty_Test() { histogram = new Histogram(std::vector()); // test on empty histogramgram CPPUNIT_ASSERT( histogram->isEmpty() ); // create non-empty histogram and test Histogram::samples_t sampled_values; sampled_values += 1.,2.,3.,4.; delete histogram; histogram = new Histogram(sampled_values, 4); CPPUNIT_ASSERT( !histogram->isEmpty() ); } /** UnitTest for operator+=(), operator-=() */ void HistogramTest::operator_Test() { }