2020-05-25 02:33:45 +03:00
|
|
|
// The MIT License (MIT)
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Mateusz Pusz
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
2022-09-01 16:19:51 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2024-07-16 17:36:00 +02:00
|
|
|
#ifdef MP_UNITS_IMPORT_STD
|
|
|
|
import std;
|
|
|
|
#else
|
2021-03-30 13:21:05 +02:00
|
|
|
#include <array>
|
2024-04-24 20:53:54 +02:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2021-03-30 13:21:05 +02:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <random>
|
|
|
|
#include <vector>
|
2024-07-16 17:36:00 +02:00
|
|
|
#endif
|
2024-01-06 08:51:00 +01:00
|
|
|
#ifdef MP_UNITS_MODULES
|
|
|
|
import mp_units;
|
|
|
|
#else
|
|
|
|
#include <mp-units/random.h>
|
2024-04-24 20:53:54 +02:00
|
|
|
#include <mp-units/systems/isq/space_and_time.h>
|
2024-04-25 16:30:52 +02:00
|
|
|
#include <mp-units/systems/si.h>
|
2024-01-06 08:51:00 +01:00
|
|
|
#endif
|
2021-03-30 13:21:05 +02:00
|
|
|
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2022-12-29 20:18:48 +01:00
|
|
|
using namespace mp_units;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
TEST_CASE("distributions", "[random][distribution]")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("uniform_int_distribution")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::uniform_int_distribution<q>();
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.a() == q::zero());
|
|
|
|
CHECK(dist.b() == q::max());
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep a = 2;
|
|
|
|
constexpr rep b = 5;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::uniform_int_distribution(a, b);
|
|
|
|
auto units_dist = mp_units::uniform_int_distribution(a * si::metre, b * si::metre);
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.a() == stl_dist.a() * si::metre);
|
|
|
|
CHECK(units_dist.b() == stl_dist.b() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("uniform_real_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::uniform_real_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.a() == q::zero());
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.b() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep a = 2.0;
|
|
|
|
constexpr rep b = 5.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::uniform_real_distribution(a, b);
|
|
|
|
auto units_dist = mp_units::uniform_real_distribution(a * si::metre, b * si::metre);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.a() == stl_dist.a() * si::metre);
|
|
|
|
CHECK(units_dist.b() == stl_dist.b() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("binomial_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::binomial_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.p() == 0.5);
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.t() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep t = 5;
|
|
|
|
constexpr double p = 0.25;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::binomial_distribution(t, p);
|
|
|
|
auto units_dist = mp_units::binomial_distribution(t * si::metre, p);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.p() == stl_dist.p());
|
|
|
|
CHECK(units_dist.t() == stl_dist.t() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("negative_binomial_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::negative_binomial_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.p() == 0.5);
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.k() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep k = 5;
|
|
|
|
constexpr double p = 0.25;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::negative_binomial_distribution(k, p);
|
|
|
|
auto units_dist = mp_units::negative_binomial_distribution(k * si::metre, p);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.p() == stl_dist.p());
|
|
|
|
CHECK(units_dist.k() == stl_dist.k() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("geometric_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::geometric_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.p() == 0.5);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr double p = 0.25;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::geometric_distribution<rep>(p);
|
|
|
|
auto units_dist = mp_units::geometric_distribution<q>(p);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.p() == stl_dist.p());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("poisson_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::poisson_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.mean() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr double mean = 5.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::poisson_distribution<rep>(mean);
|
|
|
|
auto units_dist = mp_units::poisson_distribution<q>(mean);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.mean() == stl_dist.mean());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("exponential_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::exponential_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.lambda() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr double lambda = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::exponential_distribution<rep>(lambda);
|
|
|
|
auto units_dist = mp_units::exponential_distribution<q>(lambda);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.lambda() == stl_dist.lambda());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("gamma_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::gamma_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.alpha() == 1.0);
|
|
|
|
CHECK(dist.beta() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr double alpha = 5.0;
|
|
|
|
constexpr double beta = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::gamma_distribution<rep>(alpha, beta);
|
|
|
|
auto units_dist = mp_units::gamma_distribution<q>(alpha, beta);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.alpha() == stl_dist.alpha());
|
|
|
|
CHECK(units_dist.beta() == stl_dist.beta());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("weibull_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::weibull_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.a() == 1.0);
|
|
|
|
CHECK(dist.b() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep a = 5.0;
|
|
|
|
constexpr rep b = 2.0;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::weibull_distribution(a, b);
|
|
|
|
auto units_dist = mp_units::weibull_distribution<q>(a, b);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.a() == stl_dist.a());
|
|
|
|
CHECK(units_dist.b() == stl_dist.b());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("extreme_value_distribution")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::extreme_value_distribution<q>();
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.a() == q::zero());
|
|
|
|
CHECK(dist.b() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep a = 5.0;
|
|
|
|
constexpr rep b = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::extreme_value_distribution(a, b);
|
|
|
|
auto units_dist = mp_units::extreme_value_distribution<q>(a * si::metre, b);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.a() == stl_dist.a() * si::metre);
|
|
|
|
CHECK(units_dist.b() == stl_dist.b());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("normal_distribution")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::normal_distribution<q>();
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.mean() == q::zero());
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.stddev() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep mean = 5.0;
|
|
|
|
constexpr rep stddev = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::normal_distribution(mean, stddev);
|
|
|
|
auto units_dist = mp_units::normal_distribution(mean * si::metre, stddev * si::metre);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.mean() == stl_dist.mean() * si::metre);
|
|
|
|
CHECK(units_dist.stddev() == stl_dist.stddev() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("lognormal_distribution")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::lognormal_distribution<q>();
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.m() == q::zero());
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.s() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep m = 5.0;
|
|
|
|
constexpr rep s = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::lognormal_distribution(m, s);
|
|
|
|
auto units_dist = mp_units::lognormal_distribution(m * si::metre, s * si::metre);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.m() == stl_dist.m() * si::metre);
|
|
|
|
CHECK(units_dist.s() == stl_dist.s() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("chi_squared_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::chi_squared_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.n() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep n = 5.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::chi_squared_distribution(n);
|
|
|
|
auto units_dist = mp_units::chi_squared_distribution<q>(n);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.n() == stl_dist.n());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("cauchy_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::cauchy_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.a() == q::zero());
|
2025-02-05 12:08:32 +01:00
|
|
|
CHECK(dist.b() == 1 * si::metre);
|
2024-11-12 11:27:52 +01:00
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep a = 5.0;
|
|
|
|
constexpr rep b = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::cauchy_distribution(a, b);
|
|
|
|
auto units_dist = mp_units::cauchy_distribution(a * si::metre, b * si::metre);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.a() == stl_dist.a() * si::metre);
|
|
|
|
CHECK(units_dist.b() == stl_dist.b() * si::metre);
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("fisher_f_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::fisher_f_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.m() == 1.0);
|
|
|
|
CHECK(dist.n() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep m = 5.0;
|
|
|
|
constexpr rep n = 2.0;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::fisher_f_distribution<rep>(m, n);
|
|
|
|
auto units_dist = mp_units::fisher_f_distribution<q>(m, n);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.m() == stl_dist.m());
|
|
|
|
CHECK(units_dist.n() == stl_dist.n());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("student_t_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto dist = mp_units::student_t_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(dist.n() == 1.0);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized")
|
|
|
|
{
|
|
|
|
constexpr rep n = 2.0;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::student_t_distribution<rep>(n);
|
|
|
|
auto units_dist = mp_units::student_t_distribution<q>(n);
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.n() == stl_dist.n());
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("discrete_distribution")
|
2022-03-17 23:59:48 +01:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = std::int64_t;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto stl_dist = std::discrete_distribution<rep>();
|
|
|
|
auto units_dist = mp_units::discrete_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
CHECK(units_dist.probabilities() == stl_dist.probabilities());
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized_input_it")
|
|
|
|
{
|
|
|
|
constexpr std::array<double, 3> weights = {1.0, 2.0, 3.0};
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::discrete_distribution<rep>(weights.cbegin(), weights.cend());
|
|
|
|
auto units_dist = mp_units::discrete_distribution<q>(weights.cbegin(), weights.cend());
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.probabilities() == stl_dist.probabilities());
|
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized_initializer_list")
|
|
|
|
{
|
|
|
|
const std::initializer_list<double> weights = {1.0, 2.0, 3.0};
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::discrete_distribution<rep>(weights);
|
|
|
|
auto units_dist = mp_units::discrete_distribution<q>(weights);
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.probabilities() == stl_dist.probabilities());
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized_range")
|
|
|
|
{
|
|
|
|
constexpr std::size_t count = 3;
|
|
|
|
constexpr double xmin = 1, xmax = 3;
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
auto stl_dist = std::discrete_distribution<rep>(count, xmin, xmax, [](double val) { return val; });
|
|
|
|
auto units_dist = mp_units::discrete_distribution<q>(count, xmin, xmax, [](double val) { return val; });
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.probabilities() == stl_dist.probabilities());
|
|
|
|
}
|
2020-05-22 06:49:25 +03:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("piecewise_constant_distribution")
|
2020-05-22 06:49:25 +03:00
|
|
|
{
|
2024-11-12 11:27:52 +01:00
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
std::vector<rep> intervals_rep_vec = {1.0, 2.0, 3.0};
|
|
|
|
std::vector<q> intervals_qty_vec = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto stl_dist = std::piecewise_constant_distribution<rep>();
|
|
|
|
auto units_dist = mp_units::piecewise_constant_distribution<q>();
|
2020-05-22 06:49:25 +03:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
CHECK(stl_dist.intervals().size() == 2);
|
|
|
|
CHECK(units_dist.intervals().size() == 2);
|
|
|
|
CHECK(stl_dist.densities().size() == 1);
|
|
|
|
CHECK(units_dist.densities().size() == 1);
|
|
|
|
}
|
2022-03-17 23:59:48 +01:00
|
|
|
|
2024-11-12 11:27:52 +01:00
|
|
|
SECTION("parametrized_input_it")
|
|
|
|
{
|
|
|
|
constexpr std::array<rep, 3> intervals_rep = {1.0, 2.0, 3.0};
|
|
|
|
constexpr std::array<q, 3> intervals_qty = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
|
|
|
constexpr std::array<rep, 3> weights = {1.0, 2.0, 3.0};
|
|
|
|
|
|
|
|
auto stl_dist =
|
|
|
|
std::piecewise_constant_distribution<rep>(intervals_rep.cbegin(), intervals_rep.cend(), weights.cbegin());
|
|
|
|
auto units_dist =
|
|
|
|
mp_units::piecewise_constant_distribution<q>(intervals_qty.cbegin(), intervals_qty.cend(), weights.cbegin());
|
|
|
|
|
|
|
|
CHECK(stl_dist.intervals() == intervals_rep_vec);
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parametrized_initializer_list")
|
|
|
|
{
|
|
|
|
const std::initializer_list<rep> intervals_rep = {1.0, 2.0, 3.0};
|
|
|
|
const std::initializer_list<q> intervals_qty = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
|
|
|
|
|
|
|
auto stl_dist = std::piecewise_constant_distribution<rep>(intervals_rep, [](rep val) { return val; });
|
|
|
|
auto units_dist = mp_units::piecewise_constant_distribution<q>(
|
|
|
|
intervals_qty, [](q qty) { return qty.numerical_value_ref_in(qty.unit); });
|
|
|
|
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parametrized_range")
|
|
|
|
{
|
|
|
|
constexpr std::size_t nw = 2;
|
|
|
|
constexpr rep xmin_rep = 1.0, xmax_rep = 3.0;
|
|
|
|
constexpr q xmin_qty = 1.0 * isq::length[si::metre], xmax_qty = 3.0 * isq::length[si::metre];
|
|
|
|
|
|
|
|
auto stl_dist = std::piecewise_constant_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
|
|
|
|
auto units_dist = mp_units::piecewise_constant_distribution<q>(
|
|
|
|
nw, xmin_qty, xmax_qty, [](q qty) { return qty.numerical_value_ref_in(qty.unit); });
|
|
|
|
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("piecewise_linear_distribution")
|
|
|
|
{
|
|
|
|
using rep = long double;
|
|
|
|
using q = quantity<isq::length[si::metre], rep>;
|
|
|
|
|
|
|
|
std::vector<rep> intervals_rep_vec = {1.0, 2.0, 3.0};
|
|
|
|
std::vector<q> intervals_qty_vec = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
|
|
|
|
|
|
|
SECTION("default")
|
|
|
|
{
|
|
|
|
auto stl_dist = std::piecewise_linear_distribution<rep>();
|
|
|
|
auto units_dist = mp_units::piecewise_linear_distribution<q>();
|
|
|
|
|
|
|
|
CHECK(units_dist.min() == stl_dist.min() * si::metre);
|
|
|
|
CHECK(units_dist.max() == stl_dist.max() * si::metre);
|
|
|
|
CHECK(stl_dist.intervals().size() == 2);
|
|
|
|
CHECK(units_dist.intervals().size() == 2);
|
|
|
|
CHECK(stl_dist.densities().size() == 2);
|
|
|
|
CHECK(units_dist.densities().size() == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parametrized_input_it")
|
|
|
|
{
|
|
|
|
constexpr std::array<rep, 3> intervals_rep = {1.0, 2.0, 3.0};
|
|
|
|
constexpr std::array<q, 3> intervals_qty = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
|
|
|
constexpr std::array<rep, 3> weights = {1.0, 2.0, 3.0};
|
|
|
|
|
|
|
|
auto stl_dist =
|
|
|
|
std::piecewise_linear_distribution<rep>(intervals_rep.cbegin(), intervals_rep.cend(), weights.cbegin());
|
|
|
|
auto units_dist =
|
|
|
|
mp_units::piecewise_linear_distribution<q>(intervals_qty.cbegin(), intervals_qty.cend(), weights.cbegin());
|
|
|
|
|
|
|
|
CHECK(stl_dist.intervals() == intervals_rep_vec);
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parametrized_initializer_list")
|
|
|
|
{
|
|
|
|
const std::initializer_list<rep> intervals_rep = {1.0, 2.0, 3.0};
|
|
|
|
const std::initializer_list<q> intervals_qty = {1.0 * isq::length[si::metre], 2.0 * isq::length[si::metre],
|
|
|
|
3.0 * isq::length[si::metre]};
|
|
|
|
|
|
|
|
auto stl_dist = std::piecewise_linear_distribution<rep>(intervals_rep, [](rep val) { return val; });
|
|
|
|
auto units_dist = mp_units::piecewise_linear_distribution<q>(
|
|
|
|
intervals_qty, [](q qty) { return qty.numerical_value_ref_in(qty.unit); });
|
|
|
|
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parametrized_range")
|
|
|
|
{
|
|
|
|
constexpr std::size_t nw = 2;
|
|
|
|
constexpr rep xmin_rep = 1.0, xmax_rep = 3.0;
|
|
|
|
constexpr q xmin_qty = 1.0 * isq::length[si::metre], xmax_qty = 3.0 * isq::length[si::metre];
|
|
|
|
|
|
|
|
auto stl_dist = std::piecewise_linear_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
|
|
|
|
auto units_dist = mp_units::piecewise_linear_distribution<q>(
|
|
|
|
nw, xmin_qty, xmax_qty, [](q qty) { return qty.numerical_value_ref_in(qty.unit); });
|
|
|
|
|
|
|
|
CHECK(units_dist.intervals() == intervals_qty_vec);
|
|
|
|
CHECK(units_dist.densities() == stl_dist.densities());
|
|
|
|
}
|
|
|
|
}
|
2024-11-12 11:31:26 +01:00
|
|
|
}
|