Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
hdr
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
21
using namespace
std
;
22
using namespace
toolbox
;
23
24
BOOST_AUTO_TEST_SUITE
(
HistogramSuite
)
25
26
constexpr
std
::
int64_t
Lowest
{1};
27
constexpr
std::int64_t
Highest
{3600ULL * 1000 * 1000};
28
constexpr
std::int32_t
Significant
{3};
29
constexpr
auto
TestValueLevel
= 4;
30
[[
maybe_unused
]]
constexpr
auto
Interval
= 10000;
31
constexpr
auto
Bitness
= 64;
32
33
BOOST_AUTO_TEST_CASE
(
HistogramBasicCase
)
34
{
35
Histogram
h{
Lowest
,
Highest
,
Significant
};
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);
43
BOOST_CHECK_EQUAL
(h.bucket_count(),
expected_bucket_count
);
44
BOOST_CHECK_EQUAL
(h.counts_len(),
expected_counts_len
);
45
}
46
47
BOOST_AUTO_TEST_CASE
(
HistogramEmptyCase
)
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
54
BOOST_AUTO_TEST_CASE
(
HistogramRecordValueCase
)
55
{
56
Histogram
h{
Lowest
,
Highest
,
Significant
};
57
h.
record_value
(
TestValueLevel
);
58
BOOST_CHECK_EQUAL
(h.count_at_value(
TestValueLevel
), 1);
59
BOOST_CHECK_EQUAL
(h.total_count(), 1);
60
}
61
62
BOOST_AUTO_TEST_CASE
(
HistogramInvalidSigFigCase
)
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
69
BOOST_AUTO_TEST_CASE
(
HistogramInvalidInitCase
)
70
{
71
BOOST_CHECK_THROW
(
Histogram
(0, 64 * 1024, 2), invalid_argument);
72
BOOST_CHECK_THROW
(
Histogram
(80, 110, 5), invalid_argument);
73
}
74
75
BOOST_AUTO_TEST_CASE
(
HistogramOutOfRangeCase
)
76
{
77
Histogram
h{1, 1000, 4};
78
BOOST_CHECK
(h.record_value(32767));
79
BOOST_CHECK
(!h.record_value(32768));
80
}
81
82
BOOST_AUTO_TEST_CASE
(
HistogramResetCase
)
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
92
BOOST_AUTO_TEST_CASE
(
HistogramTotalCountCase
)
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
101
BOOST_AUTO_TEST_CASE
(
HistogramRecordEquivalentValueCase
)
102
{
103
Histogram
h{
Lowest
,
Highest
,
Significant
};
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
112
BOOST_AUTO_TEST_SUITE_END
()
Histogram.hpp
Bitness
constexpr auto Bitness
Definition
Histogram.ut.cpp:31
Significant
constexpr std::int32_t Significant
Definition
Histogram.ut.cpp:28
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HistogramBasicCase)
Definition
Histogram.ut.cpp:33
Highest
constexpr std::int64_t Highest
Definition
Histogram.ut.cpp:27
TestValueLevel
constexpr auto TestValueLevel
Definition
Histogram.ut.cpp:29
Interval
constexpr auto Interval
Definition
Histogram.ut.cpp:30
Lowest
constexpr std::int64_t Lowest
Definition
Histogram.ut.cpp:26
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(v.size(), 10U)
toolbox::Histogram
A High Dynamic Range (HDR) Histogram.
Definition
Histogram.hpp:64
toolbox::hdr::Histogram::record_value
bool record_value(std::int64_t value) noexcept
Definition
Histogram.cpp:207
std
STL namespace.
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
BOOST_CHECK
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))
Generated by
1.9.8