From 758c05ea15064dab6a89118fcdf7bde32399a880 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 23 Dec 2019 13:22:37 +0100 Subject: [PATCH] quantity_cast fmt tests added --- test/unit_test/runtime/fmt_test.cpp | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index c4c3aa03..ccaf10dd 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -837,6 +837,57 @@ TEST_CASE("precision specification for integral representation should throw", "[ // rather than their parts +TEST_CASE("quantity_cast", "[text][ostream]") +{ + std::stringstream stream; + + SECTION("int to double representation") + { + const auto q = 121km / 2h; + + SECTION("original") + { + stream << q; + CHECK(stream.str() == "60 km/h"); + } + + SECTION("int") + { + stream << quantity_cast(q); + CHECK(stream.str() == "60 km/h"); + } + + SECTION("double") + { + stream << quantity_cast(q); + CHECK(stream.str() == "60 km/h"); + } + } + + SECTION("double to int representation") + { + const auto q = 121.km / 2h; + + SECTION("original") + { + stream << q; + CHECK(stream.str() == "60.5 km/h"); + } + + SECTION("int") + { + stream << quantity_cast(q); + CHECK(stream.str() == "60 km/h"); + } + + SECTION("double") + { + stream << quantity_cast(q); + CHECK(stream.str() == "60.5 km/h"); + } + } +} + // Giving a precision specification // in the chrono-format-spec is valid only for std::chrono::duration types where the representation type Rep // is a floating-point type. For all other Rep types, a format_error shall be thrown if the chrono-format-spec