Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
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
24using namespace std;
25using namespace toolbox;
26
27namespace utf = boost::unit_test;
28
30
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
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 }
53}
54
56{
57 Histogram h{1, 100000, 3};
60}
61
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
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
BOOST_CHECK_EQUAL(v.size(), 10U)
A High Dynamic Range (HDR) Histogram.
Definition Histogram.hpp:64
BOOST_AUTO_TEST_CASE(CreateWithLargeValuesCase)
STL namespace.
double mean(const Histogram &h) noexcept
Definition Utility.cpp:66
int64_t value_at_percentile(const Histogram &h, double percentile) noexcept
Definition Utility.cpp:51
double stddev(const Histogram &h) noexcept
Definition Utility.cpp:80
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))