simple_stats_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (simple_stats test)
2 #include "boost/test/unit_test.hpp"
3 
4 #include "cetlib/simple_stats.h"
5 
6 #include <cmath>
7 
9 
10 BOOST_AUTO_TEST_SUITE(simple_stats_test)
11 
12 BOOST_AUTO_TEST_CASE(default_ctor_test)
13 {
15 
16  BOOST_TEST(s.size() == 0u);
17  BOOST_TEST((std::isinf(s.max()) && s.max() < 0.0));
18  BOOST_TEST((std::isinf(s.min()) && s.min() > 0.0));
19  BOOST_TEST(std::isinf(s.small()));
20  BOOST_TEST(s.sum() == 0.0);
21  BOOST_TEST(s.sumsq() == 0.0);
22 
23  BOOST_TEST(std::isnan(s.mean()));
24  BOOST_TEST(std::isnan(s.rms()));
25  BOOST_TEST(std::isnan(s.rms0()));
26 }
27 
28 BOOST_AUTO_TEST_CASE(value_ctor_test)
29 {
30  double pi = 3.14;
31  simple_stats s(pi);
32 
33  BOOST_TEST(s.size() == 1u);
34  BOOST_TEST(s.max() == pi);
35  BOOST_TEST(s.min() == pi);
36  BOOST_TEST(s.small() == pi);
37  BOOST_TEST(s.sum() == pi);
38  BOOST_TEST(s.sumsq() == pi * pi);
39 
40  BOOST_TEST(s.mean() == pi);
41  BOOST_TEST(std::isnan(s.rms()));
42  BOOST_TEST(std::isnan(s.rms0(1u)));
43 }
44 
46 {
47  double pi = 3.14;
48  simple_stats s(pi);
49  s.sample(-pi);
50 
51  BOOST_TEST(s.size() == 2u);
52  BOOST_TEST(s.max() == pi);
53  BOOST_TEST(s.min() == -pi);
54  BOOST_TEST(s.small() == pi);
55  BOOST_TEST(s.sum() == 0.0);
56  BOOST_TEST(s.sumsq() == 2 * pi * pi);
57 
58  BOOST_TEST(s.mean() == 0.0);
59 }
60 
61 BOOST_AUTO_TEST_SUITE_END()
std::size_t size() const noexcept
Definition: simple_stats.h:35
double small() const noexcept
Definition: simple_stats.h:50
double mean() const noexcept
Definition: simple_stats.cc:46
BOOST_AUTO_TEST_CASE(default_ctor_test)
void sample(double) noexcept
double rms0(std::size_t nparams=0u) const noexcept
Definition: simple_stats.cc:80
double min() const noexcept
Definition: simple_stats.h:45
double max() const noexcept
Definition: simple_stats.h:40
double sum() const noexcept
Definition: simple_stats.h:55
float pi
Definition: units.py:11
double sumsq() const noexcept
Definition: simple_stats.h:60
double rms(std::size_t nparams=1u) const noexcept
Definition: simple_stats.cc:66
static QCString * s
Definition: config.cpp:1042