]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/histogram/test/accumulators_count_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / histogram / test / accumulators_count_test.cpp
CommitLineData
f67539c2
TL
1// Copyright 2015-2018 Hans Dembinski
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt
5// or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#include <boost/core/lightweight_test.hpp>
8#include <boost/histogram/accumulators/count.hpp>
9#include <boost/histogram/accumulators/ostream.hpp>
10#include "throw_exception.hpp"
11#include "utility_str.hpp"
12
13using namespace boost::histogram;
14using namespace std::literals;
15
1e59de90
TL
16template <class T, bool B>
17void run_tests() {
18 using c_t = accumulators::count<T, B>;
f67539c2 19
1e59de90
TL
20 {
21 c_t c;
22 ++c;
23 BOOST_TEST_EQ(c.value(), 1);
24 BOOST_TEST_EQ(str(c), "1"s);
25 BOOST_TEST_EQ(str(c, 2, false), " 1"s);
26 BOOST_TEST_EQ(str(c, 2, true), "1 "s);
f67539c2 27
1e59de90
TL
28 c += 2;
29 BOOST_TEST_EQ(str(c), "3"s);
f67539c2 30
1e59de90
TL
31 BOOST_TEST_EQ(c, static_cast<T>(3));
32 BOOST_TEST_NE(c, static_cast<T>(2));
33 }
f67539c2 34
1e59de90
TL
35 {
36 c_t one(1), two(2), one_copy(1);
37 BOOST_TEST_LT(one, two);
38 BOOST_TEST_LE(one, two);
39 BOOST_TEST_LE(one, one_copy);
40 BOOST_TEST_GT(two, one);
41 BOOST_TEST_GE(two, one);
42 BOOST_TEST_GE(one, one_copy);
43 }
f67539c2
TL
44
45 BOOST_TEST_EQ(c_t{} += c_t{}, c_t{});
46
1e59de90
TL
47 {
48 c_t two(2);
49 auto six = two * 3;
50 BOOST_TEST_EQ(six, static_cast<T>(6));
51 six *= 2;
52 BOOST_TEST_EQ(six, static_cast<T>(12));
53 }
54
55 {
56 c_t six(6);
57 auto two = six / 3;
58 BOOST_TEST_EQ(two, static_cast<T>(2));
59 two /= 2;
60 BOOST_TEST_EQ(two, static_cast<T>(1));
61 }
62}
63
64int main() {
65 run_tests<int, false>();
66 run_tests<int, true>();
67 run_tests<float, false>();
68 run_tests<float, true>();
69
f67539c2
TL
70 return boost::report_errors();
71}