forked from mpusz/mp-units
refactor: number() and number_in() renamed to value() and value_in()
Resolves #423
This commit is contained in:
@@ -36,8 +36,8 @@ struct AlmostEqualsMatcher : Catch::Matchers::MatcherGenericBase {
|
||||
{
|
||||
using std::abs;
|
||||
using common = std::common_type_t<T, U>;
|
||||
const auto x = common(target_).number();
|
||||
const auto y = common(other).number();
|
||||
const auto x = common(target_).value();
|
||||
const auto y = common(other).value();
|
||||
const auto maxXYOne = std::max({typename T::rep{1}, abs(x), abs(y)});
|
||||
return abs(x - y) <= std::numeric_limits<typename T::rep>::epsilon() * maxXYOne;
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ TEST_CASE("piecewise_constant_distribution")
|
||||
3.0 * isq::length[si::metre]};
|
||||
|
||||
auto stl_dist = std::piecewise_constant_distribution<rep>(intervals_rep, [](rep val) { return val; });
|
||||
auto units_dist = mp_units::piecewise_constant_distribution<q>(intervals_qty, [](q qty) { return qty.number(); });
|
||||
auto units_dist = mp_units::piecewise_constant_distribution<q>(intervals_qty, [](q qty) { return qty.value(); });
|
||||
|
||||
CHECK(units_dist.intervals() == intervals_qty_vec);
|
||||
CHECK(units_dist.densities() == stl_dist.densities());
|
||||
@@ -573,7 +573,7 @@ TEST_CASE("piecewise_constant_distribution")
|
||||
|
||||
auto stl_dist = std::piecewise_constant_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
|
||||
auto units_dist =
|
||||
mp_units::piecewise_constant_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.number(); });
|
||||
mp_units::piecewise_constant_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.value(); });
|
||||
|
||||
CHECK(units_dist.intervals() == intervals_qty_vec);
|
||||
CHECK(units_dist.densities() == stl_dist.densities());
|
||||
@@ -626,7 +626,7 @@ TEST_CASE("piecewise_linear_distribution")
|
||||
3.0 * isq::length[si::metre]};
|
||||
|
||||
auto stl_dist = std::piecewise_linear_distribution<rep>(intervals_rep, [](rep val) { return val; });
|
||||
auto units_dist = mp_units::piecewise_linear_distribution<q>(intervals_qty, [](q qty) { return qty.number(); });
|
||||
auto units_dist = mp_units::piecewise_linear_distribution<q>(intervals_qty, [](q qty) { return qty.value(); });
|
||||
|
||||
CHECK(units_dist.intervals() == intervals_qty_vec);
|
||||
CHECK(units_dist.densities() == stl_dist.densities());
|
||||
@@ -640,7 +640,7 @@ TEST_CASE("piecewise_linear_distribution")
|
||||
|
||||
auto stl_dist = std::piecewise_linear_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
|
||||
auto units_dist =
|
||||
mp_units::piecewise_linear_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.number(); });
|
||||
mp_units::piecewise_linear_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.value(); });
|
||||
|
||||
CHECK(units_dist.intervals() == intervals_qty_vec);
|
||||
CHECK(units_dist.densities() == stl_dist.densities());
|
||||
|
||||
@@ -71,7 +71,7 @@ template<Quantity Q1, Quantity Q2>
|
||||
requires(typename Q1::rep v1, typename Q2::rep v2) { cross_product(v1, v2); }
|
||||
[[nodiscard]] QuantityOf<Q1::quantity_spec * Q2::quantity_spec> auto cross_product(const Q1& q1, const Q2& q2)
|
||||
{
|
||||
return cross_product(q1.number(), q2.number()) * (Q1::reference * Q2::reference);
|
||||
return cross_product(q1.value(), q2.value()) * (Q1::reference * Q2::reference);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -83,21 +83,21 @@ TEST_CASE("vector quantity", "[la]")
|
||||
SECTION("non-truncating")
|
||||
{
|
||||
const auto v = vector<int>{3, 2, 1} * isq::position_vector[km];
|
||||
CHECK(v.in(m).number() == vector<int>{3000, 2000, 1000});
|
||||
CHECK(v.in(m).value() == vector<int>{3000, 2000, 1000});
|
||||
}
|
||||
|
||||
SECTION("truncating")
|
||||
{
|
||||
const auto v = vector<int>{1001, 1002, 1003} * isq::position_vector[m];
|
||||
CHECK(value_cast<km>(v).number() == vector<int>{1, 1, 1});
|
||||
CHECK(value_cast<km>(v).value() == vector<int>{1, 1, 1});
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("to scalar magnitude")
|
||||
{
|
||||
const auto v = vector<int>{2, 3, 6} * isq::velocity[km / h];
|
||||
const auto speed = get_magnitude(v.number()) * isq::speed[v.unit]; // TODO can we do better here?
|
||||
CHECK(speed.number() == 7);
|
||||
const auto speed = get_magnitude(v.value()) * isq::speed[v.unit]; // TODO can we do better here?
|
||||
CHECK(speed.value() == 7);
|
||||
}
|
||||
|
||||
SECTION("multiply by scalar value")
|
||||
@@ -106,14 +106,14 @@ TEST_CASE("vector quantity", "[la]")
|
||||
|
||||
SECTION("integral")
|
||||
{
|
||||
SECTION("scalar on LHS") { CHECK((2 * v).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * 2).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on LHS") { CHECK((2 * v).value() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * 2).value() == vector<int>{2, 4, 6}); }
|
||||
}
|
||||
|
||||
SECTION("floating-point")
|
||||
{
|
||||
SECTION("scalar on LHS") { CHECK((0.5 * v).number() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * 0.5).number() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on LHS") { CHECK((0.5 * v).value() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * 0.5).value() == vector<double>{0.5, 1., 1.5}); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ TEST_CASE("vector quantity", "[la]")
|
||||
{
|
||||
const auto v = vector<int>{2, 4, 6} * isq::position_vector[m];
|
||||
|
||||
SECTION("integral") { CHECK((v / 2).number() == vector<int>{1, 2, 3}); }
|
||||
SECTION("floating-point") { CHECK((v / 0.5).number() == vector<double>{4., 8., 12.}); }
|
||||
SECTION("integral") { CHECK((v / 2).value() == vector<int>{1, 2, 3}); }
|
||||
SECTION("floating-point") { CHECK((v / 0.5).value() == vector<double>{4., 8., 12.}); }
|
||||
}
|
||||
|
||||
SECTION("add")
|
||||
@@ -132,12 +132,12 @@ TEST_CASE("vector quantity", "[la]")
|
||||
SECTION("same unit")
|
||||
{
|
||||
const auto u = vector<int>{3, 2, 1} * isq::position_vector[m];
|
||||
CHECK((v + u).number() == vector<int>{4, 4, 4});
|
||||
CHECK((v + u).value() == vector<int>{4, 4, 4});
|
||||
}
|
||||
SECTION("different units")
|
||||
{
|
||||
const auto u = vector<int>{3, 2, 1} * isq::position_vector[km];
|
||||
CHECK((v + u).number() == vector<int>{3001, 2002, 1003});
|
||||
CHECK((v + u).value() == vector<int>{3001, 2002, 1003});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,12 +148,12 @@ TEST_CASE("vector quantity", "[la]")
|
||||
SECTION("same unit")
|
||||
{
|
||||
const auto u = vector<int>{3, 2, 1} * isq::position_vector[m];
|
||||
CHECK((v - u).number() == vector<int>{-2, 0, 2});
|
||||
CHECK((v - u).value() == vector<int>{-2, 0, 2});
|
||||
}
|
||||
SECTION("different units")
|
||||
{
|
||||
const auto u = vector<int>{3, 2, 1} * isq::position_vector[km];
|
||||
CHECK((v - u).number() == vector<int>{-2999, -1998, -997});
|
||||
CHECK((v - u).value() == vector<int>{-2999, -1998, -997});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,25 +167,25 @@ TEST_CASE("vector quantity", "[la]")
|
||||
|
||||
SECTION("derived_quantity_spec")
|
||||
{
|
||||
SECTION("scalar on LHS") { CHECK((mass * v).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * mass).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on LHS") { CHECK((mass * v).value() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * mass).value() == vector<int>{2, 4, 6}); }
|
||||
}
|
||||
SECTION("quantity_cast to momentum")
|
||||
{
|
||||
SECTION("scalar on LHS") { CHECK(quantity_cast<isq::momentum>(mass * v).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK(quantity_cast<isq::momentum>(v * mass).number() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on LHS") { CHECK(quantity_cast<isq::momentum>(mass * v).value() == vector<int>{2, 4, 6}); }
|
||||
SECTION("scalar on RHS") { CHECK(quantity_cast<isq::momentum>(v * mass).value() == vector<int>{2, 4, 6}); }
|
||||
}
|
||||
SECTION("quantity of momentum")
|
||||
{
|
||||
SECTION("scalar on LHS")
|
||||
{
|
||||
const quantity<isq::momentum[N * s], vector<int>> momentum = mass * v;
|
||||
CHECK(momentum.number() == vector<int>{2, 4, 6});
|
||||
CHECK(momentum.value() == vector<int>{2, 4, 6});
|
||||
}
|
||||
SECTION("scalar on RHS")
|
||||
{
|
||||
const quantity<isq::momentum[N * s], vector<int>> momentum = v * mass;
|
||||
CHECK(momentum.number() == vector<int>{2, 4, 6});
|
||||
CHECK(momentum.value() == vector<int>{2, 4, 6});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,18 +196,18 @@ TEST_CASE("vector quantity", "[la]")
|
||||
|
||||
SECTION("derived_quantity_spec")
|
||||
{
|
||||
SECTION("scalar on LHS") { CHECK((mass * v).number() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * mass).number() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on LHS") { CHECK((mass * v).value() == vector<double>{0.5, 1., 1.5}); }
|
||||
SECTION("scalar on RHS") { CHECK((v * mass).value() == vector<double>{0.5, 1., 1.5}); }
|
||||
}
|
||||
SECTION("quantity_cast to momentum")
|
||||
{
|
||||
SECTION("scalar on LHS")
|
||||
{
|
||||
CHECK(quantity_cast<isq::momentum>(mass * v).number() == vector<double>{0.5, 1., 1.5});
|
||||
CHECK(quantity_cast<isq::momentum>(mass * v).value() == vector<double>{0.5, 1., 1.5});
|
||||
}
|
||||
SECTION("scalar on RHS")
|
||||
{
|
||||
CHECK(quantity_cast<isq::momentum>(v * mass).number() == vector<double>{0.5, 1., 1.5});
|
||||
CHECK(quantity_cast<isq::momentum>(v * mass).value() == vector<double>{0.5, 1., 1.5});
|
||||
}
|
||||
}
|
||||
SECTION("quantity of momentum")
|
||||
@@ -215,12 +215,12 @@ TEST_CASE("vector quantity", "[la]")
|
||||
SECTION("scalar on LHS")
|
||||
{
|
||||
const quantity<isq::momentum[N * s], vector<double>> momentum = mass * v;
|
||||
CHECK(momentum.number() == vector<double>{0.5, 1., 1.5});
|
||||
CHECK(momentum.value() == vector<double>{0.5, 1., 1.5});
|
||||
}
|
||||
SECTION("scalar on RHS")
|
||||
{
|
||||
const quantity<isq::momentum[N * s], vector<double>> momentum = v * mass;
|
||||
CHECK(momentum.number() == vector<double>{0.5, 1., 1.5});
|
||||
CHECK(momentum.value() == vector<double>{0.5, 1., 1.5});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,15 +234,15 @@ TEST_CASE("vector quantity", "[la]")
|
||||
{
|
||||
const auto dur = 2 * isq::duration[h];
|
||||
|
||||
SECTION("derived_quantity_spec") { CHECK((pos / dur).number() == vector<int>{15, 10, 5}); }
|
||||
SECTION("derived_quantity_spec") { CHECK((pos / dur).value() == vector<int>{15, 10, 5}); }
|
||||
SECTION("quantity_cast to velocity")
|
||||
{
|
||||
CHECK(quantity_cast<isq::velocity>(pos / dur).number() == vector<int>{15, 10, 5});
|
||||
CHECK(quantity_cast<isq::velocity>(pos / dur).value() == vector<int>{15, 10, 5});
|
||||
}
|
||||
SECTION("quantity of velocity")
|
||||
{
|
||||
const quantity<isq::velocity[km / h], vector<int>> v = pos / dur;
|
||||
CHECK(v.number() == vector<int>{15, 10, 5});
|
||||
CHECK(v.value() == vector<int>{15, 10, 5});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,15 +250,15 @@ TEST_CASE("vector quantity", "[la]")
|
||||
{
|
||||
const auto dur = 0.5 * isq::duration[h];
|
||||
|
||||
SECTION("derived_quantity_spec") { CHECK((pos / dur).number() == vector<double>{60, 40, 20}); }
|
||||
SECTION("derived_quantity_spec") { CHECK((pos / dur).value() == vector<double>{60, 40, 20}); }
|
||||
SECTION("quantity_cast to velocity")
|
||||
{
|
||||
CHECK(quantity_cast<isq::velocity>(pos / dur).number() == vector<double>{60, 40, 20});
|
||||
CHECK(quantity_cast<isq::velocity>(pos / dur).value() == vector<double>{60, 40, 20});
|
||||
}
|
||||
SECTION("quantity of velocity")
|
||||
{
|
||||
const quantity<isq::velocity[km / h], vector<double>> v = pos / dur;
|
||||
CHECK(v.number() == vector<double>{60, 40, 20});
|
||||
CHECK(v.value() == vector<double>{60, 40, 20});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,8 +294,8 @@ TEST_CASE("vector of quantities", "[la]")
|
||||
SECTION("to scalar magnitude")
|
||||
{
|
||||
const vector<quantity<isq::velocity[km / h], int>> v = {2 * (km / h), 3 * (km / h), 6 * (km / h)};
|
||||
const auto speed = get_magnitude(v).number() * isq::speed[v(0).unit]; // TODO can we do better here?
|
||||
CHECK(speed.number() == 7);
|
||||
const auto speed = get_magnitude(v).value() * isq::speed[v(0).unit]; // TODO can we do better here?
|
||||
CHECK(speed.value() == 7);
|
||||
}
|
||||
|
||||
SECTION("multiply by scalar value")
|
||||
|
||||
@@ -90,12 +90,12 @@ TEST_CASE("numeric_limits functions", "[limits]")
|
||||
{
|
||||
SECTION("'epsilon' works as expected using default floating type")
|
||||
{
|
||||
REQUIRE(epsilon<double>(isq::length[m]).number() ==
|
||||
REQUIRE(epsilon<double>(isq::length[m]).value() ==
|
||||
std::numeric_limits<decltype(1. * isq::length[m])::rep>::epsilon());
|
||||
}
|
||||
SECTION("'epsilon' works as expected using integers")
|
||||
{
|
||||
REQUIRE(epsilon<int>(isq::length[m]).number() == std::numeric_limits<decltype(1 * isq::length[m])::rep>::epsilon());
|
||||
REQUIRE(epsilon<int>(isq::length[m]).value() == std::numeric_limits<decltype(1 * isq::length[m])::rep>::epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user