diff --git a/include/xo/unit/quantity.hpp b/include/xo/unit/quantity.hpp index 10658791..a6dc0391 100644 --- a/include/xo/unit/quantity.hpp +++ b/include/xo/unit/quantity.hpp @@ -45,6 +45,8 @@ namespace xo { }; namespace qty { + // ----- mass ----- + inline constexpr auto picograms(double x) { return quantity(x); } inline constexpr auto nanograms(double x) { return quantity(x); } inline constexpr auto micrograms(double x) { return quantity(x); } @@ -55,6 +57,38 @@ namespace xo { inline constexpr auto kilotonnes(double x) { return quantity(x); } inline constexpr auto megatonnes(double x) { return quantity(x); } inline constexpr auto gigatonnes(double x) { return quantity(x); } + + // ----- distance ----- + + inline constexpr auto picometers(double x) { return quantity(x); } + inline constexpr auto nanometers(double x) { return quantity(x); } + inline constexpr auto micrometers(double x) { return quantity(x); } + inline constexpr auto millimeters(double x) { return quantity(x); } + inline constexpr auto meters(double x) { return quantity(x); } + inline constexpr auto kilometers(double x) { return quantity(x); } + inline constexpr auto megameters(double x) { return quantity(x); } + inline constexpr auto gigameters(double x) { return quantity(x); } + + inline constexpr auto lightseconds(double x) { return quantity(x); } + inline constexpr auto astronomicalunits(double x) { return quantity(x); } + + // ----- time ----- + + inline constexpr auto picoseconds(double x) { return quantity(x); } + inline constexpr auto nanoseconds(double x) { return quantity(x); } + inline constexpr auto microseconds(double x) { return quantity(x); } + inline constexpr auto milliseconds(double x) { return quantity(x); } + inline constexpr auto seconds(double x) { return quantity(x); } + inline constexpr auto minutes(double x) { return quantity(x); } + inline constexpr auto hours(double x) { return quantity(x); } + inline constexpr auto days(double x) { return quantity(x); } + inline constexpr auto weeks(double x) { return quantity(x); } + inline constexpr auto months(double x) { return quantity(x); } + inline constexpr auto years(double x) { return quantity(x); } + inline constexpr auto year250s(double x) { return quantity(x); } + inline constexpr auto year360s(double x) { return quantity(x); } + inline constexpr auto year365s(double x) { return quantity(x); } + //inline constexpr auto year366s(double x) { return quantity(x); } } } /*namespace qty*/ } /*namespace xo*/ diff --git a/utest/quantity.test.cpp b/utest/quantity.test.cpp index 1f2d679a..ee232477 100644 --- a/utest/quantity.test.cpp +++ b/utest/quantity.test.cpp @@ -8,7 +8,7 @@ namespace xo { namespace qty { - TEST_CASE("quantity", "[quantity]") { + TEST_CASE("quantity.mass", "[quantity]") { constexpr bool c_debug_flag = true; // can get bits from /dev/random by uncommenting the 2nd line below @@ -17,7 +17,7 @@ namespace xo { //auto rng = xo::rng::xoshiro256ss(seed); - scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.quantity")); + scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.quantity.mass")); //log && log("(A)", xtag("foo", foo)); constexpr auto pg = qty::picograms(1.0); @@ -103,7 +103,217 @@ namespace xo { REQUIRE(tostr(kt) == "1kt"); REQUIRE(tostr(mt) == "1Mt"); REQUIRE(tostr(gt) == "1Gt"); - } /*TEST_CASE(quantity)*/ + } /*TEST_CASE(quantity.mass)*/ + + TEST_CASE("quantity.distance", "[quantity]") { + constexpr bool c_debug_flag = true; + + scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.quantity.distance")); + + constexpr auto pm = qty::picometers(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(pm) == sizeof(double)); + static_assert(pm.scale() == 1.0); + static_assert(pm.abbrev() == flatstring("pm")); + + constexpr auto nm = qty::nanometers(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(nm) == sizeof(double)); + static_assert(nm.scale() == 1.0); + static_assert(nm.abbrev() == flatstring("nm")); + + constexpr auto um = qty::micrometers(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(um) == sizeof(double)); + static_assert(um.scale() == 1.0); + static_assert(um.abbrev() == flatstring("um")); + + constexpr auto mm = qty::millimeters(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(mm) == sizeof(double)); + static_assert(mm.scale() == 1.0); + static_assert(mm.abbrev() == flatstring("mm")); + + constexpr auto m = qty::meters(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(m) == sizeof(double)); + static_assert(m.scale() == 1.0); + static_assert(m.abbrev() == flatstring("m")); + + constexpr auto km = qty::kilometers(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(km) == sizeof(double)); + static_assert(km.scale() == 1.0); + static_assert(km.abbrev() == flatstring("km")); + + constexpr auto Mm = qty::megameters(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(Mm) == sizeof(double)); + static_assert(Mm.scale() == 1.0); + static_assert(Mm.abbrev() == flatstring("Mm")); + + constexpr auto Gm = qty::gigameters(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(Gm) == sizeof(double)); + static_assert(Gm.scale() == 1.0); + static_assert(Gm.abbrev() == flatstring("Gm")); + + constexpr auto lsec = qty::lightseconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(lsec) == sizeof(double)); + static_assert(lsec.scale() == 1.0); + static_assert(lsec.abbrev() == flatstring("lsec")); + + constexpr auto AU = qty::astronomicalunits(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(AU) == sizeof(double)); + static_assert(AU.scale() == 1.0); + static_assert(AU.abbrev() == flatstring("AU")); + + log && log(xtag("pm.abbrev", pm.abbrev())); + log && log(xtag("nm.abbrev", nm.abbrev())); + log && log(xtag("um.abbrev", um.abbrev())); + log && log(xtag("mm.abbrev", mm.abbrev())); + log && log(xtag("m.abbrev", m.abbrev())); + log && log(xtag("km.abbrev", km.abbrev())); + log && log(xtag("Mm.abbrev", Mm.abbrev())); + log && log(xtag("Gm.abbrev", Gm.abbrev())); + log && log(xtag("lsec.abbrev", lsec.abbrev())); + log && log(xtag("AU.abbrev", AU.abbrev())); + + REQUIRE(tostr(pm) == "1pm"); + REQUIRE(tostr(nm) == "1nm"); + REQUIRE(tostr(um) == "1um"); + REQUIRE(tostr(mm) == "1mm"); + REQUIRE(tostr(m) == "1m"); + REQUIRE(tostr(km) == "1km"); + REQUIRE(tostr(Mm) == "1Mm"); + REQUIRE(tostr(Gm) == "1Gm"); + REQUIRE(tostr(lsec) == "1lsec"); + REQUIRE(tostr(AU) == "1AU"); + + } /*TEST_CASE(quantity.distance)*/ + + TEST_CASE("quantity.time", "[quantity]") { + constexpr bool c_debug_flag = true; + + scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.quantity.time")); + + constexpr auto ps = qty::picoseconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(ps) == sizeof(double)); + static_assert(ps.scale() == 1.0); + static_assert(ps.abbrev() == flatstring("ps")); + + constexpr auto ns = qty::nanoseconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(ns) == sizeof(double)); + static_assert(ns.scale() == 1.0); + static_assert(ns.abbrev() == flatstring("ns")); + + constexpr auto us = qty::microseconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(us) == sizeof(double)); + static_assert(us.scale() == 1.0); + static_assert(us.abbrev() == flatstring("us")); + + constexpr auto ms = qty::milliseconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(ms) == sizeof(double)); + static_assert(ms.scale() == 1.0); + static_assert(ms.abbrev() == flatstring("ms")); + + constexpr auto s = qty::seconds(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(s) == sizeof(double)); + static_assert(s.scale() == 1.0); + static_assert(s.abbrev() == flatstring("s")); + + constexpr auto min = qty::minutes(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(min) == sizeof(double)); + static_assert(min.scale() == 1.0); + static_assert(min.abbrev() == flatstring("min")); + + constexpr auto hr = qty::hours(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(hr) == sizeof(double)); + static_assert(hr.scale() == 1.0); + static_assert(hr.abbrev() == flatstring("hr")); + + constexpr auto dy = qty::days(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(dy) == sizeof(double)); + static_assert(dy.scale() == 1.0); + static_assert(dy.abbrev() == flatstring("dy")); + + constexpr auto wk = qty::weeks(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(wk) == sizeof(double)); + static_assert(wk.scale() == 1.0); + static_assert(wk.abbrev() == flatstring("wk")); + + constexpr auto mo = qty::months(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(mo) == sizeof(double)); + static_assert(mo.scale() == 1.0); + static_assert(mo.abbrev() == flatstring("mo")); + + constexpr auto yr = qty::years(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(yr) == sizeof(double)); + static_assert(yr.scale() == 1.0); + static_assert(yr.abbrev() == flatstring("yr")); + + constexpr auto yr250 = qty::year250s(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(yr250) == sizeof(double)); + static_assert(yr250.scale() == 1.0); + static_assert(yr250.abbrev() == flatstring("yr250")); + + constexpr auto yr360 = qty::year360s(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(yr360) == sizeof(double)); + static_assert(yr360.scale() == 1.0); + static_assert(yr360.abbrev() == flatstring("yr360")); + + constexpr auto yr365 = qty::year365s(1.0); + static_assert(quantity2_concept); + static_assert(sizeof(yr365) == sizeof(double)); + static_assert(yr365.scale() == 1.0); + static_assert(yr365.abbrev() == flatstring("yr365")); + + log && log(xtag("ps.abbrev", ps.abbrev())); + log && log(xtag("ns.abbrev", ns.abbrev())); + log && log(xtag("us.abbrev", us.abbrev())); + log && log(xtag("ms.abbrev", ms.abbrev())); + log && log(xtag("s.abbrev", s.abbrev())); + log && log(xtag("min.abbrev", min.abbrev())); + log && log(xtag("hr.abbrev", hr.abbrev())); + log && log(xtag("dy.abbrev", dy.abbrev())); + log && log(xtag("wk.abbrev", wk.abbrev())); + log && log(xtag("mo.abbrev", mo.abbrev())); + log && log(xtag("yr.abbrev", yr.abbrev())); + log && log(xtag("yr250.abbrev", yr250.abbrev())); + log && log(xtag("yr360.abbrev", yr360.abbrev())); + log && log(xtag("yr365.abbrev", yr365.abbrev())); + + REQUIRE(tostr(ps) == "1ps"); + REQUIRE(tostr(ns) == "1ns"); + REQUIRE(tostr(us) == "1us"); + REQUIRE(tostr(ms) == "1ms"); + REQUIRE(tostr(s) == "1s"); + REQUIRE(tostr(min) == "1min"); + REQUIRE(tostr(hr) == "1hr"); + REQUIRE(tostr(dy) == "1dy"); + REQUIRE(tostr(wk) == "1wk"); + REQUIRE(tostr(mo) == "1mo"); + REQUIRE(tostr(yr) == "1yr"); + REQUIRE(tostr(yr250) == "1yr250"); + REQUIRE(tostr(yr360) == "1yr360"); + REQUIRE(tostr(yr365) == "1yr365"); + } /*TEST_CASE(quantity.time)*/ + } /*namespace qty*/ } /*namespace xo*/