OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WHistogramBasic_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WHISTOGRAMBASIC_TEST_H
26 #define WHISTOGRAMBASIC_TEST_H
27 
28 #include <cxxtest/TestSuite.h>
29 
30 #include "../WHistogramBasic.h"
31 #include "../WLimits.h"
32 #include "../WLogger.h"
33 
34 /**
35  * Unit tests the WHistogramBasic class.
36  */
37 class WHistogramBasicTest : public CxxTest::TestSuite
38 {
39 public:
40 
41  /**
42  * Setup logger and other stuff for each test.
43  */
44  void setUp()
45  {
47  }
48 
49  /**
50  * Check when nothing was inserted every thing is empty.
51  */
52  void testInitialization( void )
53  {
54  WHistogramBasic h( 0.0, 1.0 );
55  TS_ASSERT_EQUALS( h.size(), 1000 );
56  TS_ASSERT_EQUALS( h.valuesSize(), 0 );
57  }
58 
59  /**
60  * Check normal insertion inside the min max boundaries.
61  */
62  void testInsert( void )
63  {
64  WHistogramBasic h( 0.0, 1.0 );
65  h.insert( 0.7234 );
66  TS_ASSERT_EQUALS( h.size(), 1000 );
67  TS_ASSERT_EQUALS( h.valuesSize(), 1 );
68  TS_ASSERT_EQUALS( h[723], 1 );
69  }
70 
71  /**
72  * If the value is directly on the borderline it counts to the right interval.
73  */
75  {
76  WHistogramBasic h( 0.0, 1.0 );
77  h.insert( 0.001 );
78  TS_ASSERT_EQUALS( h[1], 1 );
79  h.insert( 0.0039999 );
80  TS_ASSERT_EQUALS( h[3], 1 );
81  h.insert( 0.0070001 );
82  TS_ASSERT_EQUALS( h[7], 1 );
83  }
84 
85  /**
86  * If the minimum is inserted the first bin should be incremented.
87  */
88  void testInsertMin( void )
89  {
90  WHistogramBasic h( 0.0, 1.0 );
91  h.insert( 0.0 );
92  TS_ASSERT_EQUALS( h[0], 1 );
93  TS_ASSERT_EQUALS( h[1], 0 );
94  }
95 
96  /**
97  * If the maximum is inserted the right most interval is used.
98  */
99  void testInsertMax( void )
100  {
101  WHistogramBasic h( 0.0, 1.0 );
102  h.insert( 0.0 );
103  h.insert( 1.0 );
104  TS_ASSERT_EQUALS( h[999], 1 );
105  TS_ASSERT_EQUALS( h[0], 1 );
106  }
107 
108  /**
109  * If above the maximum values are inserted a warning should be printed and nothing should happen.
110  */
112  {
113  WHistogramBasic h( 0.0, 1.0 );
114  h.insert( 1.0 + wlimits::DBL_EPS );
115  h.insert( 0.0 - wlimits::DBL_EPS );
116  for( size_t i = 0; i < h.size(); ++i )
117  {
118  TS_ASSERT_EQUALS( h[i], 0 );
119  }
120  }
121 
122  /**
123  * For each insert this number should increase by one.
124  */
126  {
127  WHistogramBasic h( 0.0, 1.0 );
128  for( size_t i = 0; i < h.size(); ++i )
129  {
130  TS_ASSERT_EQUALS( h[i], 0 );
131  }
132  h.insert( 0.0 );
133  h.insert( 0.0 );
134  TS_ASSERT_EQUALS( h.valuesSize(), 2 );
135  }
136 };
137 
138 #endif // WHISTOGRAMBASIC_TEST_H