Skip to content

Commit

Permalink
test: a few more natural units tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Nov 29, 2024
1 parent 9c46717 commit 52e95f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/static/concepts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ inline constexpr struct my_relative_origin final : relative_point_origin<my_orig

inline constexpr auto dim_speed = isq::dim_length / isq::dim_time;

namespace nu {
inline constexpr struct second final : named_unit<"s"> {
} second;
inline constexpr struct hour final : named_unit<"h", mag<3600> * second> {
} hour;

} // namespace nu

// BaseDimension
static_assert(detail::BaseDimension<struct isq::dim_length>);
static_assert(!detail::BaseDimension<decltype(isq::dim_length / isq::dim_time)>);
Expand Down Expand Up @@ -143,6 +151,8 @@ static_assert(Unit<struct si::standard_gravity>);
static_assert(Unit<scaled_unit<mag<10>, struct si::second>>);
static_assert(Unit<derived_unit<struct si::metre, per<struct si::second>>>);
static_assert(Unit<struct one>);
static_assert(Unit<struct nu::second>);
static_assert(Unit<decltype(si::metre / nu::second)>);
static_assert(!Unit<named_unit<"?", kind_of<isq::length>>>);
static_assert(!Unit<named_unit<"?">>);
static_assert(!Unit<named_unit<"?", si::metre / si::second>>);
Expand Down Expand Up @@ -193,6 +203,9 @@ static_assert(AssociatedUnit<struct si::standard_gravity>);
static_assert(AssociatedUnit<scaled_unit<mag<10>, struct si::second>>);
static_assert(AssociatedUnit<derived_unit<struct si::metre, per<struct si::second>>>);
static_assert(AssociatedUnit<struct one>);
static_assert(AssociatedUnit<decltype(get_common_unit(si::kilo<si::metre> / si::hour, si::metre / si::second))>);
static_assert(!AssociatedUnit<decltype(si::metre / nu::second)>);
static_assert(!AssociatedUnit<decltype(get_common_unit(si::kilo<si::metre> / nu::hour, si::metre / nu::second))>);
static_assert(!AssociatedUnit<named_unit<"?", kind_of<isq::length>>>);
static_assert(!AssociatedUnit<named_unit<"?">>);
static_assert(!AssociatedUnit<named_unit<"?", si::metre / si::second>>);
Expand Down
6 changes: 6 additions & 0 deletions test/static/reference_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ static_assert(
quantity<reference<derived_quantity_spec<length_, mass_, per<time_>>, MP_UNITS_NONCONST_TYPE(si::kilo<gram>)>{},
int>>);

// Mixed-systems quantities
static_assert(
is_of_type<
42 * metre / nu::time[nu::second],
quantity<reference<derived_quantity_spec<length_, per<time_>>, derived_unit<metre_, per<nu::second_>>>{}, int>>);

template<auto dim, auto unit>
concept invalid_nu_unit = !requires { dim[unit]; };

Expand Down

0 comments on commit 52e95f9

Please sign in to comment.