From e7f37e4e33617bf8eba665561be38a8722b6cb4c Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 29 Dec 2019 17:06:03 +0100 Subject: [PATCH] CGS fmt tests added --- test/unit_test/runtime/fmt_test.cpp | 69 ++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 1bae34a9..893a5d0b 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include "units/physical/cgs/length.h" +#include "units/physical/cgs/mass.h" #include "units/physical/si/area.h" #include "units/physical/si/frequency.h" #include "units/physical/si/power.h" @@ -378,22 +380,46 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") { SECTION("unit::ratio::num == 1 && unit::ratio::den == 1") { - const auto q = 2s * 2m * 2kg; - stream << q; - - SECTION("iostream") + SECTION("SI base units") { - CHECK(stream.str() == "8 m⋅kg⋅s"); + const auto q = 2s * 2m * 2kg; + stream << q; + + SECTION("iostream") + { + CHECK(stream.str() == "8 m⋅kg⋅s"); + } + + SECTION("fmt with default format {} on a quantity") + { + CHECK(fmt::format("{}", q) == stream.str()); + } + + SECTION("fmt with format {:%Q %q} on a quantity") + { + CHECK(fmt::format("{:%Q %q}", q) == stream.str()); + } } - SECTION("fmt with default format {} on a quantity") + SECTION("CGS base units") { - CHECK(fmt::format("{}", q) == stream.str()); - } + const auto q = 2s * cgs::length(2) * cgs::mass(2); + stream << q; - SECTION("fmt with format {:%Q %q} on a quantity") - { - CHECK(fmt::format("{:%Q %q}", q) == stream.str()); + SECTION("iostream") + { + CHECK(stream.str() == "8 cm⋅g⋅s"); + } + + SECTION("fmt with default format {} on a quantity") + { + CHECK(fmt::format("{}", q) == stream.str()); + } + + SECTION("fmt with format {:%Q %q} on a quantity") + { + CHECK(fmt::format("{:%Q %q}", q) == stream.str()); + } } } @@ -460,6 +486,27 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") } } + SECTION("CGS base units") + { + const auto q = 2s * cgs::length(2) * cgs::mass(2); + stream << q; + + SECTION("iostream") + { + CHECK(stream.str() == "8 [1 × 10⁵]cm⋅g⋅s"); + } + + SECTION("fmt with default format {} on a quantity") + { + CHECK(fmt::format("{}", q) == stream.str()); + } + + SECTION("fmt with format {:%Q %q} on a quantity") + { + CHECK(fmt::format("{:%Q %q}", q) == stream.str()); + } + } + SECTION("unit::ratio::num != 1 && unit::ratio::den != 1") { const auto q = 60min / 2km;