DGtal  1.0.0
Functions
testStatistics.cpp File Reference
#include <iostream>
#include <vector>
#include "DGtal/math/Statistic.h"
Include dependency graph for testStatistics.cpp:

Go to the source code of this file.

Functions

bool testStatistics ()
 
bool testStatisticsSaving ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/06/24

Functions for testing class Statistics.

This file is part of the DGtal library.

Definition in file testStatistics.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 118 of file testStatistics.cpp.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
std::ostream & emphase()
bool testStatisticsSaving()
std::ostream & info()
bool testStatistics()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testStatistics(), testStatisticsSaving(), and DGtal::trace.

◆ testStatistics()

bool testStatistics ( )

Example of a test. To be completed.

Definition at line 47 of file testStatistics.cpp.

48 {
49  unsigned int nbok = 0;
50  unsigned int nb = 3;
51 
52  trace.beginBlock ( "Testing Statistics ..." );
53 
54  Statistic<double> stat;
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;
71  trace.endBlock();
72 
73  return nbok == nb;
74 }
void beginBlock(const std::string &keyword="")
double variance() const
Trace trace
Definition: Common.h:144
double mean() const
double endBlock()
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:69
void addValue(Quantity v)
std::ostream & info()
Quantity min() const
Quantity max() const

References DGtal::Statistic< TQuantity >::addValue(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Statistic< TQuantity >::max(), DGtal::Statistic< TQuantity >::mean(), DGtal::Statistic< TQuantity >::min(), DGtal::Statistic< TQuantity >::terminate(), DGtal::trace, and DGtal::Statistic< TQuantity >::variance().

Referenced by main().

◆ testStatisticsSaving()

bool testStatisticsSaving ( )

Example of a test. To be completed.

Definition at line 80 of file testStatistics.cpp.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:69
std::ostream & info()

References DGtal::Statistic< TQuantity >::addValue(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Statistic< TQuantity >::max(), DGtal::Statistic< TQuantity >::mean(), DGtal::Statistic< TQuantity >::median(), DGtal::Statistic< TQuantity >::min(), DGtal::Statistic< TQuantity >::terminate(), DGtal::trace, and DGtal::Statistic< TQuantity >::variance().

Referenced by main().