DGtal  0.9.2
testMultiStatistics.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtalCatch.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/math/MultiStatistics.h"
38 
39 using namespace std;
40 using namespace DGtal;
41 
43 // Functions for testing class MultiStatistics.
45 
46 TEST_CASE( "Testing MultiStatistics" )
47 {
48  MultiStatistics stats (100, false);
49  for(unsigned int i = 0; i< 100; i++)
50  {
51  for(unsigned int j = 0; j<= i; j++)
52  {
53  stats.addValue(i, j);
54  }
55  }
56  stats.terminate();
57 
58  SECTION("Testing multiStatics estimated quantities without saving the data")
59  {
60  unsigned int val = 50;
61  REQUIRE( stats.max(val) == val );
62  REQUIRE( stats.min(val) == 0 );
63  REQUIRE( stats.mean(val) == val/2.0 );
64  val = 31;
65  REQUIRE( stats.max(val) == val );
66  REQUIRE( stats.min(val) == 0 );
67  REQUIRE( stats.mean(val) == val/2.0 );
68  }
69 
70  MultiStatistics stats2 (100, true);
71  for(unsigned int i = 0; i< 100; i++)
72  {
73  for(unsigned int j = 0; j<= i; j++)
74  {
75  stats2.addValue(i, j);
76  }
77  }
78  stats2.terminate();
79 
80  SECTION("Testing multiStatics estimated quantities with saving the data")
81  {
82  unsigned int val = 12;
83  REQUIRE( stats2.max(val) == val );
84  REQUIRE( stats2.min(val) == 0 );
85  REQUIRE( stats2.mean(val) == val/2.0 );
86  REQUIRE( stats2.median(val) == ((val+1)/2) );
87  val = 33;
88  REQUIRE( stats2.max(val) == val );
89  REQUIRE( stats2.min(val) == 0 );
90  REQUIRE( stats2.mean(val) == val/2.0 );
91  REQUIRE( stats2.median(val) == ((val+1)/2) );
92  }
93 
94 
95  MultiStatistics stats3 (100, true);
96  for(unsigned int i = 0; i< 100; i++)
97  {
98  std::vector<double> vectValues;
99  for(unsigned int j = 0; j<= i; j++)
100  {
101  vectValues.push_back(j);
102  }
103  stats3.addValues(i, vectValues.begin(), vectValues.end());
104  }
105  stats3.terminate();
106 
107  SECTION("Testing feature math of MultiStatistics with saving data")
108  {
109  unsigned int val = 12;
110  REQUIRE( stats3.max(val) == val );
111  REQUIRE( stats3.min(val) == 0 );
112  REQUIRE( stats3.mean(val) == val/2.0 );
113  REQUIRE( stats3.median(val) == ((val+1)/2) );
114  val = 33;
115  REQUIRE( stats3.max(val) == val );
116  REQUIRE( stats3.min(val) == 0 );
117  REQUIRE( stats3.mean(val) == val/2.0 );
118  REQUIRE( stats3.median(val) == ((val+1)/2) );
119  }
120 
121 
122 }
123 
Aim: This class stores a set of sample values for several variables and can then compute different st...
STL namespace.
DGtal is the top-level namespace which contains all DGtal functions and types.