]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/accumulators/test/moment.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / accumulators / test / moment.cpp
CommitLineData
7c673cae
FG
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#include <boost/test/unit_test.hpp>
7#include <boost/test/floating_point_comparison.hpp>
8#include <boost/accumulators/accumulators.hpp>
9#include <boost/accumulators/statistics/stats.hpp>
10#include <boost/accumulators/statistics/moment.hpp>
11
12using namespace boost;
13using namespace unit_test;
14using namespace accumulators;
15
16///////////////////////////////////////////////////////////////////////////////
17// test_stat
18//
19void test_stat()
20{
21 accumulator_set<int, stats<tag::moment<2> > > acc1;
22
23 acc1(2); // 4
24 acc1(4); // 16
25 acc1(5); // + 25
26 // = 45 / 3 = 15
27
28 BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc1), 1e-5);
29
30 accumulator_set<int, stats<tag::moment<5> > > acc2;
31
32 acc2(2); // 32
33 acc2(3); // 243
34 acc2(4); // 1024
35 acc2(5); // + 3125
36 // = 4424 / 4 = 1106
37
38 BOOST_CHECK_CLOSE(1106., accumulators::moment<5>(acc2), 1e-5);
39}
40
41///////////////////////////////////////////////////////////////////////////////
42// init_unit_test_suite
43//
44test_suite* init_unit_test_suite( int argc, char* argv[] )
45{
46 test_suite *test = BOOST_TEST_SUITE("moment test");
47
48 test->add(BOOST_TEST_CASE(&test_stat));
49
50 return test;
51}
52