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) |
5 | |
6 | // Test case for extended_p_square.hpp |
7 | |
8 | #include <iostream> |
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> |
18 | |
19 | using namespace boost; |
20 | using namespace unit_test; |
21 | using namespace boost::accumulators; |
22 | |
23 | /////////////////////////////////////////////////////////////////////////////// |
24 | // test_stat |
25 | // |
26 | void test_stat() |
27 | { |
28 | typedef accumulator_set<double, stats<tag::extended_p_square> > accumulator_t; |
29 | |
30 | // tolerance |
31 | double epsilon = 3; |
32 | |
33 | // a random number generator |
34 | boost::lagged_fibonacci607 rng; |
35 | |
36 | std::vector<double> probs; |
37 | |
38 | probs.push_back(x: 0.001); |
39 | probs.push_back(x: 0.01 ); |
40 | probs.push_back(x: 0.1 ); |
41 | probs.push_back(x: 0.25 ); |
42 | probs.push_back(x: 0.5 ); |
43 | probs.push_back(x: 0.75 ); |
44 | probs.push_back(x: 0.9 ); |
45 | probs.push_back(x: 0.99 ); |
46 | probs.push_back(x: 0.999); |
47 | |
48 | accumulator_t acc(extended_p_square_probabilities = probs); |
49 | |
50 | for (int i=0; i<10000; ++i) |
51 | acc(rng()); |
52 | |
53 | BOOST_CHECK_GE(extended_p_square(acc)[0], 0.0005); |
54 | BOOST_CHECK_LE(extended_p_square(acc)[0], 0.0015); |
55 | BOOST_CHECK_CLOSE(extended_p_square(acc)[1], probs[1], 15); |
56 | BOOST_CHECK_CLOSE(extended_p_square(acc)[2], probs[2], 5); |
57 | |
58 | for (std::size_t i=3; i<probs.size(); ++i) |
59 | { |
60 | BOOST_CHECK_CLOSE(extended_p_square(acc)[i], probs[i], epsilon); |
61 | } |
62 | } |
63 | |
64 | /////////////////////////////////////////////////////////////////////////////// |
65 | // init_unit_test_suite |
66 | // |
67 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
68 | { |
69 | test_suite *test = BOOST_TEST_SUITE("extended_p_square test" ); |
70 | |
71 | test->add(BOOST_TEST_CASE(&test_stat)); |
72 | |
73 | return test; |
74 | } |
75 | |
76 | |