Repository navigation
Expand file tree
/
Copy pathhistogram_mixed_test.cpp
More file actions
91 lines (82 loc) · 2.77 KB
/
Copy pathhistogram_mixed_test.cpp
File metadata and controls
91 lines (82 loc) · 2.77 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2015-2017 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/axis/integer.hpp>
#include <boost/histogram/axis/ostream.hpp>
#include <boost/histogram/axis/regular.hpp>
#include <boost/histogram/histogram.hpp>
#include <boost/histogram/literals.hpp>
#include <boost/histogram/ostream.hpp>
#include <boost/histogram/storage_adaptor.hpp>
#include <boost/histogram/unlimited_storage.hpp>
#include <vector>
#include "histogram.hpp"
#include "throw_exception.hpp"
using namespace boost::histogram;
template <typename T1, typename T2>
void run_tests() {
// compare
{
auto a = make(T1{}, axis::regular<>{3, 0, 3}, axis::integer<>(0, 2));
auto b = make_s(T2{}, std::vector<unsigned>(), axis::regular<>{3, 0, 3},
axis::integer<>(0, 2));
BOOST_TEST_EQ(a, b);
auto b2 = make(T2{}, axis::integer<>{0, 3}, axis::integer<>(0, 2));
BOOST_TEST_NE(a, b2);
auto b3 = make(T2{}, axis::regular<>(3, 0, 4), axis::integer<>(0, 2));
BOOST_TEST_NE(a, b3);
}
// operators
{
auto a = make(T1{}, axis::integer<int, use_default, axis::option::none_t>{0, 2});
auto b = make(T2{}, axis::integer<int, use_default, axis::option::none_t>{0, 2});
BOOST_TEST_EQ(a, b);
a(0); // 1 0
b(1); // 0 1
a += b;
BOOST_TEST_EQ(a[0], 1);
BOOST_TEST_EQ(a[1], 1);
a *= b;
BOOST_TEST_EQ(a[0], 0);
BOOST_TEST_EQ(a[1], 1);
a -= b;
BOOST_TEST_EQ(a[0], 0);
BOOST_TEST_EQ(a[1], 0);
a[0] = 2;
a[1] = 4;
b[0] = 2;
b[1] = 2;
a /= b;
BOOST_TEST_EQ(a[0], 1);
BOOST_TEST_EQ(a[1], 2);
BOOST_TEST_THROWS(a += make(T2{}, axis::integer<>{0, 3}), std::invalid_argument);
BOOST_TEST_THROWS(a -= make(T2{}, axis::integer<>{0, 3}), std::invalid_argument);
BOOST_TEST_THROWS(a *= make(T2{}, axis::integer<>{0, 3}), std::invalid_argument);
BOOST_TEST_THROWS(a /= make(T2{}, axis::integer<>{0, 3}), std::invalid_argument);
}
// copy_assign
{
auto a = make(T1{}, axis::regular<>{3, 0, 3}, axis::integer<>{0, 2});
auto b = make_s(T2{}, std::vector<double>(), axis::regular<>{3, 0, 3},
axis::integer<>{0, 2});
a(1, 1);
BOOST_TEST_NE(a, b);
b = a;
BOOST_TEST_EQ(a, b);
}
}
int main() {
run_tests<static_tag, dynamic_tag>();
run_tests<dynamic_tag, static_tag>();
// copy assign
{
auto a = make(static_tag{}, axis::regular<>{3, 0, 3}, axis::integer<>{0, 2});
auto b = make(dynamic_tag{}, axis::regular<>{3, 0, 3}, axis::regular<>{2, 0, 2},
axis::integer<>{0, 2});
BOOST_TEST_THROWS(a = b, std::invalid_argument);
}
return boost::report_errors();
}