Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Histogram.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Histogram.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace std;
22using namespace toolbox;
23
25
27constexpr std::int64_t Highest{3600ULL * 1000 * 1000};
28constexpr std::int32_t Significant{3};
29constexpr auto TestValueLevel = 4;
30[[maybe_unused]] constexpr auto Interval = 10000;
31constexpr auto Bitness = 64;
32
34{
36 const auto expected_bucket_count = Bitness == 64 ? 22 : 21;
37 const auto expected_counts_len = Bitness == 64 ? 23552 : 22528;
38
39 BOOST_CHECK_EQUAL(h.lowest_trackable_value(), Lowest);
40 BOOST_CHECK_EQUAL(h.highest_trackable_value(), Highest);
41 BOOST_CHECK_EQUAL(h.significant_figures(), Significant);
42 BOOST_CHECK_EQUAL(h.sub_bucket_count(), 2048);
45}
46
48{
49 Histogram h{1, 100000000, 1};
50 BOOST_CHECK_EQUAL(h.min(), numeric_limits<int64_t>::max());
51 BOOST_CHECK_EQUAL(h.max(), 0);
52}
53
61
63{
64 BOOST_CHECK_THROW(Histogram(1, 36000000, -1), invalid_argument);
65 BOOST_CHECK_THROW(Histogram(1, 36000000, 0), invalid_argument);
66 BOOST_CHECK_THROW(Histogram(1, 36000000, 6), invalid_argument);
67}
68
70{
71 BOOST_CHECK_THROW(Histogram(0, 64 * 1024, 2), invalid_argument);
72 BOOST_CHECK_THROW(Histogram(80, 110, 5), invalid_argument);
73}
74
76{
77 Histogram h{1, 1000, 4};
78 BOOST_CHECK(h.record_value(32767));
79 BOOST_CHECK(!h.record_value(32768));
80}
81
83{
84 Histogram h{1, 10000000, 3};
85 for (int i{0}; i < 1000; ++i) {
86 BOOST_CHECK(h.record_value(i));
87 }
88 h.reset();
89 BOOST_CHECK_EQUAL(h.max(), 0);
90}
91
93{
94 Histogram h{1, 10000000, 3};
95 for (int i{0}; i < 1000; ++i) {
96 BOOST_CHECK(h.record_value(i));
97 BOOST_CHECK_EQUAL(h.total_count(), i + 1);
98 }
99}
100
102{
104 BOOST_CHECK_EQUAL(8183 * 1024 + 1023, h.highest_equivalent_value(8180 * 1024));
105 BOOST_CHECK_EQUAL(8191 * 1024 + 1023, h.highest_equivalent_value(8191 * 1024));
106 BOOST_CHECK_EQUAL(8199 * 1024 + 1023, h.highest_equivalent_value(8193 * 1024));
107 BOOST_CHECK_EQUAL(9999 * 1024 + 1023, h.highest_equivalent_value(9995 * 1024));
108 BOOST_CHECK_EQUAL(10007 * 1024 + 1023, h.highest_equivalent_value(10007 * 1024));
109 BOOST_CHECK_EQUAL(10015 * 1024 + 1023, h.highest_equivalent_value(10008 * 1024));
110}
111
constexpr auto Bitness
constexpr std::int32_t Significant
BOOST_AUTO_TEST_CASE(HistogramBasicCase)
constexpr std::int64_t Highest
constexpr auto TestValueLevel
constexpr auto Interval
constexpr std::int64_t Lowest
BOOST_CHECK_EQUAL(v.size(), 10U)
A High Dynamic Range (HDR) Histogram.
Definition Histogram.hpp:64
bool record_value(std::int64_t value) noexcept
STL namespace.
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))