xo-unit: utest: + bpu test to verify bpu is structurual type
This commit is contained in:
parent
67802ed5a3
commit
9350f017b1
4 changed files with 40 additions and 1 deletions
|
|
@ -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 **/
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ namespace xo {
|
|||
ratio::ratio<Int2>(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_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
36
utest/bpu.test.cpp
Normal file
36
utest/bpu.test.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* @file bpu.test.cpp */
|
||||
|
||||
#include "xo/unit/bpu.hpp"
|
||||
//#include "xo/indentlog/scope.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace qty {
|
||||
using bpu64_type = bpu<std::int64_t>;
|
||||
|
||||
/* compile-time test:
|
||||
* verify we can use a bpu as a non-type template parameter.
|
||||
* Will need this for quantity<Repr, Int, natural_unit<Int>>
|
||||
*/
|
||||
template <bpu64_type bpu>
|
||||
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<xoshio256ss> 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)> == bpu64_type::unit_power(bu::gram).abbrev());
|
||||
REQUIRE(bpu_mpl_abbrev<bpu64_type::unit_power(bu::gram)> == bpu64_type::unit_power(bu::gram).abbrev());
|
||||
} /*TEST_CASE(bpu)*/
|
||||
} /*namespace qty*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end bpu.test.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue