Revert "test: custom_rep_test_min_expl updated for V2"

This reverts commit 2b2f381ad5.
This commit is contained in:
Mateusz Pusz
2023-06-12 12:10:46 +03:00
parent c8c865ec39
commit 46f1a00f4b
2 changed files with 67 additions and 81 deletions

View File

@@ -35,7 +35,6 @@ add_library(
chrono_test.cpp chrono_test.cpp
concepts_test.cpp concepts_test.cpp
# custom_rep_test_min_expl.cpp # custom_rep_test_min_expl.cpp
custom_rep_test_min_impl.cpp
dimension_test.cpp dimension_test.cpp
fixed_string_test.cpp fixed_string_test.cpp
fractional_exponent_quantity.cpp fractional_exponent_quantity.cpp

View File

@@ -20,7 +20,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
#include <mp-units/systems/si/units.h> #include <units/generic/dimensionless.h>
#include <units/isq/si/length.h>
#include <units/isq/si/prefixes.h>
#include <ostream> #include <ostream>
#include <type_traits> #include <type_traits>
@@ -41,8 +43,6 @@ template<int Mode = 0>
class min_expl { class min_expl {
std::intmax_t value_; std::intmax_t value_;
public: public:
using value_type = std::intmax_t;
// default construction // default construction
min_expl() min_expl()
requires(Mode != 1) requires(Mode != 1)
@@ -103,9 +103,6 @@ public:
} // namespace } // namespace
template<int Mode>
inline constexpr bool mp_units::is_scalar<min_expl<Mode>> = true;
template<int Mode> template<int Mode>
struct std::common_type<std::intmax_t, min_expl<Mode>> : std::type_identity<min_expl<Mode>> {}; struct std::common_type<std::intmax_t, min_expl<Mode>> : std::type_identity<min_expl<Mode>> {};
template<int Mode> template<int Mode>
@@ -113,68 +110,63 @@ struct std::common_type<min_expl<Mode>, std::intmax_t> : std::type_identity<min_
namespace { namespace {
using namespace mp_units; using namespace units;
using namespace units::isq::si;
// quantity explicitly constructible (not convertible) from the representation type // quantity explicitly constructible (not convertible) from the representation type
static_assert(!std::constructible_from<quantity<si::metre, min_expl<>>, min_expl<>>); static_assert(std::constructible_from<length<metre, min_expl<>>, min_expl<>>);
static_assert(!std::convertible_to<min_expl<>, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<min_expl<>, length<metre, min_expl<>>>);
// not constructible from an underlying type // not constructible from an underlying type
static_assert(!std::constructible_from<quantity<si::metre, min_expl<>>, int>); static_assert(!std::constructible_from<length<metre, min_expl<>>, int>);
static_assert(!std::convertible_to<int, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<int, length<metre, min_expl<>>>);
// multiply syntax should work
template<typename T, Unit auto U>
concept creates_quantity = requires { T{} * U; };
static_assert(creates_quantity<min_expl<>, si::metre>);
// dimensionless quantity implicitly convertible from the representation type // dimensionless quantity implicitly convertible from the representation type
static_assert(std::constructible_from<quantity<one, min_expl<>>, min_expl<>>); static_assert(std::constructible_from<dimensionless<one, min_expl<>>, min_expl<>>);
static_assert(std::convertible_to<min_expl<>, quantity<one, min_expl<>>>); static_assert(std::convertible_to<min_expl<>, dimensionless<one, min_expl<>>>);
// but not from an underlying type // but not from an underlying type
static_assert(std::constructible_from<quantity<one, min_expl<>>, int>); static_assert(!std::constructible_from<dimensionless<one, min_expl<>>, int>);
static_assert(!std::convertible_to<int, quantity<one, min_expl<>>>); static_assert(!std::convertible_to<int, dimensionless<one, min_expl<>>>);
// or for ratio != 1 // or for ratio != 1
static_assert(!std::constructible_from<quantity<percent, min_expl<>>, min_expl<>>); static_assert(std::constructible_from<dimensionless<percent, min_expl<>>, min_expl<>>);
static_assert(!std::convertible_to<min_expl<>, quantity<percent, min_expl<>>>); static_assert(!std::convertible_to<min_expl<>, dimensionless<percent, min_expl<>>>);
// quantity convertible from itself // quantity convertible from itself
static_assert(std::constructible_from<quantity<si::metre, min_expl<>>, quantity<si::metre, min_expl<>>>); static_assert(std::constructible_from<length<metre, min_expl<>>, length<metre, min_expl<>>>);
static_assert(std::convertible_to<quantity<si::metre, min_expl<>>, quantity<si::metre, min_expl<>>>); static_assert(std::convertible_to<length<metre, min_expl<>>, length<metre, min_expl<>>>);
// not convertible from an underlying type // not convertible from an underlying type
static_assert(std::constructible_from<quantity<si::metre, min_expl<>>, quantity<si::metre, int>>); static_assert(!std::constructible_from<length<metre, min_expl<>>, length<metre, int>>);
static_assert(!std::convertible_to<quantity<si::metre, int>, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<length<metre, int>, length<metre, min_expl<>>>);
// quantity convertible from another non truncating unit // quantity convertible from another non truncating unit
static_assert(std::constructible_from<quantity<si::metre, min_expl<>>, quantity<si::kilo<si::metre>, min_expl<>>>); static_assert(std::constructible_from<length<metre, min_expl<>>, length<kilometre, min_expl<>>>);
static_assert(std::convertible_to<quantity<si::kilo<si::metre>, min_expl<>>, quantity<si::metre, min_expl<>>>); static_assert(std::convertible_to<length<kilometre, min_expl<>>, length<metre, min_expl<>>>);
// quantity not convertible from another truncating unit // quantity not convertible from another truncating unit
static_assert(!std::constructible_from<quantity<si::kilo<si::metre>, min_expl<>>, quantity<si::metre, min_expl<>>>); static_assert(!std::constructible_from<length<kilometre, min_expl<>>, length<metre, min_expl<>>>);
static_assert(!std::convertible_to<quantity<si::metre, min_expl<>>, quantity<si::kilo<si::metre>, min_expl<>>>); static_assert(!std::convertible_to<length<metre, min_expl<>>, length<kilometre, min_expl<>>>);
// rep type with explicit constructor - implicit construction of rep not allowed // rep type with explicit constructor - implicit construction of rep not allowed
static_assert(!std::constructible_from<quantity<si::metre, min_expl<>>, int>); static_assert(!std::constructible_from<length<metre, min_expl<>>, int>);
static_assert(!std::convertible_to<int, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<int, length<metre, min_expl<>>>);
static_assert(!std::constructible_from<quantity<si::metre, min_expl<>>, quantity<si::metre, int>>); static_assert(!std::constructible_from<length<metre, min_expl<>>, length<metre, int>>);
static_assert(!std::convertible_to<quantity<si::metre, int>, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<length<metre, int>, length<metre, min_expl<>>>);
static_assert(!std::constructible_from<quantity<si::metre, int>, min_expl<>>); static_assert(!std::constructible_from<length<metre, int>, min_expl<>>);
static_assert(!std::convertible_to<min_expl<>, quantity<si::metre, int>>); static_assert(!std::convertible_to<min_expl<>, length<metre, int>>);
static_assert(!std::constructible_from<quantity<si::metre, int>, quantity<si::metre, min_expl<>>>); static_assert(!std::constructible_from<length<metre, int>, length<metre, min_expl<>>>);
static_assert(!std::convertible_to<quantity<si::metre, min_expl<>>, quantity<si::metre, int>>); static_assert(!std::convertible_to<length<metre, min_expl<>>, length<metre, int>>);
static_assert(!std::constructible_from<quantity<si::metre, min_expl<>>, quantity<one>>); static_assert(!std::constructible_from<length<metre, min_expl<>>, dimensionless<one>>);
static_assert(!std::convertible_to<quantity<one>, quantity<si::metre, min_expl<>>>); static_assert(!std::convertible_to<dimensionless<one>, length<metre, min_expl<>>>);
static_assert(!std::constructible_from<quantity<si::metre, int>, quantity<one, min_expl<>>>); static_assert(!std::constructible_from<length<metre, int>, dimensionless<one, min_expl<>>>);
static_assert(!std::convertible_to<quantity<one, min_expl<>>, quantity<si::metre, int>>); static_assert(!std::convertible_to<dimensionless<one, min_expl<>>, length<metre, int>>);
// all operations needed to satisfy concept // all operations needed to satisfy concept
static_assert(Representation<min_expl<>>); static_assert(Representation<min_expl<>>);
@@ -194,7 +186,7 @@ static_assert(!Representation<min_expl<9>>);
// quantity's operators should mirror the representation type capabilities // quantity's operators should mirror the representation type capabilities
template<typename Rep> template<typename Rep>
concept invalid_member_operations = requires(quantity<si::metre, Rep> lhs) { concept invalid_member_operations = requires(length<metre, Rep> lhs) {
requires !requires { +lhs; }; requires !requires { +lhs; };
requires !requires { -lhs; }; requires !requires { -lhs; };
requires !requires { ++lhs; }; requires !requires { ++lhs; };
@@ -202,55 +194,50 @@ concept invalid_member_operations = requires(quantity<si::metre, Rep> lhs) {
requires !requires { --lhs; }; requires !requires { --lhs; };
requires !requires { lhs--; }; requires !requires { lhs--; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs += rhs; }; requires !requires(length<metre, Rep> rhs) { lhs += rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs -= rhs; }; requires !requires(length<metre, Rep> rhs) { lhs -= rhs; };
requires !requires(Rep rhs) { lhs *= rhs; }; requires !requires(Rep rhs) { lhs *= rhs; };
requires !requires(Rep rhs) { lhs /= rhs; }; requires !requires(Rep rhs) { lhs /= rhs; };
requires !requires(Rep rhs) { lhs %= rhs; }; requires !requires(Rep rhs) { lhs %= rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs %= rhs; }; requires !requires(length<metre, Rep> rhs) { lhs %= rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs + rhs; }; requires !requires(length<metre, Rep> rhs) { lhs + rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs - rhs; }; requires !requires(length<metre, Rep> rhs) { lhs - rhs; };
requires !requires(Rep rhs) { lhs % rhs; }; requires !requires(Rep rhs) { lhs % rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs % rhs; }; requires !requires(length<metre, Rep> rhs) { lhs % rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs < rhs; }; requires !requires(length<metre, Rep> rhs) { lhs < rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs > rhs; }; requires !requires(length<metre, Rep> rhs) { lhs > rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs <= rhs; }; requires !requires(length<metre, Rep> rhs) { lhs <= rhs; };
requires !requires(quantity<si::metre, Rep> rhs) { lhs >= rhs; }; requires !requires(length<metre, Rep> rhs) { lhs >= rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs + rhs; }; requires !requires(length<metre, int> rhs) { lhs + rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs - rhs; }; requires !requires(length<metre, int> rhs) { lhs - rhs; };
requires !requires(int rhs) { lhs % rhs; }; requires !requires(int rhs) { lhs % rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs % rhs; }; requires !requires(length<metre, int> rhs) { lhs % rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs == rhs; }; requires !requires(length<metre, int> rhs) { lhs == rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs != rhs; }; requires !requires(length<metre, int> rhs) { lhs != rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs < rhs; }; requires !requires(length<metre, int> rhs) { lhs < rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs > rhs; }; requires !requires(length<metre, int> rhs) { lhs > rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs <= rhs; }; requires !requires(length<metre, int> rhs) { lhs <= rhs; };
requires !requires(quantity<si::metre, int> rhs) { lhs >= rhs; }; requires !requires(length<metre, int> rhs) { lhs >= rhs; };
requires !requires(std::ostream os) { os << lhs; }; requires !requires(std::ostream os) { os << lhs; };
}; };
static_assert(invalid_member_operations<min_expl<>>); static_assert(invalid_member_operations<min_expl<>>);
// equality // equality
static_assert(quantity<si::kilo<si::metre>, min_expl<>>(min_expl(2)) == static_assert(length<kilometre, min_expl<>>(min_expl(2)) == length<metre, min_expl<>>(min_expl(2000)));
quantity<si::metre, min_expl<>>(min_expl(2'000))); static_assert(length<metre, min_expl<>>(min_expl(123)) * min_expl(2) == length<metre, min_expl<>>(min_expl(246)));
static_assert(quantity<si::metre, min_expl<>>(min_expl(123)) * min_expl(2) == static_assert(length<metre, min_expl<>>(min_expl(123)) * quantity{min_expl(2)} ==
quantity<si::metre, min_expl<>>(min_expl(246))); length<metre, min_expl<>>(min_expl(246)));
static_assert(quantity<si::metre, min_expl<>>(min_expl(123)) * quantity{min_expl(2)} == static_assert(min_expl(2) * length<metre, min_expl<>>(min_expl(123)) == length<metre, min_expl<>>(min_expl(246)));
quantity<si::metre, min_expl<>>(min_expl(246))); static_assert(quantity{min_expl(2)} * length<metre, min_expl<>>(min_expl(123)) ==
static_assert(min_expl(2) * quantity<si::metre, min_expl<>>(min_expl(123)) == length<metre, min_expl<>>(min_expl(246)));
quantity<si::metre, min_expl<>>(min_expl(246))); static_assert(length<metre, min_expl<>>(min_expl(246)) / min_expl(2) == length<metre, min_expl<>>(min_expl(123)));
static_assert(quantity{min_expl(2)} * quantity<si::metre, min_expl<>>(min_expl(123)) == static_assert(length<metre, min_expl<>>(min_expl(246)) / quantity{min_expl(2)} ==
quantity<si::metre, min_expl<>>(min_expl(246))); length<metre, min_expl<>>(min_expl(123)));
static_assert(quantity<si::metre, min_expl<>>(min_expl(246)) / min_expl(2) == static_assert(length<metre, min_expl<>>(min_expl(246)) / length<metre, min_expl<>>(min_expl(2)) ==
quantity<si::metre, min_expl<>>(min_expl(123)));
static_assert(quantity<si::metre, min_expl<>>(min_expl(246)) / quantity{min_expl(2)} ==
quantity<si::metre, min_expl<>>(min_expl(123)));
static_assert(quantity<si::metre, min_expl<>>(min_expl(246)) / quantity<si::metre, min_expl<>>(min_expl(2)) ==
quantity{min_expl(123)}); quantity{min_expl(123)});
static_assert(quantity<si::metre, min_expl<>>(min_expl(246)) / quantity<si::metre, min_expl<>>(min_expl(2)) == static_assert(length<metre, min_expl<>>(min_expl(246)) / length<metre, min_expl<>>(min_expl(2)) == min_expl(123));
min_expl(123));
} // namespace } // namespace