Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Math.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 "Math.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace std;
22using namespace toolbox;
23
24namespace utf = boost::unit_test;
25
27
48
49BOOST_AUTO_TEST_CASE(VarAccumCase, *utf::tolerance(0.0000001))
50{
51 VarAccum v;
52 v.append(1345, 1301, 1368, 1322, 1310, 1370, 1318, 1350, 1303, 1299);
53 BOOST_CHECK_EQUAL(v.size(), 10U);
54 BOOST_CHECK_EQUAL(v.mean(), 1328.6);
55 BOOST_CHECK_CLOSE_FRACTION(var(v), 754.2666667, 1e-7);
57 BOOST_CHECK_CLOSE_FRACTION(stdev(v), 27.4639157, 1e-7);
58 BOOST_CHECK_CLOSE_FRACTION(stdevp(v), 26.0545581, 1e-7);
59 BOOST_CHECK_EQUAL(v.min(), 1299);
60 BOOST_CHECK_EQUAL(v.max(), 1370);
61}
62
64{
65 BOOST_CHECK_EQUAL(ceil(1U, 3U), 1U);
66 BOOST_CHECK_EQUAL(ceil(2U, 3U), 1U);
67 BOOST_CHECK_EQUAL(ceil(3U, 3U), 1U);
68 BOOST_CHECK_EQUAL(ceil(4U, 3U), 2U);
69 BOOST_CHECK_EQUAL(ceil(5U, 3U), 2U);
70 BOOST_CHECK_EQUAL(ceil(6U, 3U), 2U);
71}
72
BOOST_CHECK_CLOSE_FRACTION(var(v), 754.2666667, 1e-7)
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(NextPow2Case)
Definition Math.ut.cpp:28
void append(double val) noexcept
Definition Math.hpp:81
STL namespace.
double var(const VarAccum &v) noexcept
Definition Math.hpp:106
double stdevp(const VarAccum &v) noexcept
Definition Math.hpp:121
unsigned next_pow2(unsigned n) noexcept
Definition Math.hpp:35
double varp(const VarAccum &v) noexcept
Definition Math.hpp:111
constexpr std::size_t ceil(std::size_t dividend, std::size_t divisor) noexcept
Definition Math.hpp:150
double stdev(const VarAccum &v) noexcept
Definition Math.hpp:116
constexpr auto bind() noexcept
Definition Slot.hpp:92