Macros | Functions
ChiSquareAccumulator_test.cc File Reference

Tests the classes in ChiSquareAccumulator.h More...

#include "boost/test/unit_test.hpp"
#include "lardata/Utilities/ChiSquareAccumulator.h"
#include <type_traits>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( ChiSquareAccumulator_test )
 

Functions

void testChiSquareAccumulator ()
 
void testChiSquareAccumulator_documentation ()
 
void testMakeChiSquareAccumulator_documentation1 ()
 
void testMakeChiSquareAccumulator_documentation2 ()
 
 BOOST_AUTO_TEST_CASE (ChiSquareAccumulatorTestCase)
 

Detailed Description

Tests the classes in ChiSquareAccumulator.h

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
July 26, 2018
Version
1.0
See also
lardata/Utilities/ChiSquareAccumulator.h

See http://www.boost.org/libs/test for the Boost test library home page.

Timing: not given yet

Definition in file ChiSquareAccumulator_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( ChiSquareAccumulator_test )

Definition at line 17 of file ChiSquareAccumulator_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( ChiSquareAccumulatorTestCase  )

Definition at line 149 of file ChiSquareAccumulator_test.cc.

149  {
150 
155 
156 } // ChiSquareAccumulatorTestCase
void testChiSquareAccumulator()
void testChiSquareAccumulator_documentation()
void testMakeChiSquareAccumulator_documentation2()
void testMakeChiSquareAccumulator_documentation1()
void testChiSquareAccumulator ( )

Definition at line 29 of file ChiSquareAccumulator_test.cc.

29  {
30 
31  auto one = [](double){ return 1.0; };
32  auto chiSquare = lar::util::makeChiSquareAccumulator(one);
33 
34  BOOST_TEST(chiSquare.expected(1.0) == 1.0);
35  BOOST_TEST(chiSquare.expected(2.0) == 1.0);
36  BOOST_TEST(chiSquare.expected(3.0) == 1.0);
37 
38  BOOST_TEST(chiSquare.N() == 0U);
39  BOOST_TEST(chiSquare() == 0.0);
40  BOOST_TEST(double(chiSquare) == 0.0);
41  BOOST_TEST(chiSquare.chiSquare() == 0.0);
42 
43  chiSquare.add(1.0, 1.0); // uncertainty: 1
44  BOOST_TEST(chiSquare.N() == 1U);
45  BOOST_TEST(chiSquare() == 0, 1e-5% tolerance());
46  BOOST_TEST(double(chiSquare) == 0, 1e-5% tolerance());
47  BOOST_TEST(chiSquare.chiSquare() == 0, 1e-5% tolerance());
48 
49  chiSquare.add(2.0, 0.5); // uncertainty: 1
50  BOOST_TEST(chiSquare.N() == 2U);
51  BOOST_TEST(chiSquare() == 0.25, 1e-4% tolerance());
52  BOOST_TEST(double(chiSquare) == 0.25, 1e-4% tolerance());
53  BOOST_TEST(chiSquare.chiSquare() == 0.25, 1e-4% tolerance());
54 
55  chiSquare.add(3.0, 2.0, 0.5);
56  BOOST_TEST(chiSquare.N() == 3U);
57  BOOST_TEST(chiSquare() == 4.25, 1e-4% tolerance());
58  BOOST_TEST(double(chiSquare) == 4.25, 1e-4% tolerance());
59  BOOST_TEST(chiSquare.chiSquare() == 4.25, 1e-4% tolerance());
60 
61 } // testChiSquareAccumulator()
auto makeChiSquareAccumulator(F &&e)
Creates a ChiSquareAccumulator object with the specified function.
auto const tolerance
const double e
void testChiSquareAccumulator_documentation ( )

Definition at line 65 of file ChiSquareAccumulator_test.cc.

