test: more tests for pow added for units and quantity specs

This commit is contained in:
Mateusz Pusz
2023-06-13 09:21:07 +03:00
parent ee2abaf9f7
commit 16ad71a31a
2 changed files with 21 additions and 0 deletions

View File

@ -280,6 +280,10 @@ static_assert(is_of_type<kind_of<length> / kind_of<time>, kind_of_<derived_quant
static_assert(is_of_type<kind_of<length / time>, kind_of_<derived_quantity_spec<length_, per<time_>>{}>>); static_assert(is_of_type<kind_of<length / time>, kind_of_<derived_quantity_spec<length_, per<time_>>{}>>);
// power // power
static_assert(is_of_type<pow<0>(length), dimensionless_>);
static_assert(is_of_type<pow<1>(length), length_>);
static_assert(is_of_type<pow<2, 2>(length), length_>);
static_assert(is_of_type<pow<2>(dimensionless), dimensionless_>);
static_assert(is_of_type<pow<2>(length), derived_quantity_spec<mp_units::power<length_, 2>>>); static_assert(is_of_type<pow<2>(length), derived_quantity_spec<mp_units::power<length_, 2>>>);
static_assert(is_of_type<pow<1, 2>(length), derived_quantity_spec<mp_units::power<length_, 1, 2>>>); static_assert(is_of_type<pow<1, 2>(length), derived_quantity_spec<mp_units::power<length_, 1, 2>>>);
static_assert(is_of_type<pow<1, 2>(length* length), length_>); static_assert(is_of_type<pow<1, 2>(length* length), length_>);
@ -293,6 +297,10 @@ static_assert(
static_assert(is_same_v<decltype(pow<2>(length)), decltype(length * length)>); static_assert(is_same_v<decltype(pow<2>(length)), decltype(length * length)>);
static_assert(is_same_v<decltype(pow<2>(length / time)), decltype(length * length / time / time)>); static_assert(is_same_v<decltype(pow<2>(length / time)), decltype(length * length / time / time)>);
static_assert(dimensionless * dimensionless == dimensionless);
static_assert(is_of_type<dimensionless * dimensionless, dimensionless_>);
template<auto& t> template<auto& t>
concept invalid_operations = requires { concept invalid_operations = requires {
requires !requires { t < t; }; requires !requires { t < t; };

View File

@ -33,6 +33,7 @@ using namespace mp_units;
using namespace mp_units::detail; using namespace mp_units::detail;
using one_ = struct one; using one_ = struct one;
using percent_ = struct percent;
// base dimensions // base dimensions
// clang-format off // clang-format off
@ -475,6 +476,12 @@ static_assert(is_of_type<metre / metre, one_>);
static_assert(is_of_type<si::kilo<metre> / metre, derived_unit<si::kilo_<metre>, per<metre_>>>); static_assert(is_of_type<si::kilo<metre> / metre, derived_unit<si::kilo_<metre>, per<metre_>>>);
static_assert(metre / metre == one); static_assert(metre / metre == one);
static_assert(hertz * second == one); static_assert(hertz * second == one);
static_assert(one * one == one);
static_assert(is_of_type<one * one, one_>);
static_assert(one * percent == percent);
static_assert(percent * one == percent);
static_assert(is_of_type<one * percent, percent_>);
static_assert(is_of_type<percent * one, percent_>);
static_assert(hertz == 1 / second); static_assert(hertz == 1 / second);
static_assert(newton == kilogram * metre / square(second)); static_assert(newton == kilogram * metre / square(second));
@ -492,6 +499,12 @@ static_assert(is_same_v<decltype(pow<2>(mag<3600> * second)), decltype((mag<3600
static_assert(is_same_v<decltype(pow<2>(metre / second)), decltype(metre * metre / second / second)>); static_assert(is_same_v<decltype(pow<2>(metre / second)), decltype(metre * metre / second / second)>);
static_assert(is_same_v<decltype(pow<2>(kilometre / hour)), decltype(kilometre * kilometre / hour / hour)>); static_assert(is_same_v<decltype(pow<2>(kilometre / hour)), decltype(kilometre * kilometre / hour / hour)>);
static_assert(is_of_type<pow<0>(metre), one_>);
static_assert(is_of_type<pow<1>(metre), metre_>);
static_assert(is_of_type<pow<2, 2>(metre), metre_>);
static_assert(is_of_type<pow<2>(one), one_>);
static_assert(is_of_type<pow<2>(percent), derived_unit<power<percent_, 2>>>);
static_assert(is_of_type<pow<2>(radian), derived_unit<power<radian_, 2>>>);
static_assert(is_of_type<pow<2>(metre), derived_unit<power<metre_, 2>>>); static_assert(is_of_type<pow<2>(metre), derived_unit<power<metre_, 2>>>);
static_assert(is_of_type<pow<1, 2>(metre), derived_unit<power<metre_, 1, 2>>>); static_assert(is_of_type<pow<1, 2>(metre), derived_unit<power<metre_, 1, 2>>>);
static_assert(is_of_type<pow<1, 2>(metre* metre), metre_>); static_assert(is_of_type<pow<1, 2>(metre* metre), metre_>);