From 1830735544a20a8276b6fafe1ab0963a8538c05b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 8 May 2020 21:18:16 +0200 Subject: [PATCH] Unit tests for alias_unit added --- test/unit_test/runtime/fmt_test.cpp | 42 +++++++++++++++++++++++++ test/unit_test/static/quantity_test.cpp | 8 +++++ 2 files changed, 50 insertions(+) diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 515b8dea..4d306f5e 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -155,6 +155,48 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") } } + SECTION("quantity with an alias unit") + { + const auto q = 2q_l; + os << q; + + SECTION("iostream") + { + CHECK(os.str() == "2 l"); + } + + SECTION("fmt with default format {} on a quantity") + { + CHECK(fmt::format("{}", q) == os.str()); + } + + SECTION("fmt with format {:%Q %q} on a quantity") + { + CHECK(fmt::format("{:%Q %q}", q) == os.str()); + } + } + + SECTION("quantity with a prefixed alias unit") + { + const auto q = 2q_ml; + os << q; + + SECTION("iostream") + { + CHECK(os.str() == "2 ml"); + } + + SECTION("fmt with default format {} on a quantity") + { + CHECK(fmt::format("{}", q) == os.str()); + } + + SECTION("fmt with format {:%Q %q} on a quantity") + { + CHECK(fmt::format("{:%Q %q}", q) == os.str()); + } + } + SECTION("quantity with a deduced unit") { SECTION("coherent derived unit") diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index b74e72ed..d7c5c687 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -24,6 +24,7 @@ #include "units/physical/si/area.h" #include "units/physical/si/frequency.h" #include "units/physical/si/velocity.h" +#include "units/physical/si/volume.h" #include #include @@ -202,6 +203,13 @@ static_assert(999q_m < 1q_km); static_assert(1000q_m >= 1q_km); static_assert(1000q_m <= 1q_km); +// alias units + +static_assert(2q_l + 2q_ml == 2002q_ml); +static_assert(2q_l + 2q_ml == 2002q_cm3); +static_assert(2q_l + 2q_cm3 == 2002q_ml); +static_assert(2q_dm3 + 2q_cm3 == 2002q_ml); + // is_quantity static_assert(Quantity>);