Files
mp-units/test/unit_test/static/concepts_test.cpp
Chip Hogg d19b2803ce Migrate units from ratio to Magnitude
This commit is huge, but hopefully the cognitive load is not too bad.
The bulk of this commit is just some fairly mechanical updates from
`ratio` to `Magnitude`.  Other things to call out:

- `UnitRatio` goes away.  We don't need this concept, because Magnitude
  can't even _represent_ anything that doesn't satisfy it.

- I commented out some formatting test cases where the precise
  expression changes, but the number is completely equivalent.  We will
  need to decide how we want to handle Magnitude formatting as a
  separate, follow-on task.  But at least Magnitude gives us all the
  tools we'll need to do so!
2022-04-11 15:16:16 +00:00

145 lines
5.1 KiB
C++

// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/chrono.h>
#include <units/isq/si/cgs/length.h>
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
#include <units/isq/si/fps/length.h>
#include <units/isq/si/fps/speed.h> // IWYU pragma: keep
#include <units/isq/si/length.h> // IWYU pragma: keep
#include <units/isq/si/prefixes.h>
#include <units/isq/si/speed.h>
#include <units/quantity_point_kind.h>
#include <chrono>
#include <complex>
#include <mutex>
#include <optional>
#include <ratio>
#include <string>
#include <utility>
namespace {
using namespace units;
using namespace units::isq;
// Prefix family
static_assert(PrefixFamily<si::prefix>);
static_assert(!PrefixFamily<si::kilo>);
// Prefix
static_assert(Prefix<si::kilo>);
static_assert(!Prefix<si::prefix>);
static_assert(!Prefix<std::kilo>);
// BaseDimension
static_assert(BaseDimension<si::dim_length>);
static_assert(!BaseDimension<si::dim_speed>);
static_assert(!BaseDimension<int>);
// DerivedDimension
static_assert(DerivedDimension<si::dim_speed>);
static_assert(!DerivedDimension<si::dim_length>);
static_assert(!DerivedDimension<int>);
// Dimension
static_assert(Dimension<si::dim_length>);
static_assert(Dimension<si::dim_speed>);
static_assert(!Dimension<si::metre>);
static_assert(!Dimension<int>);
static_assert(!Dimension<std::chrono::seconds>);
// Unit
static_assert(Unit<si::metre>);
static_assert(Unit<si::kilometre>);
static_assert(Unit<si::fps::mile>);
static_assert(Unit<si::metre_per_second>);
static_assert(!Unit<si::dim_length>);
static_assert(!Unit<int>);
static_assert(!Unit<std::chrono::seconds>);
// UnitOf
static_assert(UnitOf<si::metre, si::dim_length>);
static_assert(UnitOf<si::kilometre, si::dim_length>);
static_assert(UnitOf<si::fps::mile, si::dim_length>);
static_assert(!UnitOf<si::second, si::dim_length>);
// Representation
static_assert(Representation<int>);
static_assert(Representation<std::complex<double>>);
static_assert(!Representation<si::length<si::metre>>);
static_assert(!Representation<std::optional<si::length<si::metre>>>);
static_assert(!Representation<std::mutex>);
static_assert(!Representation<std::string>);
// Quantity
static_assert(Quantity<si::length<si::metre>>);
static_assert(!Quantity<std::chrono::seconds>);
static_assert(!Quantity<quantity_point<dynamic_origin<si::dim_length>, si::metre>>);
// QuantityPoint
static_assert(QuantityPoint<quantity_point<dynamic_origin<si::dim_length>, si::metre>>);
static_assert(!QuantityPoint<si::length<si::metre>>);
static_assert(!QuantityPoint<std::chrono::seconds>);
// QuantityLike
static_assert(QuantityLike<std::chrono::seconds>);
static_assert(QuantityLike<std::chrono::hours>);
static_assert(!QuantityLike<si::time<si::second>>);
static_assert(!QuantityLike<int>);
// WrappedQuantity
static_assert(wrapped_quantity_<std::optional<si::length<si::metre>>>);
static_assert(!wrapped_quantity_<std::pair<si::length<si::metre>, si::length<si::metre>>>);
// QuantityOf
static_assert(QuantityOf<si::length<si::metre>, si::dim_length>);
// TODO it seems `QuantityOf` is a bad name if `si::cgs::length<si::cgs::centimetre>` matches `si::fps::dim_length`
static_assert(QuantityOf<si::cgs::length<si::cgs::centimetre>, si::dim_length>);
static_assert(QuantityOf<si::cgs::length<si::metre>, si::dim_length>);
static_assert(QuantityOf<si::cgs::length<si::cgs::centimetre>, si::fps::dim_length>);
static_assert(!QuantityOf<si::cgs::length<si::cgs::centimetre>, si::dim_time>);
static_assert(
QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>, dynamic_origin<si::dim_time>>);
static_assert(QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>,
clock_origin<std::chrono::system_clock>>);
static_assert(!QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>,
clock_origin<std::chrono::system_clock>>);
static_assert(!QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>,
dynamic_origin<si::dim_time>>);
} // namespace