From 361ff5c3d1194de59afecf0bcc996d1e25a45196 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 5 Jun 2023 15:06:06 +0200 Subject: [PATCH] test: international system tests added --- .../systems/international/international.h | 1 + test/unit_test/static/CMakeLists.txt | 1 + test/unit_test/static/international_test.cpp | 74 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/unit_test/static/international_test.cpp diff --git a/src/systems/international/include/mp-units/systems/international/international.h b/src/systems/international/include/mp-units/systems/international/international.h index 0b103eba..2660b6d6 100644 --- a/src/systems/international/include/mp-units/systems/international/international.h +++ b/src/systems/international/include/mp-units/systems/international/international.h @@ -35,6 +35,7 @@ inline constexpr struct dram : named_unit<"dr", mag * ounce> {} dr inline constexpr struct grain : named_unit<"gr", mag * pound> {} grain; // length +// https://en.wikipedia.org/wiki/United_States_customary_units#Length inline constexpr struct yard : named_unit<"yd", mag * si::metre> {} yard; inline constexpr struct foot : named_unit<"ft", mag * yard> {} foot; inline constexpr struct inch : named_unit<"in", mag * foot> {} inch; diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index f0677c36..17e4109e 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -48,6 +48,7 @@ add_library( hep_test.cpp iec80000_test.cpp imperial_test.cpp + international_test.cpp isq_test.cpp isq_angle_test.cpp # kind_test.cpp diff --git a/test/unit_test/static/international_test.cpp b/test/unit_test/static/international_test.cpp new file mode 100644 index 00000000..a159dbc4 --- /dev/null +++ b/test/unit_test/static/international_test.cpp @@ -0,0 +1,74 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include +#include + +template + requires mp_units::is_scalar +inline constexpr bool mp_units::is_vector = true; + +namespace { + +using namespace mp_units; +using namespace mp_units::international; +using namespace mp_units::international::unit_symbols; + +// Mass +static_assert(100'000'000 * isq::mass[lb] == 45'359'237 * isq::mass[si::kilogram]); +static_assert(1 * isq::mass[lb] == 16 * isq::mass[oz]); +static_assert(1 * isq::mass[oz] == 16 * isq::mass[dr]); +static_assert(7'000 * isq::mass[gr] == 1 * isq::mass[lb]); + +// Length +// https://en.wikipedia.org/wiki/United_States_customary_units#Length +static_assert(20 * isq::length[twip] == 1 * isq::length[p]); +static_assert(1000 * isq::length[mil] == 1 * isq::length[in]); +static_assert(72 * isq::length[p] == 1 * isq::length[in]); +static_assert(1 * isq::length[P] == 12 * isq::length[p]); +static_assert(1 * isq::length[in] == 6 * isq::length[P]); +static_assert(1 * isq::length[ft] == 12 * isq::length[in]); +static_assert(1 * isq::length[yd] == 3 * isq::length[ft]); +static_assert(10'000 * isq::length[yd] == 9'144 * isq::length[si::metre]); +static_assert(1 * isq::length[mi] == 5280 * isq::length[ft]); +static_assert(1 * isq::length[mi] == 1760 * isq::length[yd]); +static_assert(1 * isq::length[le] == 15'840 * isq::length[ft]); +static_assert(1 * isq::length[le] == 5280 * isq::length[yd]); + +// Nautical +static_assert(1 * isq::length[nmi] == 1852 * isq::length[si::metre]); +static_assert(1 * isq::speed[kn] == isq::length(1 * nmi) / isq::time(1 * si::hour)); + +// Force +static_assert(1 * isq::force[pdl] == isq::mass(1 * lb) * isq::length(1 * ft) / pow<2>(isq::time(1 * si::second))); +static_assert(1 * isq::force[lbf] == isq::mass(1 * lb) * (1 * si::standard_gravity)); +static_assert(1 * isq::force[kip] == 1000 * isq::force[lbf]); + +// Pressure +static_assert(1 * isq::pressure[psi] == isq::force(1 * lbf) / isq::area(1 * square(inch))); + +// Power +static_assert(1 * isq::power[hp] == isq::length(33'000 * ft) * isq::force(1 * lbf) / isq::time(1 * si::minute)); + +} // namespace