refactor: dead ratio code removed

This commit is contained in:
Mateusz Pusz
2022-09-06 23:49:16 +02:00
parent 1238cc17c2
commit d0eceefe80
7 changed files with 0 additions and 249 deletions
-73
View File
@@ -294,79 +294,6 @@ TEST_CASE("round functions", "[round]")
}
}
TEMPLATE_TEST_CASE_SIG("pow<N>() implementation exponentiates values to power N", "[math][pow][exp]",
(std::intmax_t N, N), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25)
{
auto v = GENERATE(range(0.5, 20.0, 0.5));
REQUIRE(detail::pow_impl<N>(v) == Catch::Approx(std::pow(v, N)).epsilon(1e-15).margin(0));
}
template<std::intmax_t N>
struct Pow {
constexpr static std::intmax_t exponent = N;
template<typename T>
[[nodiscard]] constexpr static auto pow(const T& v) noexcept
{
return detail::pow_impl<N>(v);
}
};
template<std::intmax_t N>
struct CompileRoot : Pow<N> {
[[nodiscard]] constexpr static std::intmax_t root(std::intmax_t v) noexcept { return detail::iroot_compile<N>(v); }
};
template<std::intmax_t N>
struct RuntimeRoot : Pow<N> {
[[nodiscard]] static std::intmax_t root(std::intmax_t v) noexcept { return detail::iroot_runtime<N>(v); }
};
// test to make sure precision is not lost when rounding what should be integer roots
template<typename TestType>
static void root_test()
{
SECTION("Roots are truncated down")
{
auto base = GENERATE(range(1.0, 10.0, 1.0)); // doubles to guard against overflow
if (TestType::pow(base) < static_cast<double>(std::numeric_limits<std::intmax_t>::max())) {
const std::intmax_t x = TestType::pow(static_cast<std::intmax_t>(base));
const auto expect = static_cast<std::intmax_t>(base);
REQUIRE(TestType::root(x - 1) == expect - 1);
REQUIRE(TestType::root(x) == expect);
}
}
SECTION("Roots are truncated correctly for very large inputs")
{
auto exponent = GENERATE(range(10, std::numeric_limits<std::intmax_t>::digits10, 1));
const auto large_val = static_cast<std::intmax_t>(std::pow(10, exponent));
const auto expected = static_cast<std::intmax_t>(std::pow(10, exponent / static_cast<double>(TestType::exponent)));
REQUIRE(TestType::root(large_val) == expected);
}
}
/* Catch2 uses int for indexing in TEMPLATE_PRODUCT_TEST_CASE_SIG so it does not compile with -Werror=sign-conversion
* https://github.com/catchorg/Catch2/pull/2074
TEMPLATE_PRODUCT_TEST_CASE_SIG("detail::iroot<N>()", "[math][pow][iroot]", (std::intmax_t N, N),
(CompileRoot, RuntimeRoot), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25))
{
root_test<TestType>();
}
*/
#define ROOT_TEST_CASE(Type) \
TEMPLATE_TEST_CASE_SIG("detail::iroot<N>() - " #Type, "[math][pow][iroot]", (std::intmax_t N, N), 1, 2, 3, 4, 5, 6, \
7, 8, 9, 10, 15, 20, 25) \
{ \
root_test<Type<N>>(); \
}
ROOT_TEST_CASE(CompileRoot)
ROOT_TEST_CASE(RuntimeRoot)
TEST_CASE("hypot functions", "[hypot]")
{
using namespace units::aliases::isq::si;