xo-unit: utest tidy
This commit is contained in:
parent
c5c0ab72ef
commit
e95a21f83f
2 changed files with 296 additions and 361 deletions
|
|
@ -141,356 +141,6 @@ namespace xo {
|
|||
static_assert(ng2.natural_unit_.n_bpu() == 0);
|
||||
} /*TEST_CASE(scaled_unit1)*/
|
||||
|
||||
TEST_CASE("Quantity", "[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.Quantity"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
auto ng = unit_qty(su2::nanogram);
|
||||
|
||||
log && log(xtag("ng", ng));
|
||||
|
||||
REQUIRE(ng.scale() == 1);
|
||||
} /*TEST_CASE(Quantity)*/
|
||||
|
||||
TEST_CASE("Quantity2", "[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.Quantity2"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
auto ng2 = ng * ng;
|
||||
|
||||
log && log(xtag("ng*ng", ng2));
|
||||
|
||||
REQUIRE(ng2.scale() == 1);
|
||||
} /*TEST_CASE(Quantity2)*/
|
||||
|
||||
TEST_CASE("Quantity3", "[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.Quantity3"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
auto ng0 = ng / ng;
|
||||
|
||||
log && log(xtag("ng/ng", ng0));
|
||||
|
||||
REQUIRE(ng0.scale() == 1);
|
||||
} /*TEST_CASE(Quantity3)*/
|
||||
|
||||
TEST_CASE("Quantity4", "[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.Quantity4"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
Quantity ug = unit_qty(su2::microgram);
|
||||
|
||||
{
|
||||
auto prod1 = ng * ug;
|
||||
log && log(xtag("ng*ug", prod1));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(prod1.unit().n_bpu() == 1);
|
||||
REQUIRE(prod1.unit()[0].native_dim() == dim::mass);
|
||||
REQUIRE(prod1.unit()[0].scalefactor() == scalefactor_ratio_type(1, 1000000000));
|
||||
REQUIRE(prod1.unit()[0].power() == power_ratio_type(2, 1));
|
||||
REQUIRE(prod1.scale() == 1000);
|
||||
}
|
||||
|
||||
{
|
||||
auto prod2 = ug * ng;
|
||||
log && log(xtag("ug*ng", prod2));
|
||||
|
||||
REQUIRE(prod2.unit().n_bpu() == 1);
|
||||
REQUIRE(prod2.unit()[0].native_dim() == dim::mass);
|
||||
REQUIRE(prod2.unit()[0].native_dim() == dim::mass);
|
||||
REQUIRE(prod2.unit()[0].scalefactor() == scalefactor_ratio_type(1, 1000000));
|
||||
REQUIRE(prod2.unit()[0].power() == power_ratio_type(2, 1));
|
||||
REQUIRE(prod2.scale() == 0.001);
|
||||
}
|
||||
|
||||
//REQUIRE(ng2.scale() == 1);
|
||||
} /*TEST_CASE(Quantity4)*/
|
||||
|
||||
TEST_CASE("Quantity5", "[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.Quantity5"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
Quantity ug = unit_qty(su2::microgram);
|
||||
|
||||
{
|
||||
auto ratio1 = ng / ug;
|
||||
log && log(xtag("ng/ug", ratio1));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(ratio1.unit().n_bpu() == 0);
|
||||
REQUIRE(ratio1.scale() == 0.001);
|
||||
}
|
||||
|
||||
{
|
||||
auto ratio2 = ug / ng;
|
||||
log && log(xtag("ug/ng", ratio2));
|
||||
|
||||
REQUIRE(ratio2.unit().n_bpu() == 0);
|
||||
REQUIRE(ratio2.scale() == 1000.0);
|
||||
}
|
||||
|
||||
//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)*/
|
||||
|
||||
TEST_CASE("Quantity7", "[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.Quantity7"));
|
||||
//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() == -999.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() == 0.999);
|
||||
}
|
||||
|
||||
//REQUIRE(ng2.scale() == 1);
|
||||
} /*TEST_CASE(Quantity7)*/
|
||||
|
||||
TEST_CASE("Quantity.compare", "[Quantity.compare]") {
|
||||
constexpr bool c_debug_flag = false;
|
||||
|
||||
// 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.Quantity.compare"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = 1000 * unit_qty(su2::nanogram);
|
||||
Quantity ug = unit_qty(su2::microgram);
|
||||
|
||||
{
|
||||
auto cmp = (ng == ug);
|
||||
log && log(xtag("ng==ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng != ug);
|
||||
log && log(xtag("ng!=ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng < ug);
|
||||
log && log(xtag("ng<ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng <= ug);
|
||||
log && log(xtag("ng=<ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng > ug);
|
||||
log && log(xtag("ng>ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng >= ug);
|
||||
log && log(xtag("ng>=ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
} /*TEST_CASE(Quantity.compare)*/
|
||||
|
||||
TEST_CASE("Quantity.compare2", "[Quantity]") {
|
||||
constexpr bool c_debug_flag = false;
|
||||
|
||||
// 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.Quantity.compare2"));
|
||||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
Quantity ug = unit_qty(su2::microgram);
|
||||
|
||||
{
|
||||
auto cmp = (ng == ug);
|
||||
log && log(xtag("ng==ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng != ug);
|
||||
log && log(xtag("ng!=ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng < ug);
|
||||
log && log(xtag("ng<ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng <= ug);
|
||||
log && log(xtag("ng=<ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == true);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng > ug);
|
||||
log && log(xtag("ng>ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
{
|
||||
auto cmp = (ng >= ug);
|
||||
log && log(xtag("ng>=ug", cmp));
|
||||
|
||||
/* units will be nanograms, since that's on lhs */
|
||||
REQUIRE(cmp == false);
|
||||
}
|
||||
|
||||
} /*TEST_CASE(Quantity.compare2)*/
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue