diff --git a/include/xo/unit/natural_unit.hpp b/include/xo/unit/natural_unit.hpp index 96272fff..bbd2f249 100644 --- a/include/xo/unit/natural_unit.hpp +++ b/include/xo/unit/natural_unit.hpp @@ -122,7 +122,7 @@ namespace xo { return retval; } - private: + public: /* need public members so that a natural_unit instance can be a non-type template parameter (a structural type) */ /** @brief the number of occupied slots in @c bpu_v_ **/ std::size_t n_bpu_; diff --git a/include/xo/unit/scaled_unit.hpp b/include/xo/unit/scaled_unit.hpp index bf696f5d..7653c391 100644 --- a/include/xo/unit/scaled_unit.hpp +++ b/include/xo/unit/scaled_unit.hpp @@ -24,9 +24,9 @@ namespace xo { {} constexpr scaled_unit reciprocal() const { - return scaled_unit(nu_reciprocal(natural_unit_, - 1 / outer_scale_factor_, - 1.0 / outer_scale_sq_)); + return scaled_unit(natural_unit_.reciprocal(), + 1 / outer_scale_factor_, + 1.0 / outer_scale_sq_); } natural_unit natural_unit_; diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 0fcfa866..a2166a52 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -6,6 +6,7 @@ set(SELF_SRCS Quantity.test.cpp bpu.test.cpp bu.test.cpp + natural_unit.test.cpp unit.test.cpp #quantity.test.cpp ) diff --git a/utest/bpu.test.cpp b/utest/bpu.test.cpp index 0c4265b0..d2ca41d2 100644 --- a/utest/bpu.test.cpp +++ b/utest/bpu.test.cpp @@ -9,7 +9,7 @@ namespace xo { using bpu64_type = bpu; /* compile-time test: - * verify we can use a bpu as a non-type template parameter. + * verify we can use a bpu64_type instance as a non-type template parameter. * Will need this for quantity> */ template diff --git a/utest/natural_unit.test.cpp b/utest/natural_unit.test.cpp new file mode 100644 index 00000000..d3c0f756 --- /dev/null +++ b/utest/natural_unit.test.cpp @@ -0,0 +1,37 @@ +/* @file natural_unit.test.cpp */ + +#include "xo/unit/natural_unit.hpp" +#include + +namespace xo { + namespace qty { + using nu64_type = natural_unit; + + /* compile-time test: + * verify we can use an nu64_type instance as a non-type template parameter. + * Will need this for quantity> + */ + template + constexpr nu_abbrev_type nu_mpl_abbrev = nu.abbrev(); + + TEST_CASE("natural_unit", "[natural_unit]") { + //constexpr bool c_debug_flag = false; + + // can get bits from /dev/random by uncommenting the 2nd line below + //uint64_t seed = xxx; + //rng::Seed seed; + + //auto rng = xo::rng::xoshiro256ss(seed); + + //scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.bpu")); + //log && log("(A)", xtag("foo", foo)); + + static_assert(nu_mpl_abbrev == nu::gram.abbrev()); + REQUIRE(nu_mpl_abbrev == nu::gram.abbrev()); + + } /*TEST_CASE(natural_unit)*/ + } /*namespace qty*/ +} /*namespace xo*/ + + +/* end natural_unit.test.cpp */ diff --git a/utest/scaled_unit.test.cpp b/utest/scaled_unit.test.cpp new file mode 100644 index 00000000..8e72a7b0 --- /dev/null +++ b/utest/scaled_unit.test.cpp @@ -0,0 +1,41 @@ +/* @file scaled_unit.test.cpp */ + +#include "xo/unit/scaled_unit.hpp" +#include + +namespace xo { + namespace qty { + using su64_type = scaled_unit; + + /* compile-time test: + * verify we can use an su64_type instance as a non-type template parameter. + * Will need this for quantity> + */ + template + constexpr su64_type su_reciprocal = su.reciprocal(); + + TEST_CASE("scaled_unit", "[scaled_unit]") { + //constexpr bool c_debug_flag = false; + + // can get bits from /dev/random by uncommenting the 2nd line below + //uint64_t seed = xxx; + //rng::Seed seed; + + //auto rng = xo::rng::xoshiro256ss(seed); + + //scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.bpu")); + //log && log("(A)", xtag("foo", foo)); + + static_assert(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); + REQUIRE(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); + + static_assert(su_reciprocal.outer_scale_factor_ == 1); + REQUIRE(su_reciprocal.outer_scale_factor_ == 1); + + static_assert(su_reciprocal.outer_scale_sq_ == 1.0); + REQUIRE(su_reciprocal.outer_scale_sq_ == 1.0); + } /*TEST_CASE(scaled_unit)*/ + } /*namespace qty*/ +} /*namespace xo*/ + +/* end scaled_unit.test.cpp */