1 // (C) Copyright Eric Niebler 2005.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // Test case for extended_p_square.hpp
9 #include <boost/random.hpp>
10 #include <boost/test/unit_test.hpp>
11 #include <boost/test/floating_point_comparison.hpp>
12 #include <boost/accumulators/numeric/functional/vector.hpp>
13 #include <boost/accumulators/numeric/functional/complex.hpp>
14 #include <boost/accumulators/numeric/functional/valarray.hpp>
15 #include <boost/accumulators/accumulators.hpp>
16 #include <boost/accumulators/statistics/stats.hpp>
17 #include <boost/accumulators/statistics/extended_p_square.hpp>
19 #include <boost/archive/text_oarchive.hpp>
20 #include <boost/archive/text_iarchive.hpp>
22 using namespace boost
;
23 using namespace unit_test
;
24 using namespace boost::accumulators
;
26 typedef accumulator_set
<double, stats
<tag::extended_p_square
> > accumulator_t
;
28 ///////////////////////////////////////////////////////////////////////////////
37 // a random number generator
38 boost::lagged_fibonacci607 rng
;
40 std::vector
<double> probs
;
42 probs
.push_back(0.001);
43 probs
.push_back(0.01 );
44 probs
.push_back(0.1 );
45 probs
.push_back(0.25 );
46 probs
.push_back(0.5 );
47 probs
.push_back(0.75 );
48 probs
.push_back(0.9 );
49 probs
.push_back(0.99 );
50 probs
.push_back(0.999);
52 accumulator_t
acc(extended_p_square_probabilities
= probs
);
54 for (int i
=0; i
<10000; ++i
)
57 BOOST_CHECK_GE(extended_p_square(acc
)[0], 0.0005);
58 BOOST_CHECK_LE(extended_p_square(acc
)[0], 0.0015);
59 BOOST_CHECK_CLOSE(extended_p_square(acc
)[1], probs
[1], 15);
60 BOOST_CHECK_CLOSE(extended_p_square(acc
)[2], probs
[2], 5);
62 for (std::size_t i
=3; i
<probs
.size(); ++i
)
64 BOOST_CHECK_CLOSE(extended_p_square(acc
)[i
], probs
[i
], epsilon
);
68 ///////////////////////////////////////////////////////////////////////////////
71 void test_persistency()
73 // "persistent" storage
77 std::vector
<double> probs
;
78 probs
.push_back(0.75);
80 accumulator_t
acc(extended_p_square_probabilities
= probs
);
81 // a random number generator
82 boost::lagged_fibonacci607 rng
;
84 for (int i
=0; i
<10000; ++i
)
87 BOOST_CHECK_CLOSE(extended_p_square(acc
)[0], probs
[0], epsilon
);
88 boost::archive::text_oarchive
oa(ss
);
91 accumulator_t
acc(extended_p_square_probabilities
= probs
);
92 boost::archive::text_iarchive
ia(ss
);
94 BOOST_CHECK_CLOSE(extended_p_square(acc
)[0], probs
[0], epsilon
);
98 ///////////////////////////////////////////////////////////////////////////////
99 // init_unit_test_suite
101 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
103 test_suite
*test
= BOOST_TEST_SUITE("extended_p_square test");
105 test
->add(BOOST_TEST_CASE(&test_stat
));
106 test
->add(BOOST_TEST_CASE(&test_persistency
));