OpenWalnut
1.4.0
|
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 * Setup logger and other stuff for each test. 00042 */ 00043 void setUp() 00044 { 00045 WLogger::startup(); 00046 } 00047 00048 /** 00049 * Check when nothing was inserted every thing is empty. 00050 */ 00051 void testInitialization( void ) 00052 { 00053 WHistogramBasic h( 0.0, 1.0 ); 00054 TS_ASSERT_EQUALS( h.size(), 1000 ); 00055 TS_ASSERT_EQUALS( h.valuesSize(), 0 ); 00056 } 00057 00058 /** 00059 * Check normal insertion inside the min max boundaries. 00060 */ 00061 void testInsert( void ) 00062 { 00063 WHistogramBasic h( 0.0, 1.0 ); 00064 h.insert( 0.7234 ); 00065 TS_ASSERT_EQUALS( h.size(), 1000 ); 00066 TS_ASSERT_EQUALS( h.valuesSize(), 1 ); 00067 TS_ASSERT_EQUALS( h[723], 1 ); 00068 } 00069 00070 /** 00071 * If the value is directly on the borderline it counts to the right interval. 00072 */ 00073 void testInsertOnIntervalBorder( void ) 00074 { 00075 WHistogramBasic h( 0.0, 1.0 ); 00076 h.insert( 0.001 ); 00077 TS_ASSERT_EQUALS( h[1], 1 ); 00078 h.insert( 0.0039999 ); 00079 TS_ASSERT_EQUALS( h[3], 1 ); 00080 h.insert( 0.0070001 ); 00081 TS_ASSERT_EQUALS( h[7], 1 ); 00082 } 00083 00084 /** 00085 * If the minimum is inserted the first bin should be incremented. 00086 */ 00087 void testInsertMin( void ) 00088 { 00089 WHistogramBasic h( 0.0, 1.0 ); 00090 h.insert( 0.0 ); 00091 TS_ASSERT_EQUALS( h[0], 1 ); 00092 TS_ASSERT_EQUALS( h[1], 0 ); 00093 } 00094 00095 /** 00096 * If the maximum is inserted the right most interval is used. 00097 */ 00098 void testInsertMax( void ) 00099 { 00100 WHistogramBasic h( 0.0, 1.0 ); 00101 h.insert( 0.0 ); 00102 h.insert( 1.0 ); 00103 TS_ASSERT_EQUALS( h[999], 1 ); 00104 TS_ASSERT_EQUALS( h[0], 1 ); 00105 } 00106 00107 /** 00108 * If above the maximum values are inserted a warning should be printed and nothing should happen. 00109 */ 00110 void testInsertOutOfBounds( void ) 00111 { 00112 WHistogramBasic h( 0.0, 1.0 ); 00113 h.insert( 1.0 + wlimits::DBL_EPS ); 00114 h.insert( 0.0 - wlimits::DBL_EPS ); 00115 for( size_t i = 0; i < h.size(); ++i ) 00116 { 00117 TS_ASSERT_EQUALS( h[i], 0 ); 00118 } 00119 } 00120 00121 /** 00122 * For each insert this number should increase by one. 00123 */ 00124 void testOperatorToGetNumberOfElementsInsideTheBin( void ) 00125 { 00126 WHistogramBasic h( 0.0, 1.0 ); 00127 for( size_t i = 0; i < h.size(); ++i ) 00128 { 00129 TS_ASSERT_EQUALS( h[i], 0 ); 00130 } 00131 h.insert( 0.0 ); 00132 h.insert( 0.0 ); 00133 TS_ASSERT_EQUALS( h.valuesSize(), 2 ); 00134 } 00135 00136 /** 00137 * Also for values near the maxium. You may also see #186 for further details. 00138 */ 00139 void testInsertAlmostMax( void ) 00140 { 00141 double max = 10000.000000010001; 00142 WHistogramBasic h( -2147483646, max ); 00143 h.insert( 10000 ); 00144 h.insert( max - 2.0 * wlimits::FLT_EPS ); 00145 TS_ASSERT_EQUALS( h[999], 2 ); 00146 } 00147 }; 00148 00149 #endif // WHISTOGRAMBASIC_TEST_H