diff --git a/docs/bu-store-class.rst b/docs/bu-store-class.rst index 48614ebd..c7f13e2d 100644 --- a/docs/bu-store-class.rst +++ b/docs/bu-store-class.rst @@ -7,7 +7,7 @@ Basis Unit Store #include - namespace bu = xo::qty::bu; + namespace bu = xo::qty::detail::bu; A :code:`xo::qty::bu_store` is a small, constexpr, key-value store associating abbreviations with basis units. To satisfy the constexpr requirement, @@ -54,7 +54,28 @@ This class supports the implementation of ``natural_unit::abbrev()``. Application code is not expected to interact directly with it. -.. doxygenclass:: xo::qty::bu_store +.. doxygenclass:: xo::qty::detail::bu_store + +For example, this would be possible: + +.. code-block:: cpp + + #include + + namespace bu = using xo::qty::detail::bu; + using xo::qty::detail::bu_store; + using xo::qty::dim; + using xo::flatstring; + + constexpr bu_store store; + static_assert(store.bu_abbrev(bu::minute) == flatstring("min")); + static_assert(store.bu_abbrev(bu::microgram) == flatstring("ug")); + + +.. doxygenclass:: xo::qty::detail::bu_dim_store +.. doxygengroup:: bu-dim-store-type-traits +.. doxygengroup:: bu-dim-store-instance-vars + Constants --------- diff --git a/include/xo/unit/bu_store.hpp b/include/xo/unit/bu_store.hpp index 11dd5d66..3bc816f0 100644 --- a/include/xo/unit/bu_store.hpp +++ b/include/xo/unit/bu_store.hpp @@ -14,201 +14,211 @@ namespace xo { using power_ratio_type = xo::ratio::ratio; - struct bu_dim_store { - /** max number of basis-units per dimension **/ - static constexpr std::size_t max_bu_per_dim = 25; - - using entry_type = std::pair; - - /* e.g. - * [(1/1000000000, "nm"), (1/1000000, "um"), (1/1000, "mm"), (1/1, "m"), (1000/1, "km")] - */ - using native_scale_v = std::array; - - public: - constexpr bu_dim_store() = default; - - constexpr bool empty() const { return n_bu_ == 0; } - constexpr std::size_t size() const { return n_bu_; } - - constexpr const entry_type & operator[](std::size_t i) const { return bu_abbrev_v_[i]; } - - /** @brief get least-upper-bound index position in bu_abbrev_v[] - * - * return value in [0, n] where n = .size() + namespace detail { + /** @class bu_dim_store + * @brief store basis-unit abbreviations for a particular dimension **/ - constexpr std::size_t abbrev_lub_ix(const scalefactor_ratio_type & scalefactor) const - { - if (n_bu_ == 0) - return 0; + struct bu_dim_store { + /** max number of basis-units per dimension **/ + static constexpr std::size_t max_bu_per_dim = 25; - std::size_t lo = 0; - std::size_t hi = n_bu_-1; + /** @defgroup bu-dim-store-type-traits bu-dim-store type traits **/ + ///@{ + using entry_type = std::pair; - if (scalefactor <= bu_abbrev_v_[lo].first) - return 0; + /* e.g. + * [(1/1000000000, "nm"), (1/1000000, "um"), (1/1000, "mm"), (1/1, "m"), (1000/1, "km")] + */ + using native_scale_v = std::array; + ///@} - auto cmp = (scalefactor <=> bu_abbrev_v_[hi].first); + public: + constexpr bu_dim_store() = default; - if (cmp > 0) - return n_bu_; + constexpr bool empty() const { return n_bu_ == 0; } + constexpr std::size_t size() const { return n_bu_; } + + constexpr const entry_type & operator[](std::size_t i) const { return bu_abbrev_v_[i]; } + + /** @brief get least-upper-bound index position in bu_abbrev_v[] + * + * return value in [0, n] where n = .size() + **/ + constexpr std::size_t abbrev_lub_ix(const scalefactor_ratio_type & scalefactor) const + { + if (n_bu_ == 0) + return 0; + + std::size_t lo = 0; + std::size_t hi = n_bu_-1; + + if (scalefactor <= bu_abbrev_v_[lo].first) + return 0; + + auto cmp = (scalefactor <=> bu_abbrev_v_[hi].first); + + if (cmp > 0) + return n_bu_; + + if (cmp == 0) + return hi; + + while (hi-lo > 1) { + /* inv: + * bu_abbrev_v[lo].first < scalefactor <= bu_abbrev_v[hi].first + */ + + std::size_t mid = lo + (hi - lo)/2; + + if (scalefactor > bu_abbrev_v_[mid].first) + lo = mid; + else + hi = mid; + } - if (cmp == 0) return hi; - - while (hi-lo > 1) { - /* inv: - * bu_abbrev_v[lo].first < scalefactor <= bu_abbrev_v[hi].first - */ - - std::size_t mid = lo + (hi - lo)/2; - - if (scalefactor > bu_abbrev_v_[mid].first) - lo = mid; - else - hi = mid; } - return hi; - } + constexpr void insert_aux(std::size_t ix, + const entry_type & entry) + { - constexpr void insert_aux(std::size_t ix, - const entry_type & entry) - { + if (n_bu_ >= max_bu_per_dim) + return; - if (n_bu_ >= max_bu_per_dim) - return; + ++n_bu_; - ++n_bu_; + for (std::size_t dest_ix = n_bu_; dest_ix > ix; --dest_ix) + bu_abbrev_v_[dest_ix] = bu_abbrev_v_[dest_ix - 1]; - for (std::size_t dest_ix = n_bu_; dest_ix > ix; --dest_ix) - bu_abbrev_v_[dest_ix] = bu_abbrev_v_[dest_ix - 1]; + bu_abbrev_v_[ix] = entry; + } - bu_abbrev_v_[ix] = entry; - } + /** @brief establish abbreviation @p abbrev for basis unit @p bu + **/ + constexpr void bu_establish_abbrev(const scalefactor_ratio_type & scalefactor, + const bu_abbrev_type & abbrev) + { - /** @brief establish abbreviation @p abbrev for basis unit @p bu + std::int32_t i_abbrev = this->abbrev_lub_ix(scalefactor); + + auto entry = std::make_pair(scalefactor, abbrev); + + if ((i_abbrev < bu_abbrev_v_.size()) + && (bu_abbrev_v_[i_abbrev].first == scalefactor)) + { + bu_abbrev_v_[i_abbrev] = entry; + } else { + this->insert_aux(i_abbrev, entry); + } + } + + public: + /** @defgroup bu-dim-store-instance-vars bu-dim-store instance vars **/ + ///@{ + std::size_t n_bu_ = 0; + std::array bu_abbrev_v_; + ///@} + }; /*bu_dim_store*/ + + /** @class bu_store + * @brief associate basis units with abbreviations **/ - constexpr void bu_establish_abbrev(const scalefactor_ratio_type & scalefactor, - const bu_abbrev_type & abbrev) - { + struct bu_store { + constexpr bu_store() { + // ----- mass ----- - std::int32_t i_abbrev = this->abbrev_lub_ix(scalefactor); + this->bu_establish_abbrev(detail::bu::picogram, bu_abbrev_type::from_chars("pg")); + this->bu_establish_abbrev(detail::bu::nanogram, bu_abbrev_type::from_chars("ng")); + this->bu_establish_abbrev(detail::bu::microgram, bu_abbrev_type::from_chars("ug")); + this->bu_establish_abbrev(detail::bu::milligram, bu_abbrev_type::from_chars("mg")); + this->bu_establish_abbrev(detail::bu::gram, bu_abbrev_type::from_chars("g")); + this->bu_establish_abbrev(detail::bu::kilogram, bu_abbrev_type::from_chars("kg")); + this->bu_establish_abbrev(detail::bu::tonne, bu_abbrev_type::from_chars("t")); + this->bu_establish_abbrev(detail::bu::kilotonne, bu_abbrev_type::from_chars("kt")); + this->bu_establish_abbrev(detail::bu::megatonne, bu_abbrev_type::from_chars("Mt")); + this->bu_establish_abbrev(detail::bu::gigatonne, bu_abbrev_type::from_chars("Gt")); - auto entry = std::make_pair(scalefactor, abbrev); + // ----- distance ----- - if ((i_abbrev < bu_abbrev_v_.size()) - && (bu_abbrev_v_[i_abbrev].first == scalefactor)) - { - bu_abbrev_v_[i_abbrev] = entry; - } else { - this->insert_aux(i_abbrev, entry); - } + this->bu_establish_abbrev(detail::bu::picometer, bu_abbrev_type::from_chars("pm")); + this->bu_establish_abbrev(detail::bu::nanometer, bu_abbrev_type::from_chars("nm")); + this->bu_establish_abbrev(detail::bu::micrometer, bu_abbrev_type::from_chars("um")); + this->bu_establish_abbrev(detail::bu::millimeter, bu_abbrev_type::from_chars("mm")); + this->bu_establish_abbrev(detail::bu::meter, bu_abbrev_type::from_chars("m")); + this->bu_establish_abbrev(detail::bu::kilometer, bu_abbrev_type::from_chars("km")); + this->bu_establish_abbrev(detail::bu::megameter, bu_abbrev_type::from_chars("Mm")); + this->bu_establish_abbrev(detail::bu::gigameter, bu_abbrev_type::from_chars("Gm")); + + this->bu_establish_abbrev(detail::bu::lightsecond, bu_abbrev_type::from_chars("lsec")); + this->bu_establish_abbrev(detail::bu::astronomicalunit, bu_abbrev_type::from_chars("AU")); + + this->bu_establish_abbrev(detail::bu::inch, bu_abbrev_type::from_chars("in")); + this->bu_establish_abbrev(detail::bu::foot, bu_abbrev_type::from_chars("ft")); + this->bu_establish_abbrev(detail::bu::yard, bu_abbrev_type::from_chars("yd")); + this->bu_establish_abbrev(detail::bu::mile, bu_abbrev_type::from_chars("mi")); + + // ----- time ----- + + this->bu_establish_abbrev(detail::bu::picosecond, bu_abbrev_type::from_chars("ps")); + this->bu_establish_abbrev(detail::bu::nanosecond, bu_abbrev_type::from_chars("ns")); + this->bu_establish_abbrev(detail::bu::microsecond, bu_abbrev_type::from_chars("us")); + this->bu_establish_abbrev(detail::bu::millisecond, bu_abbrev_type::from_chars("ms")); + this->bu_establish_abbrev(detail::bu::second, bu_abbrev_type::from_chars("s")); + this->bu_establish_abbrev(detail::bu::minute, bu_abbrev_type::from_chars("min")); + this->bu_establish_abbrev(detail::bu::hour, bu_abbrev_type::from_chars("hr")); + this->bu_establish_abbrev(detail::bu::day, bu_abbrev_type::from_chars("dy")); + this->bu_establish_abbrev(detail::bu::week, bu_abbrev_type::from_chars("wk")); + this->bu_establish_abbrev(detail::bu::month, bu_abbrev_type::from_chars("mo")); + this->bu_establish_abbrev(detail::bu::year250, bu_abbrev_type::from_chars("yr250")); + this->bu_establish_abbrev(detail::bu::year, bu_abbrev_type::from_chars("yr")); + this->bu_establish_abbrev(detail::bu::year360, bu_abbrev_type::from_chars("yr360")); + this->bu_establish_abbrev(detail::bu::year365, bu_abbrev_type::from_chars("yr365")); + + // ----- misc (currency, price) ----- + + this->bu_establish_abbrev(detail::bu::currency, bu_abbrev_type::from_chars("ccy")); + this->bu_establish_abbrev(detail::bu::price, bu_abbrev_type::from_chars("px")); } - public: - std::size_t n_bu_ = 0; - std::array bu_abbrev_v_; - }; - - /** @class bu_store - * @brief associate basis units with abbreviations - **/ - struct bu_store { - constexpr bu_store() { - // ----- mass ----- - - this->bu_establish_abbrev(detail::bu::picogram, bu_abbrev_type::from_chars("pg")); - this->bu_establish_abbrev(detail::bu::nanogram, bu_abbrev_type::from_chars("ng")); - this->bu_establish_abbrev(detail::bu::microgram, bu_abbrev_type::from_chars("ug")); - this->bu_establish_abbrev(detail::bu::milligram, bu_abbrev_type::from_chars("mg")); - this->bu_establish_abbrev(detail::bu::gram, bu_abbrev_type::from_chars("g")); - this->bu_establish_abbrev(detail::bu::kilogram, bu_abbrev_type::from_chars("kg")); - this->bu_establish_abbrev(detail::bu::tonne, bu_abbrev_type::from_chars("t")); - this->bu_establish_abbrev(detail::bu::kilotonne, bu_abbrev_type::from_chars("kt")); - this->bu_establish_abbrev(detail::bu::megatonne, bu_abbrev_type::from_chars("Mt")); - this->bu_establish_abbrev(detail::bu::gigatonne, bu_abbrev_type::from_chars("Gt")); - - // ----- distance ----- - - this->bu_establish_abbrev(detail::bu::picometer, bu_abbrev_type::from_chars("pm")); - this->bu_establish_abbrev(detail::bu::nanometer, bu_abbrev_type::from_chars("nm")); - this->bu_establish_abbrev(detail::bu::micrometer, bu_abbrev_type::from_chars("um")); - this->bu_establish_abbrev(detail::bu::millimeter, bu_abbrev_type::from_chars("mm")); - this->bu_establish_abbrev(detail::bu::meter, bu_abbrev_type::from_chars("m")); - this->bu_establish_abbrev(detail::bu::kilometer, bu_abbrev_type::from_chars("km")); - this->bu_establish_abbrev(detail::bu::megameter, bu_abbrev_type::from_chars("Mm")); - this->bu_establish_abbrev(detail::bu::gigameter, bu_abbrev_type::from_chars("Gm")); - - this->bu_establish_abbrev(detail::bu::lightsecond, bu_abbrev_type::from_chars("lsec")); - this->bu_establish_abbrev(detail::bu::astronomicalunit, bu_abbrev_type::from_chars("AU")); - - this->bu_establish_abbrev(detail::bu::inch, bu_abbrev_type::from_chars("in")); - this->bu_establish_abbrev(detail::bu::foot, bu_abbrev_type::from_chars("ft")); - this->bu_establish_abbrev(detail::bu::yard, bu_abbrev_type::from_chars("yd")); - this->bu_establish_abbrev(detail::bu::mile, bu_abbrev_type::from_chars("mi")); - - // ----- time ----- - - this->bu_establish_abbrev(detail::bu::picosecond, bu_abbrev_type::from_chars("ps")); - this->bu_establish_abbrev(detail::bu::nanosecond, bu_abbrev_type::from_chars("ns")); - this->bu_establish_abbrev(detail::bu::microsecond, bu_abbrev_type::from_chars("us")); - this->bu_establish_abbrev(detail::bu::millisecond, bu_abbrev_type::from_chars("ms")); - this->bu_establish_abbrev(detail::bu::second, bu_abbrev_type::from_chars("s")); - this->bu_establish_abbrev(detail::bu::minute, bu_abbrev_type::from_chars("min")); - this->bu_establish_abbrev(detail::bu::hour, bu_abbrev_type::from_chars("hr")); - this->bu_establish_abbrev(detail::bu::day, bu_abbrev_type::from_chars("dy")); - this->bu_establish_abbrev(detail::bu::week, bu_abbrev_type::from_chars("wk")); - this->bu_establish_abbrev(detail::bu::month, bu_abbrev_type::from_chars("mo")); - this->bu_establish_abbrev(detail::bu::year250, bu_abbrev_type::from_chars("yr250")); - this->bu_establish_abbrev(detail::bu::year, bu_abbrev_type::from_chars("yr")); - this->bu_establish_abbrev(detail::bu::year360, bu_abbrev_type::from_chars("yr360")); - this->bu_establish_abbrev(detail::bu::year365, bu_abbrev_type::from_chars("yr365")); - - // ----- misc (currency, price) ----- - - this->bu_establish_abbrev(detail::bu::currency, bu_abbrev_type::from_chars("ccy")); - this->bu_establish_abbrev(detail::bu::price, bu_abbrev_type::from_chars("px")); - } - - static constexpr bu_abbrev_type - bu_fallback_abbrev(dim basis_dim, - const scalefactor_ratio_type & scalefactor) - { - return (bu_abbrev_type::from_flatstring - (flatstring_concat - (scalefactor.to_str(), - native_unit2_v[static_cast(basis_dim)].abbrev_str()))); - } - - /** @brief get basis-unit abbreviation at runtime **/ - constexpr bu_abbrev_type bu_abbrev(dim basis_dim, - const scalefactor_ratio_type & scalefactor) const - { - const auto & bu_abbrev_v = bu_abbrev_vv_[static_cast(basis_dim)]; - - std::size_t i_abbrev = bu_abbrev_v.abbrev_lub_ix(scalefactor); - - if ((i_abbrev < bu_abbrev_v.size()) - && (bu_abbrev_v[i_abbrev].first == scalefactor)) + static constexpr bu_abbrev_type + bu_fallback_abbrev(dim basis_dim, + const scalefactor_ratio_type & scalefactor) { - return bu_abbrev_v[i_abbrev].second; - } else { - return bu_fallback_abbrev(basis_dim, scalefactor); + return (bu_abbrev_type::from_flatstring + (flatstring_concat + (scalefactor.to_str(), + native_unit2_v[static_cast(basis_dim)].abbrev_str()))); } + + /** @brief get basis-unit abbreviation at runtime **/ + constexpr bu_abbrev_type bu_abbrev(const basis_unit & bu) const + { + const auto & bu_abbrev_v = bu_abbrev_vv_[static_cast(bu.native_dim())]; + + std::size_t i_abbrev = bu_abbrev_v.abbrev_lub_ix(bu.scalefactor()); + + if ((i_abbrev < bu_abbrev_v.size()) + && (bu_abbrev_v[i_abbrev].first == bu.scalefactor())) + { + return bu_abbrev_v[i_abbrev].second; + } else { + return bu_fallback_abbrev(bu.native_dim(), bu.scalefactor()); + } + } + + constexpr void bu_establish_abbrev(const basis_unit & bu, + const bu_abbrev_type & abbrev) { + auto & dim_store = bu_abbrev_vv_[static_cast(bu.native_dim_)]; + + dim_store.bu_establish_abbrev(bu.scalefactor_, abbrev); } - constexpr void bu_establish_abbrev(const basis_unit & bu, - const bu_abbrev_type & abbrev) { - auto & dim_store = bu_abbrev_vv_[static_cast(bu.native_dim_)]; - - dim_store.bu_establish_abbrev(bu.scalefactor_, abbrev); - } - - public: - /** **/ - std::array bu_abbrev_vv_; - }; + public: + /** **/ + std::array bu_abbrev_vv_; + }; + } /*namespace detail*/ /** @brief global abbreviation store. * @@ -216,13 +226,13 @@ namespace xo { * Extending the contents of this store at runtime is not supported, * in favor of preserving constexpr abbreviations. **/ - static constexpr bu_store bu_abbrev_store = bu_store(); + static constexpr detail::bu_store bu_abbrev_store; /** @brief get abbreviation for basis-unit @p bu **/ constexpr bu_abbrev_type bu_abbrev(const basis_unit & bu) { - return bu_abbrev_store.bu_abbrev(bu.native_dim(), bu.scalefactor()); + return bu_abbrev_store.bu_abbrev(bu); } } /*namespace qty*/ } /*namespace xo*/ diff --git a/utest/unit.test.cpp b/utest/unit.test.cpp index 57ca1879..5ae8d3cc 100644 --- a/utest/unit.test.cpp +++ b/utest/unit.test.cpp @@ -12,6 +12,7 @@ namespace xo { namespace ut { /* compile-time tests */ + namespace bu = xo::qty::detail::bu; using xo::qty::bu_abbrev_store; using xo::qty::bu_abbrev_type; using xo::qty::scalefactor_ratio_type; @@ -30,55 +31,55 @@ namespace xo { scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.basis_unit2_store")); //log && log("(A)", xtag("foo", foo)); - log && log(xtag("mass*10^-9", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000)))); - log && log(xtag("mass*10^-6", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000)))); - log && log(xtag("mass*10^-3", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000)))); - log && log(xtag("mass", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1)))); - log && log(xtag("mass*10^3", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1)))); - log && log(xtag("mass*10^6", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1)))); - log && log(xtag("mass*10^9", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1)))); + log && log(xtag("mass*10^-9", bu_abbrev_store.bu_abbrev(bu::picogram))); + log && log(xtag("mass*10^-6", bu_abbrev_store.bu_abbrev(bu::microgram))); + log && log(xtag("mass*10^-3", bu_abbrev_store.bu_abbrev(bu::milligram))); + log && log(xtag("mass", bu_abbrev_store.bu_abbrev(bu::gram))); + log && log(xtag("mass*10^3", bu_abbrev_store.bu_abbrev(bu::kilogram))); + log && log(xtag("mass*10^6", bu_abbrev_store.bu_abbrev(bu::tonne))); + log && log(xtag("mass*10^9", bu_abbrev_store.bu_abbrev(bu::megatonne))); - log && log(xtag("distance*10^-9", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000)))); - log && log(xtag("distance*10^-6", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000)))); - log && log(xtag("distance*10^-3", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000)))); - log && log(xtag("distance", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1)))); - log && log(xtag("distance*10^3", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1)))); + log && log(xtag("distance*10^-9", bu_abbrev_store.bu_abbrev(bu::nanometer))); + log && log(xtag("distance*10^-6", bu_abbrev_store.bu_abbrev(bu::micrometer))); + log && log(xtag("distance*10^-3", bu_abbrev_store.bu_abbrev(bu::millimeter))); + log && log(xtag("distance", bu_abbrev_store.bu_abbrev(bu::meter))); + log && log(xtag("distance*10^3", bu_abbrev_store.bu_abbrev(bu::kilometer))); - log && log(xtag("time*10^-9", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000)))); - log && log(xtag("time*10^-6", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000)))); - log && log(xtag("time*10^-3", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000)))); - log && log(xtag("time", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1)))); - log && log(xtag("time*60", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1)))); - log && log(xtag("time*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1)))); - log && log(xtag("time*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1)))); - log && log(xtag("time*250*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1)))); - log && log(xtag("time*360*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1)))); - log && log(xtag("time*365*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1)))); + log && log(xtag("time*10^-9", bu_abbrev_store.bu_abbrev(bu::nanosecond))); + log && log(xtag("time*10^-6", bu_abbrev_store.bu_abbrev(bu::microsecond))); + log && log(xtag("time*10^-3", bu_abbrev_store.bu_abbrev(bu::millisecond))); + log && log(xtag("time", bu_abbrev_store.bu_abbrev(bu::second))); + log && log(xtag("time*60", bu_abbrev_store.bu_abbrev(bu::minute))); + log && log(xtag("time*3600", bu_abbrev_store.bu_abbrev(bu::hour))); + log && log(xtag("time*24*3600", bu_abbrev_store.bu_abbrev(bu::day))); + log && log(xtag("time*250*24*3600", bu_abbrev_store.bu_abbrev(bu::year250))); + log && log(xtag("time*360*24*3600", bu_abbrev_store.bu_abbrev(bu::year360))); + log && log(xtag("time*365*24*3600", bu_abbrev_store.bu_abbrev(bu::year365))); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ng") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000)).c_str(), "ug") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000)).c_str(), "mg") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1)).c_str(), "g") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1)).c_str(), "kg") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1)).c_str(), "t") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1)).c_str(), "kt") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::nanogram), "ng") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::microgram), "ug") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::milligram), "mg") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::gram), "g") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::kilogram), "kg") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::tonne), "t") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::kilotonne), "kt") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000)).c_str(), "nm") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000)).c_str(), "um") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000)).c_str(), "mm") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1)).c_str(), "m") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1)).c_str(), "km") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::nanometer), "nm") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::micrometer), "um") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::millimeter), "mm") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::meter), "m") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::kilometer), "km") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ns") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000)).c_str(), "us") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000)).c_str(), "ms") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1)).c_str(), "s") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1)).c_str(), "min") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1)).c_str(), "hr") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1)).c_str(), "dy") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1)).c_str(), "yr250") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1)).c_str(), "yr360") == 0); - REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1)).c_str(), "yr365") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::nanosecond), "ns") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::microsecond), "us") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::millisecond), "ms") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::second), "s") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::minute), "min") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::hour), "hr") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::day), "dy") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::year250), "yr250") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::year360), "yr360") == 0); + REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(bu::year365), "yr365") == 0); } /*TEST_CASE(basis_unit2_store)*/