Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
hdr
Utility.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) 2022 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 "
Utility.hpp
"
18
#include "
Histogram.hpp
"
19
20
#include <boost/test/unit_test.hpp>
21
22
#include <cmath>
23
24
using namespace
std
;
25
using namespace
toolbox
;
26
27
namespace
utf
= boost::unit_test;
28
29
BOOST_AUTO_TEST_SUITE
(
UtilitySuite
)
30
31
BOOST_AUTO_TEST_CASE
(
CreateWithLargeValuesCase
)
32
{
33
Histogram
h{20000000, 100000000, 5};
34
BOOST_CHECK
(h.record_value(100000000));
35
BOOST_CHECK
(h.record_value(20000000));
36
BOOST_CHECK
(h.record_value(30000000));
37
38
BOOST_CHECK
(h.values_are_equivalent(
value_at_percentile
(h, 50.0), 20000000));
39
BOOST_CHECK
(h.values_are_equivalent(
value_at_percentile
(h, 83.33), 30000000));
40
BOOST_CHECK
(h.values_are_equivalent(
value_at_percentile
(h, 83.34), 100000000));
41
BOOST_CHECK
(h.values_are_equivalent(
value_at_percentile
(h, 99.0), 100000000));
42
}
43
44
BOOST_AUTO_TEST_CASE
(
HighSignificantFiguresCase
)
45
{
46
const
std::initializer_list<int64_t>
vals
{459876, 669187, 711612, 816326, 931423,
47
1033197, 1131895, 2477317, 3964974, 12718782};
48
Histogram
h{459876, 12718782, 5};
49
for
(
const
auto
val
:
vals
) {
50
BOOST_CHECK
(h.record_value(
val
));
51
}
52
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 50), 1048575);
53
}
54
55
BOOST_AUTO_TEST_CASE
(
NaNCase
)
56
{
57
Histogram
h{1, 100000, 3};
58
BOOST_CHECK
(
isnan
(
mean
(h)));
59
BOOST_CHECK
(
isnan
(
stddev
(h)));
60
}
61
62
BOOST_AUTO_TEST_CASE
(
StatsCase
)
63
{
64
Histogram
h{1, 100000, 4};
65
for
(
int
i
{1};
i
<= 100000; ++
i
) {
66
BOOST_CHECK
(h.record_value(
i
));
67
}
68
69
BOOST_CHECK_EQUAL
(h.min(), 1);
70
BOOST_CHECK_EQUAL
(h.max(), 100003);
71
72
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 50), 50001);
73
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 75), 75003);
74
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 90), 90003);
75
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 95), 95003);
76
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 99), 99003);
77
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 99.9), 99903);
78
BOOST_CHECK_EQUAL
(
value_at_percentile
(h, 99.99), 99991);
79
80
BOOST_CHECK_EQUAL
(
mean
(h), 50000.836179999998);
81
BOOST_CHECK_EQUAL
(
stddev
(h), 28867.704262911586);
82
}
83
84
BOOST_AUTO_TEST_SUITE_END
()
Histogram.hpp
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(v.size(), 10U)
toolbox::Histogram
A High Dynamic Range (HDR) Histogram.
Definition
Histogram.hpp:64
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(CreateWithLargeValuesCase)
Definition
Utility.ut.cpp:31
std
STL namespace.
toolbox::hdr::mean
double mean(const Histogram &h) noexcept
Definition
Utility.cpp:66
toolbox::hdr::value_at_percentile
int64_t value_at_percentile(const Histogram &h, double percentile) noexcept
Definition
Utility.cpp:51
toolbox::hdr::stddev
double stddev(const Histogram &h) noexcept
Definition
Utility.cpp:80
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
Utility.hpp
BOOST_CHECK
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))
Generated by
1.9.8