OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
WHistogramBasic_test.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WHISTOGRAMBASIC_TEST_H
00026 #define WHISTOGRAMBASIC_TEST_H
00027 
00028 #include <cxxtest/TestSuite.h>
00029 
00030 #include "../WHistogramBasic.h"
00031 #include "../WLimits.h"
00032 #include "../WLogger.h"
00033 
00034 /**
00035  * Unit tests the WHistogramBasic class.
00036  */
00037 class WHistogramBasicTest : public CxxTest::TestSuite
00038 {
00039 public:
00040 
00041     /**
00042      * Setup logger and other stuff for each test.
00043      */
00044     void setUp()
00045     {
00046         WLogger::startup();
00047     }
00048 
00049     /**
00050      * Check when nothing was inserted every thing is empty.
00051      */
00052     void testInitialization( void )
00053     {
00054         WHistogramBasic h( 0.0, 1.0 );
00055         TS_ASSERT_EQUALS( h.size(), 1000 );
00056         TS_ASSERT_EQUALS( h.valuesSize(), 0 );
00057     }
00058 
00059     /**
00060      * Check normal insertion inside the min max boundaries.
00061      */
00062     void testInsert( void )
00063     {
00064         WHistogramBasic h( 0.0, 1.0 );
00065         h.insert( 0.7234 );
00066         TS_ASSERT_EQUALS( h.size(), 1000 );
00067         TS_ASSERT_EQUALS( h.valuesSize(), 1 );
00068         TS_ASSERT_EQUALS( h[723], 1 );
00069     }
00070 
00071     /**
00072      * If the value is directly on the borderline it counts to the right interval.
00073      */
00074     void testInsertOnIntervalBorder( void )
00075     {
00076         WHistogramBasic h( 0.0, 1.0 );
00077         h.insert( 0.001 );
00078         TS_ASSERT_EQUALS( h[1], 1 );
00079         h.insert( 0.0039999 );
00080         TS_ASSERT_EQUALS( h[3], 1 );
00081         h.insert( 0.0070001 );
00082         TS_ASSERT_EQUALS( h[7], 1 );
00083     }
00084 
00085     /**
00086      * If the minimum is inserted the first bin should be incremented.
00087      */
00088     void testInsertMin( void )
00089     {
00090         WHistogramBasic h( 0.0, 1.0 );
00091         h.insert( 0.0 );
00092         TS_ASSERT_EQUALS( h[0], 1 );
00093         TS_ASSERT_EQUALS( h[1], 0 );
00094     }
00095 
00096     /**
00097      * If the maximum is inserted the right most interval is used.
00098      */
00099     void testInsertMax( void )
00100     {
00101         WHistogramBasic h( 0.0, 1.0 );
00102         h.insert( 0.0 );
00103         h.insert( 1.0 );
00104         TS_ASSERT_EQUALS( h[999], 1 );
00105         TS_ASSERT_EQUALS( h[0], 1 );
00106     }
00107 
00108     /**
00109      * If above the maximum values are inserted a warning should be printed and nothing should happen.
00110      */
00111     void testInsertOutOfBounds( void )
00112     {
00113         WHistogramBasic h( 0.0, 1.0 );
00114         h.insert( 1.0 + wlimits::DBL_EPS );
00115         h.insert( 0.0 - wlimits::DBL_EPS );
00116         for( size_t i = 0; i < h.size(); ++i )
00117         {
00118             TS_ASSERT_EQUALS( h[i], 0 );
00119         }
00120     }
00121 
00122     /**
00123      * For each insert this number should increase by one.
00124      */
00125     void testOperatorToGetNumberOfElementsInsideTheBin( void )
00126     {
00127         WHistogramBasic h( 0.0, 1.0 );
00128         for( size_t i = 0; i < h.size(); ++i )
00129         {
00130             TS_ASSERT_EQUALS( h[i], 0 );
00131         }
00132         h.insert( 0.0 );
00133         h.insert( 0.0 );
00134         TS_ASSERT_EQUALS( h.valuesSize(), 2 );
00135     }
00136 };
00137 
00138 #endif  // WHISTOGRAMBASIC_TEST_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends