xo-unit: + Quantity.add support

This commit is contained in:
Roland Conybeare 2024-04-23 15:36:11 -04:00
commit e1d7f62ca6
6 changed files with 120 additions and 13 deletions

View file

@ -1119,6 +1119,45 @@ namespace xo {
//REQUIRE(ng2.scale() == 1);
} /*TEST_CASE(Quantity5)*/
TEST_CASE("Quantity6", "[Quantity]") {
constexpr bool c_debug_flag = true;
// can get bits from /dev/random by uncommenting the 2nd line below
//uint64_t seed = xxx;
//rng::Seed<xoshio256ss> seed;
//auto rng = xo::rng::xoshiro256ss(seed);
scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.Quantity6"));
//log && log("(A)", xtag("foo", foo));
/* not constexpr until c++26 */
Quantity ng = unit_qty(su2::nanogram);
Quantity ug = unit_qty(su2::microgram);
{
auto sum1 = ng + ug;
log && log(xtag("ng+ug", sum1));
/* units will be nanograms, since that's on lhs */
REQUIRE(sum1.unit().n_bpu() == 1);
REQUIRE(sum1.unit()[0].scalefactor() == scalefactor_ratio_type(1, 1000000000));
REQUIRE(sum1.scale() == 1001.0);
}
{
auto sum2 = ug + ng;
log && log(xtag("ug+ng", sum2));
/* units will be micrograms, since that's on rhs */
REQUIRE(sum2.unit().n_bpu() == 1);
REQUIRE(sum2.unit()[0].scalefactor() == scalefactor_ratio_type(1, 1000000));
REQUIRE(sum2.scale() == 1.001);
}
//REQUIRE(ng2.scale() == 1);
} /*TEST_CASE(Quantity6)*/
} /*namespace ut*/
} /*namespace xo*/