From 8230a42cb080fa60829f00baa3c69b2565258591 Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Fri, 29 May 2020 00:57:35 +0100 Subject: [PATCH] added some units for the foot-pound-second system and the static tests --- src/include/units/physical/fps/acceleration.h | 45 +++++ src/include/units/physical/fps/area.h | 47 +++++ src/include/units/physical/fps/energy.h | 54 ++++++ src/include/units/physical/fps/force.h | 58 ++++++ src/include/units/physical/fps/length.h | 47 +++++ src/include/units/physical/fps/mass.h | 47 +++++ src/include/units/physical/fps/power.h | 55 ++++++ src/include/units/physical/fps/pressure.h | 56 ++++++ src/include/units/physical/fps/speed.h | 46 +++++ src/include/units/physical/fps/time.h | 42 +++++ test/unit_test/static/CMakeLists.txt | 2 + test/unit_test/static/fps_test.cpp | 102 +++++++++++ test/unit_test/static/si_fps_test.cpp | 165 ++++++++++++++++++ 13 files changed, 766 insertions(+) create mode 100644 src/include/units/physical/fps/acceleration.h create mode 100644 src/include/units/physical/fps/area.h create mode 100644 src/include/units/physical/fps/energy.h create mode 100644 src/include/units/physical/fps/force.h create mode 100644 src/include/units/physical/fps/length.h create mode 100644 src/include/units/physical/fps/mass.h create mode 100644 src/include/units/physical/fps/power.h create mode 100644 src/include/units/physical/fps/pressure.h create mode 100644 src/include/units/physical/fps/speed.h create mode 100644 src/include/units/physical/fps/time.h create mode 100644 test/unit_test/static/fps_test.cpp create mode 100644 test/unit_test/static/si_fps_test.cpp diff --git a/src/include/units/physical/fps/acceleration.h b/src/include/units/physical/fps/acceleration.h new file mode 100644 index 00000000..7d7ef0fb --- /dev/null +++ b/src/include/units/physical/fps/acceleration.h @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +struct foot_per_second_sq : unit {}; +struct dim_acceleration : physical::dim_acceleration {}; + +template +using acceleration = quantity; + +inline namespace literals { + +// ft_per_s2 +constexpr auto operator"" q_ft_per_s2(unsigned long long l) { return acceleration(l); } +constexpr auto operator"" q_ft_per_s2(long double l) { return acceleration(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/area.h b/src/include/units/physical/fps/area.h new file mode 100644 index 00000000..cd83c0be --- /dev/null +++ b/src/include/units/physical/fps/area.h @@ -0,0 +1,47 @@ +// 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. + +#pragma once + +#include +#include +// #include +#include + +namespace units::physical::fps { + +struct square_foot : unit {}; +struct dim_area : physical::dim_area {}; + + +template +using area = quantity; + +inline namespace literals { + +// fm2 +constexpr auto operator"" q_ft2(unsigned long long l) { return area(l); } +constexpr auto operator"" q_ft2(long double l) { return area(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/energy.h b/src/include/units/physical/fps/energy.h new file mode 100644 index 00000000..d3cbd5e7 --- /dev/null +++ b/src/include/units/physical/fps/energy.h @@ -0,0 +1,54 @@ +// 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. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Foot-poundal +struct foot_poundal : unit {}; + +// https://en.wikipedia.org/wiki/Foot-pound_(energy) +struct foot_pound_force : named_scaled_unit, foot_poundal> {}; + +struct dim_energy : physical::dim_energy {}; + +template +using energy = quantity; + +inline namespace literals { + +constexpr auto operator"" q_ft_pdl(unsigned long long l) { return energy(l); } +constexpr auto operator"" q_ft_pdl(long double l) { return energy(l); } + +// foot_pound force +constexpr auto operator"" q_ft_lbf(unsigned long long l) { return energy(l); } +constexpr auto operator"" q_ft_lbf(long double l) { return energy(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/force.h b/src/include/units/physical/fps/force.h new file mode 100644 index 00000000..cb038e09 --- /dev/null +++ b/src/include/units/physical/fps/force.h @@ -0,0 +1,58 @@ +// 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. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Poundal +struct poundal : named_unit {}; + +// https://en.wikipedia.org/wiki/Pound_(force) +struct pound_force : named_scaled_unit, poundal> {}; + + + +struct dim_force : physical::dim_force {}; + +template +using force = quantity; + +inline namespace literals { + +// poundal +constexpr auto operator"" q_pdl(unsigned long long l) { return force(l); } +constexpr auto operator"" q_pdl(long double l) { return force(l); } + +// pound force +constexpr auto operator"" q_lbf(unsigned long long l) { return force(l); } +constexpr auto operator"" q_lbf(long double l) { return force(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/length.h b/src/include/units/physical/fps/length.h new file mode 100644 index 00000000..c7e5a54c --- /dev/null +++ b/src/include/units/physical/fps/length.h @@ -0,0 +1,47 @@ +// 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. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Foot_(unit) +struct foot : named_scaled_unit, si::metre> {}; + +struct dim_length : physical::dim_length {}; + +template +using length = quantity; + +inline namespace literals { + +// ft +constexpr auto operator"" q_ft(unsigned long long l) { return length(l); } +constexpr auto operator"" q_ft(long double l) { return length(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/mass.h b/src/include/units/physical/fps/mass.h new file mode 100644 index 00000000..7d57d181 --- /dev/null +++ b/src/include/units/physical/fps/mass.h @@ -0,0 +1,47 @@ +// 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. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Pound_(mass) +struct pound : named_scaled_unit, si::kilogram> {}; + +struct dim_mass : physical::dim_mass {}; + +template +using mass = quantity; + +inline namespace literals { + +// g +constexpr auto operator"" q_lb(unsigned long long l) { return mass(l); } +constexpr auto operator"" q_lb(long double l) { return mass(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/power.h b/src/include/units/physical/fps/power.h new file mode 100644 index 00000000..3e572968 --- /dev/null +++ b/src/include/units/physical/fps/power.h @@ -0,0 +1,55 @@ +// 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. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct foot_poundal_per_second : unit {}; + +struct foot_pound_force_per_second : scaled_unit, foot_poundal_per_second> {}; + + +struct dim_power : physical::dim_power {}; + +template +using power = quantity; + +inline namespace literals { + +// foot pound force per second +constexpr auto operator"" q_ft_pdl_per_s(unsigned long long l) { return power(l); } +constexpr auto operator"" q_ft_pdl_per_s(long double l) { return power(l); } + + +// foot pound force per second +constexpr auto operator"" q_ft_lbf_per_s(unsigned long long l) { return power(l); } +constexpr auto operator"" q_ft_lbf_per_s(long double l) { return power(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/pressure.h b/src/include/units/physical/fps/pressure.h new file mode 100644 index 00000000..deb705e0 --- /dev/null +++ b/src/include/units/physical/fps/pressure.h @@ -0,0 +1,56 @@ +// 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. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::physical::fps { + +struct poundal_per_foot_sq : unit {}; + +struct pound_force_per_foot_sq : named_scaled_unit, poundal_per_foot_sq> {}; + + +struct dim_pressure : physical::dim_pressure {}; + +template +using pressure = quantity; + +struct pound_force_per_inch_sq : named_scaled_unit, pound_force_per_foot_sq> {}; + +inline namespace literals { +// Poundal per square foot +constexpr auto operator"" q_pdl_per_ft2(unsigned long long l) { return pressure(l); } +constexpr auto operator"" q_pdl_per_ft2(long double l) { return pressure(l); } + +// Pounds per square inch +constexpr auto operator"" q_psi(unsigned long long l) { return pressure(l); } +constexpr auto operator"" q_psi(long double l) { return pressure(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/speed.h b/src/include/units/physical/fps/speed.h new file mode 100644 index 00000000..222cc96c --- /dev/null +++ b/src/include/units/physical/fps/speed.h @@ -0,0 +1,46 @@ +// 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. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct foot_per_second : unit {}; +struct dim_speed : physical::dim_speed {}; + +template +using speed = quantity; + +inline namespace literals { + +// cmps +constexpr auto operator"" q_ft_per_s(unsigned long long l) { return speed(l); } +constexpr auto operator"" q_ft_per_s(long double l) { return speed(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/time.h b/src/include/units/physical/fps/time.h new file mode 100644 index 00000000..869897e0 --- /dev/null +++ b/src/include/units/physical/fps/time.h @@ -0,0 +1,42 @@ +// 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. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +using si::second; + +using si::dim_time; +using si::time; + +inline namespace literals { + +using si::literals::operator"" q_s; + +} + +} // namespace units::physical::fps diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 8c4610b0..640ecc9b 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -28,11 +28,13 @@ add_library(unit_tests_static dimension_op_test.cpp dimensions_concepts_test.cpp fixed_string_test.cpp + fps_test.cpp math_test.cpp quantity_test.cpp ratio_test.cpp si_test.cpp si_cgs_test.cpp + si_fps_test.cpp symbol_text_test.cpp type_list_test.cpp unit_test.cpp diff --git a/test/unit_test/static/fps_test.cpp b/test/unit_test/static/fps_test.cpp new file mode 100644 index 00000000..e435f056 --- /dev/null +++ b/test/unit_test/static/fps_test.cpp @@ -0,0 +1,102 @@ +// 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 +#include +#include +#include +#include +#include + +namespace { + +using namespace units; +using namespace units::physical::fps; + +/* ************** BASE DIMENSIONS **************** */ + +// length + +static_assert(foot::symbol == "ft"); + +// mass + +// time + +/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ + +// speed + +static_assert(10q_ft / 5q_s == 2q_ft_per_s); +static_assert(10q_ft / 2q_ft_per_s == 5q_s); +static_assert(10q_ft == 2q_ft_per_s * 5q_s); + +static_assert(detail::unit_text() == "ft/s"); + +// area +static_assert(std::is_same_v::ratio>, ratio<1>>); + +static_assert(1q_ft * 1q_ft == 1q_ft2); +static_assert(100q_ft2 / 10q_ft == 10q_ft); + +static_assert(detail::unit_text() == basic_symbol_text("ft²", "ft^2")); + +/* ************** DERIVED DIMENSIONS WITH NAMED UNITS **************** */ + +// acceleration + +static_assert(10q_ft_per_s / 10q_s == 1q_ft_per_s2); +static_assert(10q_ft_per_s / 1q_ft_per_s2 == 10q_s); +static_assert(1q_ft_per_s2 * 10q_s == 10q_ft_per_s); + +// force + +static_assert(10q_lb * 10q_ft_per_s2 == 100q_pdl); +static_assert(100q_pdl / 10q_lb == 10q_ft_per_s2); +static_assert(100q_pdl / 10q_ft_per_s2 == 10q_lb); + +// pressure +static_assert(10q_pdl / 10q_ft2 == 1q_pdl_per_ft2); +static_assert(10q_pdl / 1q_pdl_per_ft2 == 10q_ft2); +static_assert(1q_pdl_per_ft2 * 10q_ft2 == 10q_pdl); + +// energy + +static_assert(10q_pdl * 10q_ft == 100q_ft_pdl); +static_assert(100q_ft_pdl / 10q_ft == 10q_pdl); +static_assert(100q_ft_pdl / 10q_pdl == 10q_ft); + +/* ************** DERIVED DIMENSIONS IN TERMS OF OTHER UNITS **************** */ + +// power + +static_assert(10q_ft_pdl / 10q_s == 1q_ft_pdl_per_s); +static_assert(1q_ft_pdl_per_s * 10q_s == 10q_ft_pdl); +static_assert(10q_ft_pdl / 1q_ft_pdl_per_s == 10q_s); + +// static_assert(detail::unit_text() == "ft_lbf/s"); + +} diff --git a/test/unit_test/static/si_fps_test.cpp b/test/unit_test/static/si_fps_test.cpp new file mode 100644 index 00000000..bd1b6577 --- /dev/null +++ b/test/unit_test/static/si_fps_test.cpp @@ -0,0 +1,165 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using namespace units::physical; + +static_assert(fps::length(1) == si::length(0.3048)); +static_assert(fps::mass(1) == si::mass(0.45359237)); +static_assert(fps::time(1) == si::time(1)); +static_assert(fps::speed(1) == si::speed(0.3048)); +static_assert(fps::area(1) == si::area(0.09290304)); +static_assert(fps::acceleration(1) == si::acceleration(0.3048)); +static_assert(fps::force(1) >= si::force(0.138254) && + fps::force(1) <= si::force(0.138256)); +static_assert(fps::energy(1) >= si::energy(0.042140110093804) && + fps::energy(1) <= si::energy(0.042140110093806)); +static_assert(fps::power(1) >= si::power(0.042140110093804) && + fps::power(1) <= si::power(0.042140110093806)); +static_assert(fps::pressure(1) >= si::pressure(1.4881639435) && + fps::pressure(1) <= si::pressure(1.4881639437)); + +namespace si_literals { + +using namespace units::physical::si::literals; + +static_assert(fps::length(1) == 0.3048q_m); +static_assert(fps::mass(1) == 0.45359237q_kg); +static_assert(fps::time(1) == 1q_s); +static_assert(fps::speed(1) == 0.3048q_m_per_s); +static_assert(fps::area(1) == 0.09290304q_m2); +static_assert(fps::acceleration(1) == 0.3048q_m_per_s2); +static_assert(fps::force(1) >= 0.138254q_N && + fps::force(1) <= 0.138256q_N); +static_assert(fps::energy(1) >= 0.042140110093804q_J && + fps::energy(1) <= 0.042140110093806q_J); +static_assert(fps::power(1) >= 0.042140110093804q_W && + fps::power(1) <= 0.042140110093806q_W); +static_assert(fps::pressure(1) >= 1.4881639435q_Pa && + fps::pressure(1) <= 1.4881639437q_Pa); +} + +namespace fps_literals { + +using namespace units::physical::fps::literals; + +static_assert(1q_ft == si::length(0.3048)); +static_assert(1q_lb == si::mass(0.45359237)); +static_assert(1q_s == si::time(1)); +static_assert(1q_ft_per_s == si::speed(0.3048)); +static_assert(1q_ft2 == si::area(0.09290304)); +static_assert(1q_ft_per_s2 == si::acceleration(0.3048)); +static_assert(1q_pdl >= si::force(0.138254) && + 1q_pdl <= si::force(0.138256)); +static_assert(1q_ft_pdl >= si::energy(0.042140110093804) && + 1q_ft_pdl <= si::energy(0.042140110093806)); +static_assert(1q_ft_pdl_per_s >= si::power(0.042140110093804) && + 1q_ft_pdl_per_s <= si::power(0.042140110093806)); +static_assert(1q_pdl_per_ft2>= si::pressure(1.4881639435) && + 1q_pdl_per_ft2 <= si::pressure(1.4881639437)); +} + +namespace fps_plus_si_literals { + +using namespace units::physical::si::literals; +using namespace units::physical::fps::literals; + +// static_assert(100q_cm == 1q_m); // ambiguous +// static_assert(1'000q_g == 1q_kg); // ambiguous +static_assert(1q_ft == 0.3048q_m); +static_assert(1q_lb == 0.45359237q_kg); +static_assert(1q_s == 1q_s); +static_assert(1q_ft_per_s == 0.3048q_m_per_s); +static_assert(1q_ft2 == 0.09290304q_m2); +static_assert(1q_ft_per_s2 == 0.3048q_m_per_s2); +static_assert(1q_pdl >= 0.138254q_N && + 1q_pdl <= 0.138256q_N); +static_assert(1q_ft_pdl >= 0.042140110093804q_J && + 1q_ft_pdl <= 0.042140110093806q_J); +static_assert(1q_ft_pdl_per_s >= 0.042140110093804q_W && + 1q_ft_pdl_per_s <= 0.042140110093806q_W); +static_assert(1q_pdl_per_ft2>= 1.4881639435q_Pa && + 1q_pdl_per_ft2 <=1.4881639437q_Pa); + +} + +namespace cgs_test { + +using namespace units::physical::fps::literals; + +// addition + +// static_assert(si::length(1) + 1q_ft == si::length(1.3048)); // should not compile (different dimensions) +// static_assert(1q_ft / 0.3048 + si::length(1) == si::length(1.3048)); // should not compile (different dimensions) +static_assert(quantity_cast>(1q_ft / 0.3048) + si::length(1) == si::length(2)); // 1 m in ft + 1 m +static_assert(si::length(1) + quantity_cast>(1q_ft / 0.3048) == si::length(2)); // 1 m + 1 m in ft +static_assert(1q_ft + quantity_cast>(si::length(0.3048)) == 2q_ft); // 1 ft + 1 ft in m +static_assert(quantity_cast>(si::length(0.3048)) + 1q_ft == 2q_ft); // 1 ft in m + 1 ft + +// substraction + +// static_assert(1q_ft - si::length(1) == -si::length(0.6952)); // should not compile (different dimensions) +// static_assert(si::length(1) - 1q_ft == si::length(0.6952)); // should not compile (different dimensions) +static_assert(quantity_cast>(6.q_ft) - si::length(1) == si::length(0.8288)); // 6 ft in m - 1 m = ... m +static_assert(si::length(5) - quantity_cast>(6q_ft) == si::length(3.1712)); // 5 m - 6 ft in m = ... +static_assert(6.q_ft - quantity_cast>(si::length(0.3048)) == 5.q_ft); // 6 ft - 1 ft in m = 5 ft +static_assert(quantity_cast>(si::length(1.8288)) - 1.q_ft == 5.q_ft); // 6 ft in m - 1 ft = 5 ft + +// multiplication + +// static_assert(2q_ft * si::length(2) == si::area(1.2192)); // should not compile (unknown dimension) +// static_assert(quantity_cast>(2.q_ft) * si::length(2) == si::area(1.2192)); +static_assert(quantity_cast>(2.q_ft) * si::length(0.6096) == si::area(0.371612160)); // 2 ft * 2 ft == 4 sq ft +static_assert(2.q_ft * quantity_cast>(si::length(0.6096)) == 4.q_ft2); + +// division + +// static_assert(si::area(4) / 200q_cm == si::length(2)); // should not compile (unknown dimension) +static_assert(si::area(1.48644864) / quantity_cast>(4q_ft) == si::length(1.2192)); // 16 ft2 / 4 ft = 4 ft +static_assert(quantity_cast>(si::area(1.48644864)) / 4.q_ft == 4.q_ft); // 16 ft2 / 4 ft = 4 ft + +} + +}