From 719f71c5658d899051d08dc1362da4c61b14691c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffan=20S=C3=B8lvsten?= Date: Mon, 12 Feb 2024 17:57:09 +0100 Subject: [PATCH] Add truncation for quantify::transposition_growth And also coverage for nested::fast_reduce --- src/adiar/exec_policy.h | 15 +++++++++++++-- test/adiar/test_exec_policy.cpp | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/adiar/exec_policy.h b/src/adiar/exec_policy.h index ecdc10513..794d4dc55 100644 --- a/src/adiar/exec_policy.h +++ b/src/adiar/exec_policy.h @@ -126,12 +126,15 @@ namespace adiar ////////////////////////////////////////////////////////////////////////// class transposition_growth { + private: + static constexpr float min_val = 0.0f; + public: /// \brief Minimal value static constexpr transposition_growth min() { - return 0.0f; + return min_val; } /// \brief Maximal value @@ -144,6 +147,14 @@ namespace adiar private: float _value; + /// \brief Convert into a `signed char` + static constexpr float + from_float(float f) + { + // Truncate `f` to be in the interval [0.0f, ...) + return f < min_val ? min_val : f; + } + public: constexpr transposition_growth() : _value(1.5f) @@ -151,7 +162,7 @@ namespace adiar /// \brief Wrap a `float`. constexpr transposition_growth(float value) - : _value(value) + : _value(from_float(value)) {} /// \brief Reobtain the wrapped `float` diff --git a/test/adiar/test_exec_policy.cpp b/test/adiar/test_exec_policy.cpp index 7233495e1..ef5634ff0 100644 --- a/test/adiar/test_exec_policy.cpp +++ b/test/adiar/test_exec_policy.cpp @@ -16,14 +16,25 @@ go_bandit([]() { AssertThat(default__transposition_growth, Is().GreaterThanOrEqualTo(0.0f)); }); - it("'quantify::transposition max' defaults to a non-negative value", [&]() { - AssertThat(default__transposition_max, Is().GreaterThanOrEqualTo(0u)); + it("'quantify::transposition growth' truncates negative values to '0.0f'", [&]() { + const exec_policy::quantify::transposition_growth res(-0.5f); + AssertThat(static_cast(res), Is().GreaterThanOrEqualTo(0.0f)); }); it("'nested::fast reduce epsilon' defaults to a value in [-1,1]", [&]() { AssertThat(default__fast_reduce, Is().GreaterThanOrEqualTo(-1.0f)); AssertThat(default__fast_reduce, Is().LessThanOrEqualTo(1.0f)); }); + + it("'nested::fast reduce epsilon' truncates negative values to '-1.0f'", [&]() { + const exec_policy::nested::fast_reduce res(-42.0f); + AssertThat(static_cast(res), Is().EqualTo(-1.0f)); + }); + + it("'nested::fast reduce epsilon' truncates positive value to '1.0f'", [&]() { + const exec_policy::nested::fast_reduce res(2.0f); + AssertThat(static_cast(res), Is().EqualTo(1.0f)); + }); }); describe("exec_policy(const __ &)", [&]() {