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 WHISTOGRAM2D_TEST_H 00026 #define WHISTOGRAM2D_TEST_H 00027 00028 #include <cxxtest/TestSuite.h> 00029 00030 #include "../WHistogram2D.h" 00031 #include "../WLimits.h" 00032 #include "../WLogger.h" 00033 00034 /** 00035 * Unit tests the WHistogramBasic class. 00036 */ 00037 class WHistogram2DTest : 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 WHistogram2D h( 0.0, 1.0, 0.0, 0.1, 10, 10 ); 00054 TS_ASSERT_EQUALS( h.size(), 100 ); 00055 } 00056 00057 /** 00058 * Check normal insertion inside the min max boundaries. 00059 */ 00060 void testInsert( void ) 00061 { 00062 WHistogram2D h( 0.0, 1.0, 0.0, 1.0, 3, 3 ); 00063 TS_ASSERT_EQUALS( h.size(), 9 ); 00064 for( size_t i = 0; i < 3; ++i ) 00065 { 00066 for( size_t j = 0; j < 3; ++j ) 00067 { 00068 TS_ASSERT_EQUALS( h( i, j ), 0 ); 00069 } 00070 } 00071 h.insert( 0.1, 0.1 ); 00072 h.insert( 0.1, 0.4 ); 00073 h.insert( 0.1, 0.7 ); 00074 h.insert( 0.4, 0.1 ); 00075 h.insert( 0.4, 0.4 ); 00076 h.insert( 0.4, 0.7 ); 00077 h.insert( 0.7, 0.1 ); 00078 h.insert( 0.7, 0.4 ); 00079 h.insert( 0.7, 0.7 ); 00080 for( size_t i = 0; i < 3; ++i ) 00081 { 00082 for( size_t j = 0; j < 3; ++j ) 00083 { 00084 TS_ASSERT_EQUALS( h( i, j ), 1 ); 00085 } 00086 } 00087 } 00088 00089 /** 00090 * If the value is directly on the borderline it counts to the right interval. 00091 */ 00092 void testInsertOnIntervalBorder( void ) 00093 { 00094 WHistogram2D h( 0.0, 1.0, 0.0, 1.0, 10, 10 ); 00095 h.insert( 0.0999999, 0.0 ); 00096 TS_ASSERT_EQUALS( h( 0, 0 ), 1 ); 00097 h.insert( 0.1, 0.0 ); 00098 TS_ASSERT_EQUALS( h( 1, 0 ), 1 ); 00099 h.insert( 0.1001, 0.0 ); 00100 TS_ASSERT_EQUALS( h( 1, 0 ), 2 ); 00101 h.insert( 0.39999, 0.39999 ); 00102 TS_ASSERT_EQUALS( h( 3, 3 ), 1 ); 00103 } 00104 00105 /** 00106 * If the minimum is inserted the first bin should be incremented. 00107 */ 00108 void testInsertMin( void ) 00109 { 00110 WHistogram2D h( 0.0, 1.0, 0.0, 1.0, 2, 2 ); 00111 h.insert( 0.0, 0.0 ); 00112 TS_ASSERT_EQUALS( h( 0, 0 ), 1 ); 00113 TS_ASSERT_EQUALS( h( 1, 0 ), 0 ); 00114 TS_ASSERT_EQUALS( h( 0, 1 ), 0 ); 00115 TS_ASSERT_EQUALS( h( 1, 1 ), 0 ); 00116 } 00117 00118 /** 00119 * If the maximum is inserted the right most interval is used. 00120 */ 00121 void testInsertMax( void ) 00122 { 00123 WHistogram2D h( 0.0, 1.0, 0.0, 1.0, 2, 2 ); 00124 h.insert( 1.0, 1.0 ); 00125 TS_ASSERT_EQUALS( h( 0, 0 ), 0 ); 00126 TS_ASSERT_EQUALS( h( 1, 0 ), 0 ); 00127 TS_ASSERT_EQUALS( h( 0, 1 ), 0 ); 00128 TS_ASSERT_EQUALS( h( 1, 1 ), 1 ); 00129 } 00130 00131 /** 00132 * If above the maximum values are inserted a warning should be printed and nothing should happen. 00133 */ 00134 void testInsertOutOfBounds( void ) 00135 { 00136 WHistogram2D h( 0.0, 1.0, 0.0, 1.0, 10, 10 ); 00137 h.insert( 1.0 + wlimits::DBL_EPS, 0.0 ); 00138 h.insert( 0.0 - wlimits::DBL_EPS, 0.0 ); 00139 for( size_t i = 0; i < 10; ++i ) 00140 { 00141 for( size_t j = 0; j < 10; ++j ) 00142 { 00143 TS_ASSERT_EQUALS( h( i, j ), 0 ); 00144 } 00145 } 00146 } 00147 00148 /** 00149 * Also for values near the maxium. You may also see #186 for further details. 00150 */ 00151 void testInsertAlmostMax( void ) 00152 { 00153 double max = 10000.000000010001; 00154 WHistogram2D h( -2147483646, max, -2147483646, max, 2, 2 ); 00155 h.insert( 10000, 10000 ); 00156 h.insert( max - 2.0 * wlimits::FLT_EPS, max - 2.0 * wlimits::FLT_EPS ); 00157 TS_ASSERT_EQUALS( h( 1, 1 ), 2 ); 00158 } 00159 }; 00160 00161 #endif // WHISTOGRAM2D_TEST_H