From 9d3a1445513cc2cbbf8040d70cdcc5da07c1353b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 9 Sep 2022 15:18:49 +0200 Subject: [PATCH] test: a few more tests added to the framework v2 example --- example/v2_framework.cpp | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/example/v2_framework.cpp b/example/v2_framework.cpp index 51ca79e6..6c67a247 100644 --- a/example/v2_framework.cpp +++ b/example/v2_framework.cpp @@ -83,7 +83,7 @@ inline constexpr struct square_metre : derived_unit { } square_metre; // volume units -inline constexpr struct cubic_metre : derived_unit { +inline constexpr struct cubic_metre : derived_unit { } cubic_metre; // time units @@ -96,9 +96,12 @@ inline constexpr struct hour : named_scaled_unit<"h", mag<60>(), minute> { inline constexpr struct day : named_scaled_unit<"d", mag<24>(), hour> { } day; -// not a time unit! +// not time units! +// TODO should those be provided for other scaled units like ms, h, ... inline constexpr struct second_squared : derived_unit { } second_squared; +inline constexpr struct second_cubed : derived_unit { +} second_cubed; // mass units inline constexpr struct gram : named_unit<"g"> { @@ -356,10 +359,28 @@ static_assert(is_of_type); static_assert(is_of_type>>); static_assert(is_of_type>>); -// comparisons of equivalent dimensions -// static_assert(metre / metre == one); +// comparisons of equivalent units +static_assert(metre / metre == one); +static_assert(metre * metre == square_metre); +static_assert(second * second == second_squared); +static_assert(second * second * second == second_cubed); +static_assert(second * (second * second) == second_cubed); +static_assert(second_squared * second == second_cubed); +static_assert(second * second_squared == second_cubed); + +static_assert(1 / second * metre == metre / second); +static_assert(metre * (1 / second) == metre / second); +static_assert((metre / second) * (1 / second) == metre / second / second); +static_assert((metre / second) * (1 / second) == metre / (second * second)); +static_assert((metre / second) * (1 / second) == metre / second_squared); + +static_assert(hertz == 1 / second); +static_assert(newton == kilogram * metre / second_squared); +static_assert(joule == kilogram * square_metre / second_squared); +static_assert(joule == newton * metre); +static_assert(watt == joule / second); +static_assert(watt == kilogram * square_metre / second_cubed); -// static_assert(1 / second == dim_frequency); // static_assert(1 / dim_frequency == second); // static_assert(dim_frequency * second == one); @@ -398,6 +419,23 @@ static_assert(is_of_type +inline constexpr bool is_exactly_quantity_of = + is_same_v && is_same_v; + +namespace units::isq::si { + +// quantity tests +static_assert( + is_exactly_quantity_of>>); + +// static_assert(QuantityOf>); +// static_assert(QuantityOf>); +// // TODO Should this compile? + +} // namespace units::isq::si + + using namespace units; using namespace units::isq::si; using namespace units::isq::si::short_units;