From 9350f017b1bb3f3647b085e408f89ffd7b85ab9f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 28 Apr 2024 15:09:01 -0400 Subject: [PATCH] xo-unit: utest: + bpu test to verify bpu is structurual type --- include/xo/unit/basis_unit.hpp | 1 + include/xo/unit/bpu.hpp | 3 ++- utest/CMakeLists.txt | 1 + utest/bpu.test.cpp | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 utest/bpu.test.cpp diff --git a/include/xo/unit/basis_unit.hpp b/include/xo/unit/basis_unit.hpp index 57f440b0..922470a0 100644 --- a/include/xo/unit/basis_unit.hpp +++ b/include/xo/unit/basis_unit.hpp @@ -31,6 +31,7 @@ namespace xo { constexpr basis_unit & operator=(const basis_unit & x) = default; + public: /* need public members so that a basis_unit instance can be a non-type template parameter (a structural type) */ /** @brief identifies a native unit, e.g. time (in seconds) **/ dim native_dim_ = dim::invalid; /** @brief this unit defined as multiple scalefactor times native unit **/ diff --git a/include/xo/unit/bpu.hpp b/include/xo/unit/bpu.hpp index 5256c8ed..d9df57a2 100644 --- a/include/xo/unit/bpu.hpp +++ b/include/xo/unit/bpu.hpp @@ -109,7 +109,8 @@ namespace xo { ratio::ratio(power_.num(), power_.den())); } - /** @brief this unit represents native dimension taken to this power **/ + public: /* need public members so that a basis_unit instance can be a non-type template parameter (a structural type) */ + /** @brief this unit represents basis dimension (bu) taken to this power **/ power_ratio_type power_; }; diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 7a9fab45..0fcfa866 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -4,6 +4,7 @@ set(SELF_EXE utest.unit) set(SELF_SRCS unit_utest_main.cpp #mpl_unit.test.cpp Quantity.test.cpp + bpu.test.cpp bu.test.cpp unit.test.cpp #quantity.test.cpp ) diff --git a/utest/bpu.test.cpp b/utest/bpu.test.cpp new file mode 100644 index 00000000..0c4265b0 --- /dev/null +++ b/utest/bpu.test.cpp @@ -0,0 +1,36 @@ +/* @file bpu.test.cpp */ + +#include "xo/unit/bpu.hpp" +//#include "xo/indentlog/scope.hpp" +#include + +namespace xo { + namespace qty { + using bpu64_type = bpu; + + /* compile-time test: + * verify we can use a bpu as a non-type template parameter. + * Will need this for quantity> + */ + template + constexpr bpu_abbrev_type bpu_mpl_abbrev = bpu.abbrev(); + + TEST_CASE("bpu", "[bpu]") { + //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(bpu_mpl_abbrev == bpu64_type::unit_power(bu::gram).abbrev()); + REQUIRE(bpu_mpl_abbrev == bpu64_type::unit_power(bu::gram).abbrev()); + } /*TEST_CASE(bpu)*/ + } /*namespace qty*/ +} /*namespace xo*/ + +/* end bpu.test.cpp */