diff --git a/include/xo/unit/detail/promoter.hpp b/include/xo/unit/detail/promoter.hpp index 1dc34c78..d3b4b4ad 100644 --- a/include/xo/unit/detail/promoter.hpp +++ b/include/xo/unit/detail/promoter.hpp @@ -5,7 +5,7 @@ #pragma once -#include "unit.hpp" +#include "mpl/unit.hpp" namespace xo { namespace unit { diff --git a/include/xo/unit/dimension_concept.hpp b/include/xo/unit/mpl/dimension_concept.hpp similarity index 100% rename from include/xo/unit/dimension_concept.hpp rename to include/xo/unit/mpl/dimension_concept.hpp diff --git a/include/xo/unit/dimension_impl.hpp b/include/xo/unit/mpl/dimension_impl.hpp similarity index 100% rename from include/xo/unit/dimension_impl.hpp rename to include/xo/unit/mpl/dimension_impl.hpp diff --git a/include/xo/unit/native_bpu.hpp b/include/xo/unit/mpl/native_bpu.hpp similarity index 100% rename from include/xo/unit/native_bpu.hpp rename to include/xo/unit/mpl/native_bpu.hpp diff --git a/include/xo/unit/native_bpu_concept.hpp b/include/xo/unit/mpl/native_bpu_concept.hpp similarity index 100% rename from include/xo/unit/native_bpu_concept.hpp rename to include/xo/unit/mpl/native_bpu_concept.hpp diff --git a/include/xo/unit/quantity_concept.hpp b/include/xo/unit/mpl/quantity_concept.hpp similarity index 100% rename from include/xo/unit/quantity_concept.hpp rename to include/xo/unit/mpl/quantity_concept.hpp diff --git a/include/xo/unit/unit.hpp b/include/xo/unit/mpl/unit.hpp similarity index 100% rename from include/xo/unit/unit.hpp rename to include/xo/unit/mpl/unit.hpp diff --git a/include/xo/unit/unit_concept.hpp b/include/xo/unit/mpl/unit_concept.hpp similarity index 100% rename from include/xo/unit/unit_concept.hpp rename to include/xo/unit/mpl/unit_concept.hpp diff --git a/include/xo/unit/quantity2_concept.hpp b/include/xo/unit/quantity2_concept.hpp index 45fe8748..b401be7b 100644 --- a/include/xo/unit/quantity2_concept.hpp +++ b/include/xo/unit/quantity2_concept.hpp @@ -2,7 +2,7 @@ #pragma once -#include "unit_concept.hpp" +//#include "unit_concept.hpp" #include "numeric_concept.hpp" namespace xo { diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index d88e7450..69c6418d 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -3,6 +3,7 @@ set(SELF_EXECUTABLE_NAME utest.unit) set(SELF_SOURCE_FILES unit_utest_main.cpp + mpl_unit.test.cpp unit.test.cpp quantity.test.cpp) add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) diff --git a/utest/mpl_unit.test.cpp b/utest/mpl_unit.test.cpp new file mode 100644 index 00000000..680fad65 --- /dev/null +++ b/utest/mpl_unit.test.cpp @@ -0,0 +1,380 @@ +/* @file mpl_unit.test.cpp */ + +#include "native_bpu2.hpp" +#include "xo/unit/mpl/quantity.hpp" +//#include "xo/unit/unit.hpp" +//#include "xo/unit/Quantity2_iostream.hpp" +//#include "xo/unit/Quantity2.hpp" +//#include "xo/unit/scaled_unit_iostream.hpp" +//#include "xo/unit/natural_unit.hpp" +//#include "xo/unit/natural_unit_iostream.hpp" +//#include "xo/unit/bpu_store.hpp" +//#include "xo/unit/native_bpu2.hpp" +//#include "xo/unit/native_bpu2_iostream.hpp" +//#include "xo/unit/basis_unit2.hpp" +//#include "xo/unit/dim_util2.hpp" +#include "xo/reflect/Reflect.hpp" +//#include "xo/cxxutil/demangle.hpp" +#include "xo/indentlog/scope.hpp" +#include "xo/indentlog/print/tag.hpp" +#include + +namespace xo { + namespace ut { + /* compile-time tests */ + + using xo::reflect::Reflect; + + //namespace su2 = xo::unit::su2; + //using xo::unit::Quantity2; + using xo::unit::dim; + //using xo::unit::basis_unit2_abbrev_type; + //using xo::unit::native_unit2; + //using xo::unit::native_unit2_v; + //using xo::unit::scalefactor_ratio_type; + //using xo::unit::units::scaled_native_unit2_abbrev; + //using xo::unit::units::scaled_native_unit2_abbrev_v; + //using xo::unit::basis_unit2; + //using xo::unit::abbrev::basis_unit2_abbrev;; + //using xo::unit::bpu2_abbrev_type; + //using xo::unit::abbrev::bpu2_abbrev; + //using xo::unit::basis_unit2_store; + using xo::unit::power_ratio_type; + //using xo::unit::abbrev::flatstring_from_exponent; + //using xo::unit::bpu2; + //using xo::unit::detail::bpu2_rescale; + //using xo::unit::detail::bpu2_product; + //using xo::unit::natural_unit; + //using xo::unit::bpu_array_maker; + //using xo::unit::detail::nu_product; + //using xo::unit::unit_qty; + + using xo::unit::native_unit_abbrev_v; + using xo::unit::units::scaled_native_unit_abbrev_v; + //using xo::unit::native_dim_abbrev; + using xo::unit::stringliteral_compare; + using xo::unit::literal_size_v; + using xo::unit::stringliteral_from_digit; + using xo::unit::stringliteral_from_int_v; + using xo::unit::stringliteral; +#ifndef __clang__ + using xo::unit::stringliteral_concat; + using xo::unit::stringliteral_from_ratio; + using xo::unit::bpu_assemble_abbrev_helper; + using xo::unit::bpu_assemble_abbrev; +#endif + using xo::unit::bpu_node; + using xo::unit::wrap_unit; + using xo::unit::unit_abbrev_v; + //using xo::unit::dim_abbrev_v; + using xo::unit::di_cartesian_product; + using xo::unit::di_cartesian_product1; + using xo::unit::unit_cartesian_product_t; + using xo::unit::bpu_cartesian_product; + using xo::unit::bpu_cartesian_product_helper; + using xo::unit::unit_invert_t; + using xo::unit::units::gram; + using xo::unit::units::second; + using xo::print::ccs; + + template + int unused() + { + return 1; + } + + template + constexpr bool unused_same(typename std::enable_if_t::value, bool> result = true) + { + return result; + } + + TEST_CASE("native_unit_abbrev", "[native_dim_abbrev]") { + constexpr bool c_debug_flag = true; + + // 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.native_dim_abbrev")); + //log && log("(A)", xtag("foo", foo)); + + /* NOTE: the .value_ expression below will fail to compile if missing specialization for + * native_dim_abbrev on native_dim_id::foo; that's the point :) + */ + + REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "g") == 0); + REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "s") == 0); + REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "ccy") == 0); + REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "px") == 0); + +#ifdef OBSOLETE + REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); + REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); + REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); + REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); +#endif + + static_assert(stringliteral_compare(stringliteral_from_digit(0), stringliteral("0")) == 0); + static_assert(stringliteral_compare(stringliteral_from_digit(1), stringliteral("1")) == 0); + static_assert(stringliteral_compare(stringliteral_from_digit(9), stringliteral("9")) == 0); + + static_assert(literal_size_v<0> == 1); + static_assert(literal_size_v<10> == 2); + static_assert(literal_size_v<99> == 2); + static_assert(literal_size_v<100> == 3); + static_assert(literal_size_v<999> == 3); + + static_assert(stringliteral_compare(stringliteral_from_int_v<0>(), stringliteral("0")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<9>(), stringliteral("9")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<1, 1, false>(), stringliteral("1")) == 0); + + + static_assert(stringliteral_compare(stringliteral_from_int_v<9, 1, false>(), stringliteral("9")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<9>(), stringliteral("9")) == 0); + + /* NOTE: clang16 complains starting here; gcc is fine */ + +#ifndef __clang__ + if constexpr (stringliteral_concat("a", "b").size() == 3) { + REQUIRE(true); + } else { + REQUIRE(false); + } + + static_assert(stringliteral_compare(stringliteral_concat("hello", " ", "world"), + stringliteral("hello world")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<10, 2, false>(), stringliteral("10")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<10>(), stringliteral("10")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<99, 2, false>(), stringliteral("99")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<99>(), stringliteral("99")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<100, 3, false>(), stringliteral("100")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<100>(), stringliteral("100")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<999, 3, false>(), stringliteral("999")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<999>(), stringliteral("999")) == 0); + + //std::cerr << "test=" << stringliteral_from_int_v<-1, 2, true>().value_ << std::endl; + + static_assert(stringliteral_compare(stringliteral_from_int_v<-1, 2, true>(), stringliteral("-1")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-1>(), stringliteral("-1")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<-9, 2, true>(), stringliteral("-9")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-9>(), stringliteral("-9")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<-10, 3, true>(), stringliteral("-10")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-10>(), stringliteral("-10")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<-99, 3, true>(), stringliteral("-99")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-99>(), stringliteral("-99")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<-100, 4, true>(), stringliteral("-100")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-100>(), stringliteral("-100")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_int_v<-999, 4, true>(), stringliteral("-999")) == 0); + static_assert(stringliteral_compare(stringliteral_from_int_v<-999>(), stringliteral("-999")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(2/3)")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(2/3)")) == 0); + + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-1")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-2")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-2")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(3/2)")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(3/2)")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(1/2)")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(1/2)")) == 0); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(3/2)")) == 0); + + //log && log(xtag("ratio<2>", stringliteral_from_ratio>().c_str())); + static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("2")) == 0); + + static_assert(stringliteral_compare(bpu_assemble_abbrev_helper, std::ratio<1>>(), stringliteral("g")) == 0); + //log && log(xtag("s^(-1/2)", bpu_assemble_abbrev_helper, std::ratio<-1,2>>().c_str())); + static_assert(stringliteral_compare(bpu_assemble_abbrev_helper, std::ratio<-1,2>>(), stringliteral("s^-(1/2)")) == 0); + //stringliteral_compare(stringliteral_from_ratio>(), stringliteral("^2")) == 0); +#endif + + //static_assert(stringliteral_compare(stringliteral_from_int_v<10>(), obs::stringliteral("10")) == 0); + + //REQUIRE(strcmp(obs::stringliteral_from_digit(1).value_, "1") == 0); + //REQUIRE(strcmp(obs::ratio2str>().value_, "") == 0); + + } /*TEST_CASE(native_dim_abbrev)*/ + + TEST_CASE("dimension", "[dimension]") { + constexpr bool c_debug_flag = false; + + scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.dimension")); + //log && log("(A)", xtag("foo", foo)); + + using t1 = unit::bpu>; + + static_assert(t1::c_native_dim == unit::dim::currency); + static_assert(t1::power_type::num == 1); + static_assert(t1::power_type::den == 1); + + using t2 = unit::bpu, std::ratio<-1,2>>; + + static_assert(t2::c_native_dim == unit::dim::time); + static_assert(t2::power_type::num == -1); + static_assert(t2::power_type::den == 2); + + using dim1 = wrap_unit, bpu_node>; + using d1 = dim1::dim_type; /* ccy */ + REQUIRE(unused_same()); + REQUIRE(unused_same::power_unit_type, t1>()); +#ifdef NOT_USING + static_assert(unit::lo_basis_elt_of::c_lo_basis == t1::c_basis); +#endif + + static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); + static_assert(unit::native_lo_bwp_of::bwp_type::c_basis == unit::dim::currency); + + + using dim2 = wrap_unit, bpu_node>; + using d2 = dim2::dim_type; /* t^(-1/2) */ + REQUIRE(unused_same()); + REQUIRE(unused_same::power_unit_type, t2>()); + static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); + static_assert(unit::native_lo_bwp_of::bwp_type::c_basis == unit::dim::time); + + using dim3 = wrap_unit, bpu_node>>; + using d3 = dim3::dim_type; /* ccy.t^(-1/2) */ + REQUIRE(unused_same::power_unit_type, t1>()); + + { + using type = unit::lookup_bpu::power_unit_type; + //std::cerr << "unit::power_unit_of::power_unit_type" << xtag("type", reflect::type_name()) << std::endl; + + REQUIRE(unused_same()); + } + +#ifdef NOT_USING + static_assert(unit::lo_basis_elt_of::c_lo_basis == t2::c_basis); +#endif + + /* lowest is in pos 1, beacuse t2=time before t1=currency */ + static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 1); + + static_assert(unused_same::dim_type, d2>()); + //using type = unit::without_elt::dim_type; + //std::cerr << "unit::without_elt::dim_type" << xtag("type", reflect::type_name()) << std::endl; + static_assert(unused_same::dim_type, d1>()); + + + using d3b = wrap_unit, + bpu_node>>::dim_type; /* t^(-1/2).ccy */ + //using d3b = unit::dimension_impl>; /* t^(-1/2).ccy */ + REQUIRE(unused_same::power_unit_type, t2>()); + REQUIRE(unused_same::power_unit_type, t1>()); + + /* lowest is in pos 0 */ + static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); + + static_assert(unused_same::dim_type, d1>()); + static_assert(unused_same::dim_type, d2>()); + + static_assert(unused_same, unit::canonical_t>()); + + log && log(xtag("d1.abbrev", unit_abbrev_v.c_str())); + log && log(xtag("d2.abbrev", unit_abbrev_v.c_str())); + log && log(xtag("d3.abbrev", unit_abbrev_v.c_str())); + } + + TEST_CASE("dimension2", "[dimension2]") { + 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.dimension2")); + //log && log("(A)", xtag("foo", foo)); + + using di = di_cartesian_product; + + log && log(xtag("di", Reflect::require()->canonical_name())); + log && log(xtag("di::outer_scalefactor_type", Reflect::require()->canonical_name())); + log && log(xtag("di::bpu_list_type", Reflect::require()->canonical_name())); + + using u1 = unit_cartesian_product_t; + + log && log(xtag("u1", Reflect::require()->canonical_name())); + + log && log(xtag("u1", ccs(unit_abbrev_v.value_))); + } /*TEST_CASE(dimension2)*/ + + TEST_CASE("dimension3", "[dimension3]") { + 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.dimension3")); + //log && log("(A)", xtag("foo", foo)); + + using u1 = unit_invert_t; + + log && log(xtag("second^-1", Reflect::require()->canonical_name())); + log && log(xtag("u1", unit_abbrev_v.c_str())); + + REQUIRE(strcmp(unit_abbrev_v.c_str(), "s^-1") == 0); + + using u2 = second; + + log && log(xtag("second", Reflect::require()->canonical_name())); + log && log(xtag("u2", unit_abbrev_v.c_str())); + + using u1u2 = unit_cartesian_product_t; + + log && log(xtag("u1u2", Reflect::require()->canonical_name())); + +#ifdef NOT_USING + using di1 = d1::dim_type; + using di2 = d2::dim_type; + using di1di2 = di_cartesian_product::type; + + log && log(xtag("di1di2", Reflect::require()->canonical_name())); +#endif + + using f1 = u1::dim_type::front_type; + using r1 = u1::dim_type::rest_type; + using tmp = di_cartesian_product1; + + log && log(xtag("f1", Reflect::require()->canonical_name())); + log && log(xtag("r1", Reflect::require()->canonical_name())); + log && log(xtag("(f1.r1).outer_scalefactor_type", Reflect::require()->canonical_name())); + log && log(xtag("(f1.r1).bpu_list_type", Reflect::require()->canonical_name())); + + using tmp2 = bpu_cartesian_product; + + log && log(xtag("(f1.u2).outer_scalefactor_type", Reflect::require()->canonical_name())); + log && log(xtag("(f1.u2).bpu_list_type", Reflect::require()->canonical_name())); + + using f2 = u2::dim_type::front_type; + log && log(xtag("f2", Reflect::require()->canonical_name())); + + using tmp3 = bpu_cartesian_product_helper; + log && log(xtag("(f1.f2).outer_scalefactor_type", Reflect::require()->canonical_name())); + log && log(xtag("(f1.f2).bpu_list_type", Reflect::require()->canonical_name())); + } /*TEST_CASE(dimension3)*/ + + + } /*namespace ut*/ + +} /*namespace xo*/ + + +/* end dimension.test.cpp */ diff --git a/utest/quantity.test.cpp b/utest/quantity.test.cpp index 66d82a23..aefab2ae 100644 --- a/utest/quantity.test.cpp +++ b/utest/quantity.test.cpp @@ -769,7 +769,7 @@ namespace xo { } /*TEST_CASE(rescale)*/ TEST_CASE("rescale2", "[quantity]") { - constexpr bool c_debug_flag = true; + constexpr bool c_debug_flag = false; // can get bits from /dev/random by uncommenting the 2nd line below //uint64_t seed = xxx; @@ -789,7 +789,7 @@ namespace xo { } /*TEST_CASE(rescale2)*/ TEST_CASE("compare1", "[quantity]") { - constexpr bool c_debug_flag = true; + constexpr bool c_debug_flag = false; // can get bits from /dev/random by uncommenting the 2nd line below //uint64_t seed = xxx; @@ -823,7 +823,7 @@ namespace xo { } /*TEST_CASE(compare1)*/ TEST_CASE("compare2", "[quantity]") { - constexpr bool c_debug_flag = true; + constexpr bool c_debug_flag = false; // can get bits from /dev/random by uncommenting the 2nd line below //uint64_t seed = xxx; diff --git a/utest/unit.test.cpp b/utest/unit.test.cpp index 9e911699..451fadcc 100644 --- a/utest/unit.test.cpp +++ b/utest/unit.test.cpp @@ -1,4 +1,4 @@ -/* @file dimension.test.cpp */ +/* @file unit.test.cpp */ #include "xo/unit/unit.hpp" #include "xo/unit/Quantity2_iostream.hpp" @@ -48,32 +48,32 @@ namespace xo { using xo::unit::detail::nu_product; using xo::unit::unit_qty; - using xo::unit::native_unit_abbrev_v; - using xo::unit::units::scaled_native_unit_abbrev_v; + //using xo::unit::native_unit_abbrev_v; + //using xo::unit::units::scaled_native_unit_abbrev_v; //using xo::unit::native_dim_abbrev; - using xo::unit::stringliteral_compare; - using xo::unit::literal_size_v; - using xo::unit::stringliteral_from_digit; - using xo::unit::stringliteral_from_int_v; - using xo::unit::stringliteral; + //using xo::unit::stringliteral_compare; + //using xo::unit::literal_size_v; + //using xo::unit::stringliteral_from_digit; + //using xo::unit::stringliteral_from_int_v; + //using xo::unit::stringliteral; #ifndef __clang__ - using xo::unit::stringliteral_concat; - using xo::unit::stringliteral_from_ratio; - using xo::unit::bpu_assemble_abbrev_helper; - using xo::unit::bpu_assemble_abbrev; + //using xo::unit::stringliteral_concat; + //using xo::unit::stringliteral_from_ratio; + //using xo::unit::bpu_assemble_abbrev_helper; + //using xo::unit::bpu_assemble_abbrev; #endif - using xo::unit::bpu_node; - using xo::unit::wrap_unit; - using xo::unit::unit_abbrev_v; + //using xo::unit::bpu_node; + //using xo::unit::wrap_unit; + //using xo::unit::unit_abbrev_v; //using xo::unit::dim_abbrev_v; - using xo::unit::di_cartesian_product; - using xo::unit::di_cartesian_product1; - using xo::unit::unit_cartesian_product_t; - using xo::unit::bpu_cartesian_product; - using xo::unit::bpu_cartesian_product_helper; - using xo::unit::unit_invert_t; - using xo::unit::units::gram; - using xo::unit::units::second; + //using xo::unit::di_cartesian_product; + //using xo::unit::di_cartesian_product1; + //using xo::unit::unit_cartesian_product_t; + //using xo::unit::bpu_cartesian_product; + //using xo::unit::bpu_cartesian_product_helper; + //using xo::unit::unit_invert_t; + //using xo::unit::units::gram; + //using xo::unit::units::second; using xo::print::ccs; template @@ -359,125 +359,6 @@ namespace xo { } /*TEST_CASE(bpu2_abbrev)*/ - TEST_CASE("native_unit_abbrev", "[native_dim_abbrev]") { - constexpr bool c_debug_flag = true; - - // 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.native_dim_abbrev")); - //log && log("(A)", xtag("foo", foo)); - - /* NOTE: the .value_ expression below will fail to compile if missing specialization for - * native_dim_abbrev on native_dim_id::foo; that's the point :) - */ - - REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "g") == 0); - REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "s") == 0); - REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "ccy") == 0); - REQUIRE(strcmp(scaled_native_unit_abbrev_v>.value_, "px") == 0); - -#ifdef OBSOLETE - REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); - REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); - REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); - REQUIRE(strcmp(native_dim_abbrev().value_, "") != 0); -#endif - - static_assert(stringliteral_compare(stringliteral_from_digit(0), stringliteral("0")) == 0); - static_assert(stringliteral_compare(stringliteral_from_digit(1), stringliteral("1")) == 0); - static_assert(stringliteral_compare(stringliteral_from_digit(9), stringliteral("9")) == 0); - - static_assert(literal_size_v<0> == 1); - static_assert(literal_size_v<10> == 2); - static_assert(literal_size_v<99> == 2); - static_assert(literal_size_v<100> == 3); - static_assert(literal_size_v<999> == 3); - - static_assert(stringliteral_compare(stringliteral_from_int_v<0>(), stringliteral("0")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<9>(), stringliteral("9")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<1, 1, false>(), stringliteral("1")) == 0); - - - static_assert(stringliteral_compare(stringliteral_from_int_v<9, 1, false>(), stringliteral("9")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<9>(), stringliteral("9")) == 0); - - /* NOTE: clang16 complains starting here; gcc is fine */ - -#ifndef __clang__ - if constexpr (stringliteral_concat("a", "b").size() == 3) { - REQUIRE(true); - } else { - REQUIRE(false); - } - - static_assert(stringliteral_compare(stringliteral_concat("hello", " ", "world"), - stringliteral("hello world")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<10, 2, false>(), stringliteral("10")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<10>(), stringliteral("10")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<99, 2, false>(), stringliteral("99")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<99>(), stringliteral("99")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<100, 3, false>(), stringliteral("100")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<100>(), stringliteral("100")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<999, 3, false>(), stringliteral("999")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<999>(), stringliteral("999")) == 0); - - //std::cerr << "test=" << stringliteral_from_int_v<-1, 2, true>().value_ << std::endl; - - static_assert(stringliteral_compare(stringliteral_from_int_v<-1, 2, true>(), stringliteral("-1")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-1>(), stringliteral("-1")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<-9, 2, true>(), stringliteral("-9")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-9>(), stringliteral("-9")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<-10, 3, true>(), stringliteral("-10")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-10>(), stringliteral("-10")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<-99, 3, true>(), stringliteral("-99")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-99>(), stringliteral("-99")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<-100, 4, true>(), stringliteral("-100")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-100>(), stringliteral("-100")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_int_v<-999, 4, true>(), stringliteral("-999")) == 0); - static_assert(stringliteral_compare(stringliteral_from_int_v<-999>(), stringliteral("-999")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(2/3)")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(2/3)")) == 0); - - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-1")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-2")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-2")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(3/2)")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(3/2)")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("-(1/2)")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(1/2)")) == 0); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("(3/2)")) == 0); - - //log && log(xtag("ratio<2>", stringliteral_from_ratio>().c_str())); - static_assert(stringliteral_compare(stringliteral_from_ratio>(), stringliteral("2")) == 0); - - static_assert(stringliteral_compare(bpu_assemble_abbrev_helper, std::ratio<1>>(), stringliteral("g")) == 0); - //log && log(xtag("s^(-1/2)", bpu_assemble_abbrev_helper, std::ratio<-1,2>>().c_str())); - static_assert(stringliteral_compare(bpu_assemble_abbrev_helper, std::ratio<-1,2>>(), stringliteral("s^-(1/2)")) == 0); - //stringliteral_compare(stringliteral_from_ratio>(), stringliteral("^2")) == 0); -#endif - - //static_assert(stringliteral_compare(stringliteral_from_int_v<10>(), obs::stringliteral("10")) == 0); - - //REQUIRE(strcmp(obs::stringliteral_from_digit(1).value_, "1") == 0); - //REQUIRE(strcmp(obs::ratio2str>().value_, "") == 0); - - } /*TEST_CASE(native_dim_abbrev)*/ - TEST_CASE("bpu_rescale", "[bpu_rescale]") { constexpr bool c_debug_flag = true; @@ -1002,173 +883,7 @@ namespace xo { //REQUIRE(ng2.scale() == 1); } /*TEST_CASE(Quantity3)*/ - - TEST_CASE("dimension", "[dimension]") { - constexpr bool c_debug_flag = false; - - scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.dimension")); - //log && log("(A)", xtag("foo", foo)); - - using t1 = unit::bpu>; - - static_assert(t1::c_native_dim == unit::dim::currency); - static_assert(t1::power_type::num == 1); - static_assert(t1::power_type::den == 1); - - using t2 = unit::bpu, std::ratio<-1,2>>; - - static_assert(t2::c_native_dim == unit::dim::time); - static_assert(t2::power_type::num == -1); - static_assert(t2::power_type::den == 2); - - using dim1 = wrap_unit, bpu_node>; - using d1 = dim1::dim_type; /* ccy */ - REQUIRE(unused_same()); - REQUIRE(unused_same::power_unit_type, t1>()); -#ifdef NOT_USING - static_assert(unit::lo_basis_elt_of::c_lo_basis == t1::c_basis); -#endif - - static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); - static_assert(unit::native_lo_bwp_of::bwp_type::c_basis == unit::dim::currency); - - - using dim2 = wrap_unit, bpu_node>; - using d2 = dim2::dim_type; /* t^(-1/2) */ - REQUIRE(unused_same()); - REQUIRE(unused_same::power_unit_type, t2>()); - static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); - static_assert(unit::native_lo_bwp_of::bwp_type::c_basis == unit::dim::time); - - using dim3 = wrap_unit, bpu_node>>; - using d3 = dim3::dim_type; /* ccy.t^(-1/2) */ - REQUIRE(unused_same::power_unit_type, t1>()); - - { - using type = unit::lookup_bpu::power_unit_type; - //std::cerr << "unit::power_unit_of::power_unit_type" << xtag("type", reflect::type_name()) << std::endl; - - REQUIRE(unused_same()); - } - -#ifdef NOT_USING - static_assert(unit::lo_basis_elt_of::c_lo_basis == t2::c_basis); -#endif - - /* lowest is in pos 1, beacuse t2=time before t1=currency */ - static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 1); - - static_assert(unused_same::dim_type, d2>()); - //using type = unit::without_elt::dim_type; - //std::cerr << "unit::without_elt::dim_type" << xtag("type", reflect::type_name()) << std::endl; - static_assert(unused_same::dim_type, d1>()); - - - using d3b = wrap_unit, - bpu_node>>::dim_type; /* t^(-1/2).ccy */ - //using d3b = unit::dimension_impl>; /* t^(-1/2).ccy */ - REQUIRE(unused_same::power_unit_type, t2>()); - REQUIRE(unused_same::power_unit_type, t1>()); - - /* lowest is in pos 0 */ - static_assert(unit::native_lo_bwp_of::bwp_type::c_index == 0); - - static_assert(unused_same::dim_type, d1>()); - static_assert(unused_same::dim_type, d2>()); - - static_assert(unused_same, unit::canonical_t>()); - - log && log(xtag("d1.abbrev", unit_abbrev_v.c_str())); - log && log(xtag("d2.abbrev", unit_abbrev_v.c_str())); - log && log(xtag("d3.abbrev", unit_abbrev_v.c_str())); - } - - TEST_CASE("dimension2", "[dimension2]") { - 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.dimension2")); - //log && log("(A)", xtag("foo", foo)); - - using di = di_cartesian_product; - - log && log(xtag("di", Reflect::require()->canonical_name())); - log && log(xtag("di::outer_scalefactor_type", Reflect::require()->canonical_name())); - log && log(xtag("di::bpu_list_type", Reflect::require()->canonical_name())); - - using u1 = unit_cartesian_product_t; - - log && log(xtag("u1", Reflect::require()->canonical_name())); - - log && log(xtag("u1", ccs(unit_abbrev_v.value_))); - } /*TEST_CASE(dimension2)*/ - - TEST_CASE("dimension3", "[dimension3]") { - 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.dimension3")); - //log && log("(A)", xtag("foo", foo)); - - using u1 = unit_invert_t; - - log && log(xtag("second^-1", Reflect::require()->canonical_name())); - log && log(xtag("u1", unit_abbrev_v.c_str())); - - REQUIRE(strcmp(unit_abbrev_v.c_str(), "s^-1") == 0); - - using u2 = second; - - log && log(xtag("second", Reflect::require()->canonical_name())); - log && log(xtag("u2", unit_abbrev_v.c_str())); - - using u1u2 = unit_cartesian_product_t; - - log && log(xtag("u1u2", Reflect::require()->canonical_name())); - -#ifdef NOT_USING - using di1 = d1::dim_type; - using di2 = d2::dim_type; - using di1di2 = di_cartesian_product::type; - - log && log(xtag("di1di2", Reflect::require()->canonical_name())); -#endif - - using f1 = u1::dim_type::front_type; - using r1 = u1::dim_type::rest_type; - using tmp = di_cartesian_product1; - - log && log(xtag("f1", Reflect::require()->canonical_name())); - log && log(xtag("r1", Reflect::require()->canonical_name())); - log && log(xtag("(f1.r1).outer_scalefactor_type", Reflect::require()->canonical_name())); - log && log(xtag("(f1.r1).bpu_list_type", Reflect::require()->canonical_name())); - - using tmp2 = bpu_cartesian_product; - - log && log(xtag("(f1.u2).outer_scalefactor_type", Reflect::require()->canonical_name())); - log && log(xtag("(f1.u2).bpu_list_type", Reflect::require()->canonical_name())); - - using f2 = u2::dim_type::front_type; - log && log(xtag("f2", Reflect::require()->canonical_name())); - - using tmp3 = bpu_cartesian_product_helper; - log && log(xtag("(f1.f2).outer_scalefactor_type", Reflect::require()->canonical_name())); - log && log(xtag("(f1.f2).bpu_list_type", Reflect::require()->canonical_name())); - } /*TEST_CASE(dimension3)*/ - - } /*namespace ut*/ - } /*namespace xo*/