]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-dns_random_hh.cc
Merge pull request #1896 from tuxis-ie/mysql-foreign-keys
[thirdparty/pdns.git] / pdns / test-dns_random_hh.cc
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_NO_MAIN
3
4 // Disable this code for gcc 4.8 and lower
5 #if (__GNUC__ == 4 && __GNUC_MINOR__ > 8) || !__GNUC__
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/std/map.hpp>
12
13 #include <boost/accumulators/statistics/median.hpp>
14 #include <boost/accumulators/statistics/mean.hpp>
15 #include <boost/accumulators/accumulators.hpp>
16 #include <boost/accumulators/statistics.hpp>
17
18 #include "dns_random.hh"
19 #include "namespaces.hh"
20
21
22 using namespace boost;
23 using namespace boost::accumulators;
24
25 typedef accumulator_set<
26 double
27 , stats<boost::accumulators::tag::median(with_p_square_quantile),
28 boost::accumulators::tag::mean(immediate)
29 >
30 > acc_t;
31
32
33
34 BOOST_AUTO_TEST_SUITE(test_dns_random_hh)
35
36
37
38 BOOST_AUTO_TEST_CASE(test_dns_random_average) {
39
40 dns_random_init("loremipsumdolorx");
41 acc_t acc;
42
43 for(unsigned int n=0; n < 100000; ++n) {
44 acc(dns_random(100000)/100000.0);
45 }
46 BOOST_CHECK_CLOSE(0.5, median(acc), 2.0); // within 2%
47 BOOST_CHECK_CLOSE(0.5, mean(acc), 2.0);
48
49
50 // please add covariance tests, chi-square, Kolmogorov-Smirnov
51 }
52
53
54
55 BOOST_AUTO_TEST_SUITE_END()
56
57 #endif