File: accumulators_count_test.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (71 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2015-2018 Hans Dembinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/accumulators/count.hpp>
#include <boost/histogram/accumulators/ostream.hpp>
#include "str.hpp"
#include "throw_exception.hpp"

using namespace boost::histogram;
using namespace std::literals;

template <class T, bool B>
void run_tests() {
  using c_t = accumulators::count<T, B>;

  {
    c_t c;
    ++c;
    BOOST_TEST_EQ(c.value(), static_cast<T>(1));
    BOOST_TEST_EQ(str(c), "1"s);
    BOOST_TEST_EQ(str(c, 2, false), " 1"s);
    BOOST_TEST_EQ(str(c, 2, true), "1 "s);

    c += 2;
    BOOST_TEST_EQ(str(c), "3"s);

    BOOST_TEST_EQ(c, static_cast<T>(3));
    BOOST_TEST_NE(c, static_cast<T>(2));
  }

  {
    c_t one(1), two(2), one_copy(1);
    BOOST_TEST_LT(one, two);
    BOOST_TEST_LE(one, two);
    BOOST_TEST_LE(one, one_copy);
    BOOST_TEST_GT(two, one);
    BOOST_TEST_GE(two, one);
    BOOST_TEST_GE(one, one_copy);
  }

  BOOST_TEST_EQ(c_t{} += c_t{}, c_t{});

  {
    c_t two(2);
    auto six = two * 3;
    BOOST_TEST_EQ(six, static_cast<T>(6));
    six *= 2;
    BOOST_TEST_EQ(six, static_cast<T>(12));
  }

  {
    c_t six(6);
    auto two = six / 3;
    BOOST_TEST_EQ(two, static_cast<T>(2));
    two /= 2;
    BOOST_TEST_EQ(two, static_cast<T>(1));
  }
}

int main() {
  run_tests<int, false>();
  run_tests<int, true>();
  run_tests<float, false>();
  run_tests<float, true>();

  return boost::report_errors();
}