// 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 namespace { using namespace units::isq; static_assert(si::fps::length(1) == si::length(0.3048)); static_assert(si::fps::mass(1) == si::mass(0.45359237)); static_assert(si::fps::time(1) == si::time(1)); static_assert(si::fps::speed(1) == si::speed(0.3048)); static_assert(si::fps::area(1) == si::area(0.09290304)); static_assert(si::fps::acceleration(1) == si::acceleration(0.3048)); static_assert(si::fps::force(1) > si::force(0.138254) && si::fps::force(1) < si::force(0.138256)); static_assert(si::fps::energy(1) > si::energy(0.042140110093804) && si::fps::energy(1) < si::energy(0.042140110093806)); static_assert(si::fps::power(1) > si::power(0.042140110093804) && si::fps::power(1) < si::power(0.042140110093806)); static_assert(si::fps::pressure(1) > si::pressure(1.4881639435) && si::fps::pressure(1) < si::pressure(1.4881639437)); namespace si_literals { using namespace units::isq::si::literals; static_assert(si::fps::length(1) == 0.3048_q_m); static_assert(si::fps::mass(1) == 0.45359237_q_kg); static_assert(si::fps::time(1) == 1_q_s); static_assert(si::fps::speed(1) == 0.3048_q_m_per_s); static_assert(si::fps::area(1) == 0.09290304_q_m2); static_assert(si::fps::acceleration(1) == 0.3048_q_m_per_s2); static_assert(si::fps::force(1) > 0.138254_q_N && si::fps::force(1) < 0.138256_q_N); static_assert(si::fps::energy(1) > 0.042140110093804_q_J && si::fps::energy(1) < 0.042140110093806_q_J); static_assert(si::fps::power(1) > 0.042140110093804_q_W && si::fps::power(1) < 0.042140110093806_q_W); static_assert(si::fps::pressure(1) > 1.4881639435_q_Pa && si::fps::pressure(1) < 1.4881639437_q_Pa); } namespace fps_literals { using namespace units::isq::si::fps::literals; using namespace units::isq::si::fps::references; static_assert(1 * ft == si::length(0.3048)); static_assert(1_q_lb == si::mass(0.45359237)); static_assert(1_q_s == si::time(1)); static_assert(1_q_ft_per_s == si::speed(0.3048)); static_assert(1_q_ft2 == si::area(0.09290304)); static_assert(1_q_ft_per_s2 == si::acceleration(0.3048)); static_assert(1_q_pdl > si::force(0.138254) && 1_q_pdl < si::force(0.138256)); static_assert(1_q_ft_pdl > si::energy(0.042140110093804) && 1_q_ft_pdl < si::energy(0.042140110093806)); static_assert(1_q_ft_pdl_per_s > si::power(0.042140110093804) && 1_q_ft_pdl_per_s < si::power(0.042140110093806)); static_assert(1_q_pdl_per_ft2> si::pressure(1.4881639435) && 1_q_pdl_per_ft2 < si::pressure(1.4881639437)); } namespace fps_plus_si_literals { using namespace units::isq::si::literals; using namespace units::isq::si::fps::literals; using namespace units::isq::si::fps::references; // static_assert(100_q_cm == 1_q_m); // ambiguous // static_assert(1'000_q_g == 1_q_kg); // ambiguous static_assert(1 * ft == 0.3048_q_m); static_assert(1_q_lb == 0.45359237_q_kg); static_assert(1_q_s == 1_q_s); static_assert(1_q_ft_per_s == 0.3048_q_m_per_s); static_assert(1_q_ft2 == 0.09290304_q_m2); static_assert(1_q_ft_per_s2 == 0.3048_q_m_per_s2); static_assert(1_q_pdl > 0.138254_q_N && 1_q_pdl < 0.138256_q_N); static_assert(1_q_ft_pdl > 0.042140110093804_q_J && 1_q_ft_pdl < 0.042140110093806_q_J); static_assert(1_q_ft_pdl_per_s > 0.042140110093804_q_W && 1_q_ft_pdl_per_s < 0.042140110093806_q_W); static_assert(1_q_pdl_per_ft2> 1.4881639435_q_Pa && 1_q_pdl_per_ft2 <1.4881639437_q_Pa); } namespace fps_test { using namespace units::isq::si::fps::literals; using namespace units::isq::si::fps::references; // addition // static_assert(si::length(1) + 1 * ft == si::length(1.3048)); // should not compile (different dimensions) // static_assert(1 * ft / 0.3048 + si::length(1) == si::length(1.3048)); // should not compile (different dimensions) static_assert(quantity_cast>(1. * ft / 0.3048) + si::length(1) == si::length(2)); // 1 m in ft + 1 m static_assert(si::length(1) + quantity_cast>(1. * ft / 0.3048) == si::length(2)); // 1 m + 1 m in ft static_assert(1 * ft + quantity_cast>(si::length(0.3048)) == 2 * ft); // 1 ft + 1 ft in m static_assert(quantity_cast>(si::length(0.3048)) + 1 * ft == 2 * ft); // 1 ft in m + 1 ft // substraction // static_assert(1 * ft - si::length(1) == -si::length(0.6952)); // should not compile (different dimensions) // static_assert(si::length(1) - 1 * ft == si::length(0.6952)); // should not compile (different dimensions) static_assert(quantity_cast>(6. * ft) - si::length(1) > si::length(0.8287) && quantity_cast>(6. * ft) - si::length(1) < si::length(0.8289)); // 6 ft in m - 1 m = ... m static_assert(si::length(5) - quantity_cast>(6 * ft) == si::length(3.1712)); // 5 m - 6 ft in m = ... static_assert(6. * ft - quantity_cast>(si::length(0.3048)) == 5. * ft); // 6 ft - 1 ft in m = 5 ft static_assert(quantity_cast>(si::length(1.8288)) - 1. * ft == 5. * ft); // 6 ft in m - 1 ft = 5 ft // multiplication // static_assert(2 * ft * si::length(2) == si::area(1.2192)); // should not compile (unknown dimension) // static_assert(quantity_cast>(2. * ft) * si::length(2) == si::area(1.2192)); static_assert(quantity_cast>(2. * ft) * si::length(0.6096) == si::area(0.371612160)); // 2 ft * 2 ft == 4 sq ft static_assert(2. * ft * quantity_cast>(si::length(0.6096)) == 4._q_ft2); // division // static_assert(si::area(4) / 200_q_cm == si::length(2)); // should not compile (unknown dimension) static_assert(si::area(1.48644864) / quantity_cast>(4 * ft) == si::length(1.2192)); // 16 ft2 / 4 ft = 4 ft static_assert(quantity_cast>(si::area(1.48644864)) / (4. * ft) == 4. * ft); // 16 ft2 / 4 ft = 4 ft } }