17 #define BOOST_TEST_MODULE ( ChiSquareAccumulator_test ) 18 #include "boost/test/unit_test.hpp" 24 #include <type_traits> 31 auto one = [](double){
return 1.0; };
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);
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);
43 chiSquare.add(1.0, 1.0);
44 BOOST_TEST(chiSquare.N() == 1U);
45 BOOST_TEST(chiSquare() == 0, 1
e-5%
tolerance());
46 BOOST_TEST(
double(chiSquare) == 0, 1
e-5%
tolerance());
47 BOOST_TEST(chiSquare.chiSquare() == 0, 1
e-5%
tolerance());
49 chiSquare.add(2.0, 0.5);
50 BOOST_TEST(chiSquare.N() == 2U);
51 BOOST_TEST(chiSquare() == 0.25, 1
e-4%
tolerance());
52 BOOST_TEST(
double(chiSquare) == 0.25, 1
e-4%
tolerance());
53 BOOST_TEST(chiSquare.chiSquare() == 0.25, 1
e-4%
tolerance());
55 chiSquare.add(3.0, 2.0, 0.5);
56 BOOST_TEST(chiSquare.N() == 3U);
57 BOOST_TEST(chiSquare() == 4.25, 1
e-4%
tolerance());
58 BOOST_TEST(
double(chiSquare) == 4.25, 1
e-4%
tolerance());
59 BOOST_TEST(chiSquare.chiSquare() == 4.25, 1
e-4%
tolerance());
83 double const b = -1.0;
84 auto f = [
a,
b](
double x){
return a + b *
x; };
87 chiSquare.
add(0.0, 1.0, 0.5);
88 chiSquare.
add(1.0, 1.0, 0.5);
89 chiSquare.
add(2.0, 1.0, 0.5);
91 double const chi2value = chiSquare();
92 int degreesOfFreedom = chiSquare.
N() - 3;
94 BOOST_TEST(chi2value == 8.0, 0.001%
tolerance());
95 BOOST_TEST(degreesOfFreedom == 0U);
111 auto zero = [](double){
return 0.0; };
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!" 135 auto zero = [](
float){
return 0.0F; };
136 auto chiSquare = lar::util::makeChiSquareAccumulator<float>(zero);
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!" auto makeChiSquareAccumulator(F &&e)
Creates a ChiSquareAccumulator object with the specified function.
Computes a χ² from expectation function and data points.
void testChiSquareAccumulator()
void add(Data_t x, Data_t y)
Adds a data point to the χ².
BOOST_AUTO_TEST_CASE(ChiSquareAccumulatorTestCase)
void testChiSquareAccumulator_documentation()
void testMakeChiSquareAccumulator_documentation2()
void testMakeChiSquareAccumulator_documentation1()
Computes a simple χ² sum from data and a expectation function.
unsigned int N() const
Returns the number of added points (it's not degrees of freedom yet!).