DGtal 1.4.0
Loading...
Searching...
No Matches
testStatistics.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <vector>
33#include "DGtal/math/Statistic.h"
34
36
37using namespace std;
38using namespace DGtal;
39
41// Functions for testing class Statistics.
43
48{
49 unsigned int nbok = 0;
50 unsigned int nb = 3;
51
52 trace.beginBlock ( "Testing Statistics ..." );
53
55
56 for(unsigned int k=0; k < 1000; k++)
57 stat.addValue((double)k);
58
59 stat.terminate();
60
61 trace.info() << "Mean value = "<<stat.mean() << std::endl;
62 nbok += (stat.mean()==499.5) ? 1 : 0;
63 trace.info() << "Variance value = "<<stat.variance()<<std::endl;
64 trace.info() << "Max value = "<<stat.max()<<std::endl;
65 nbok += (stat.max()==999) ? 1 : 0;
66 trace.info() << "Min value = "<<stat.min()<<std::endl;
67 nbok += (stat.min()==0) ? 1 : 0;
68
69 trace.info() << "(" << nbok << "/" << nb << ") "
70 << "true == true" << std::endl;
72
73 return nbok == nb;
74}
75
81{
82 unsigned int nbok = 0;
83 unsigned int nb = 4;
84
85 trace.beginBlock ( "Testing Statistics with saving option ..." );
86
87 Statistic<double> stat(true);
88
89
90 for(unsigned int k=0; k < 100; k++)
91 stat.addValue(99);
92 stat.addValue(88);
93 for(unsigned int k=0; k < 100; k++)
94 stat.addValue(77);
95
96 stat.terminate();
97
98 trace.info() << "Mean value = "<<stat.mean() << std::endl;
99 nbok += (stat.mean()==88) ? 1 : 0;
100 trace.info() << "Variance value = "<<stat.variance()<<std::endl;
101 trace.info() << "Max value = "<<stat.max()<<std::endl;
102 nbok += (stat.max()==99) ? 1 : 0;
103 trace.info() << "Min value = "<<stat.min()<<std::endl;
104 nbok += (stat.min()==77) ? 1 : 0;
105 trace.info() << "Median value = "<<stat.median()<<std::endl;
106 nbok += (stat.median()==88) ? 1 : 0;
107
108 trace.info() << "(" << nbok << "/" << nb << ") "
109 << "true == true" << std::endl;
110 trace.endBlock();
111
112 return nbok == nb;
113}
114
116// Standard services - public :
117
118int main( int argc, char** argv )
119{
120 trace.beginBlock ( "Testing class Statistics" );
121 trace.info() << "Args:";
122 for ( int i = 0; i < argc; ++i )
123 trace.info() << " " << argv[ i ];
124 trace.info() << endl;
125
126 bool res = testStatistics(); // && ... other tests
127 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
128
129 trace.beginBlock ( "Testing class Statistics (with option for saving samples)" );
130 trace.info() << "Args:";
131 for ( int i = 0; i < argc; ++i )
132 trace.info() << " " << argv[ i ];
133 trace.info() << endl;
134
135 bool res2 = testStatisticsSaving(); // && ... other tests
136 trace.emphase() << ( res2 ? "Passed." : "Error." ) << endl;
137
138
139 trace.endBlock();
140 return (res &&res2) ? 0 : 1;
141}
142// //
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition Statistic.h:70
double variance() const
Quantity median()
double mean() const
Quantity max() const
Quantity min() const
void addValue(Quantity v)
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
int main()
Definition testBits.cpp:56
bool testStatistics()
bool testStatisticsSaving()