65  {
66  /*
67  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
68  * double const a = 2.0;
69  * double const b = -1.0;
70  * auto f = [a,b](double x){ return a + b * x; };
71  * lar::util::ChiSquareAccumulator<decltype(f)> chiSquare;
72  *
73  * chiSquare.add(0.0, 1.0, 0.5); // add ( 0 ; 1.0 +/- 0.5 )
74  * chiSquare.add(1.0, 1.0, 0.5); // add ( 1 ; 1.0 +/- 0.5 )
75  * chiSquare.add(2.0, 1.0, 0.5); // add ( 2 ; 1.0 +/- 0.5 )
76  *
77  * double const chi2value = chiSquare();
78  * int degreesOfFreedom = int(chiSquare.N()) - 3;
79  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80  * promised `chi2value` `8.0` and `degreeOfFreedom` `0`.
81  */
82  double const a = 2.0;
83  double const b = -1.0;
84  auto f = [a,b](double x){ return a + b * x; };
86 
87  chiSquare.add(0.0, 1.0, 0.5); // add ( 0 ; 1.0 +/- 0.5 )
88  chiSquare.add(1.0, 1.0, 0.5); // add ( 1 ; 1.0 +/- 0.5 )
89  chiSquare.add(2.0, 1.0, 0.5); // add ( 2 ; 1.0 +/- 0.5 )
90 
91  double const chi2value = chiSquare();
92  int degreesOfFreedom = chiSquare.N() - 3;
93 
94  BOOST_TEST(chi2value == 8.0, 0.001% tolerance());
95  BOOST_TEST(degreesOfFreedom == 0U);
96 
97 } // testChiSquareAccumulator_documentation();
Computes a χ² from expectation function and data points.
auto const tolerance
const double a
static bool * b
Definition: config.cpp:1043
list x
Definition: train.py:276
void testMakeChiSquareAccumulator_documentation1 ( )

Definition at line 101 of file ChiSquareAccumulator_test.cc.

101  {
102 
103  /*
104  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
105  * auto zero = [](double){ return 0.0; }; // expectation function
106  * auto chiSquare = lar::util::makeChiSquareAccumulator(zero);
107  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108  * declare `chiSquare` in a way equivalent to:
109  * `lar::util::ChiSquareAccumulator<decltype(zero)> chiSquare(zero)`.
110  */
111  auto zero = [](double){ return 0.0; }; // expectation function
112  auto const& chiSquare = lar::util::makeChiSquareAccumulator(zero);
113 
114  BOOST_TEST(chiSquare.expected(-2.0) == 0.0);
115  BOOST_TEST(chiSquare.expected(0.0) == 0.0);
116  BOOST_TEST(chiSquare.expected(2.0) == 0.0);
117  static_assert(std::is_same<decltype(chiSquare()), double>::value,
118  "makeChiSquareAccumulator() returned an unexpected type!"
119  );
120 
121 } // testMakeChiSquareAccumulator_documentation1()
auto makeChiSquareAccumulator(F &&e)
Creates a ChiSquareAccumulator object with the specified function.
void testMakeChiSquareAccumulator_documentation2 ( )

Definition at line 125 of file ChiSquareAccumulator_test.cc.

125  {
126 
127  /*
128  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
129  * auto zero = [](float){ return 0.0F; }; // expectation function
130  * auto chiSquare = lar::util::makeChiSquareAccumulator<float>(zero);
131  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132  * declare `chiSquare` in a way equivalent to:
133  * `lar::util::ChiSquareAccumulator<decltype(zero), float> chiSquare(zero)`.
134  */
135  auto zero = [](float){ return 0.0F; }; // expectation function
136  auto chiSquare = lar::util::makeChiSquareAccumulator<float>(zero);
137 
138  BOOST_TEST(chiSquare.expected(-2.0F) == 0.0F);
139  BOOST_TEST(chiSquare.expected(0.0F) == 0.0F);
140  BOOST_TEST(chiSquare.expected(2.0F) == 0.0F);
141  static_assert(std::is_same<decltype(chiSquare()), float>::value,
142  "makeChiSquareAccumulator<float>() returned an unexpected type!"
143  );
144 
145 } // testMakeChiSquareAccumulator_documentation2()