From b252da0fe1643e9b5080f0487da2ae25b6978921 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 3 Aug 2022 13:10:59 +0200 Subject: [PATCH] test: `hypot` unit tests added --- test/unit_test/runtime/math_test.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/unit_test/runtime/math_test.cpp b/test/unit_test/runtime/math_test.cpp index d74c93ef..22464106 100644 --- a/test/unit_test/runtime/math_test.cpp +++ b/test/unit_test/runtime/math_test.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -30,7 +31,7 @@ using namespace units; using namespace units::isq; -using namespace units::isq::si; +using namespace units::isq::si::literals; // classical @@ -363,3 +364,21 @@ TEMPLATE_PRODUCT_TEST_CASE_SIG("detail::iroot()", "[math][pow][iroot]", (std: ROOT_TEST_CASE(CompileRoot) ROOT_TEST_CASE(RuntimeRoot) + +TEST_CASE("hypot functions", "[hypot]") +{ + using namespace units::aliases::isq::si; + + SECTION("hypot of 3 kilometres with 4 kilometres should be 5 kilometres") + { + REQUIRE(hypot(km<>(3.), km<>(4.)) == km<>(5.)); + } + SECTION("hypot should work with different units of the same dimension") + { + REQUIRE(hypot(km<>(3.), m<>(4000.)) == km<>(5.)); + } + SECTION("hypot should work with different but equivalent dimensions") + { + REQUIRE(hypot(km<>(3.), cgs::length::cm<>(400'000.)) == km<>(5.)); + } +}