// 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; static_assert(cgs::length(100) == si::length(1)); static_assert(cgs::mass(1'000) == si::mass(1)); static_assert(cgs::time(1) == si::time(1)); static_assert(cgs::velocity(100) == si::velocity(1)); static_assert(cgs::area(10000) == si::area(1)); static_assert(cgs::acceleration(100) == si::acceleration(1)); static_assert(cgs::force(100'000) == si::force(1)); static_assert(cgs::energy(10'000'000) == si::energy(1)); static_assert(cgs::power(10'000'000) == si::power(1)); static_assert(cgs::pressure(10) == si::pressure(1)); namespace si_test { using namespace units::si::literals; static_assert(cgs::length(100) == 1m); static_assert(cgs::mass(1'000) == 1kg); static_assert(cgs::time(1) == 1s); static_assert(cgs::velocity(100) == 1mps); static_assert(cgs::acceleration(100) == 1mps2); static_assert(cgs::force(100'000) == 1N); static_assert(cgs::energy(10'000'000) == 1_J); static_assert(cgs::power(10'000'000) == 1W); static_assert(cgs::pressure(10) == 1Pa); } namespace cgs_test { using namespace units::cgs::literals; static_assert(100cm == si::length(1)); static_assert(1'000g == si::mass(1)); static_assert(1s == si::time(1)); static_assert(100cmps == si::velocity(1)); static_assert(100Gal == si::acceleration(1)); static_assert(100'000dyn == si::force(1)); static_assert(10'000'000_erg == si::energy(1)); static_assert(10'000'000_ergps == si::power(1)); static_assert(10Ba == si::pressure(1)); } namespace both_test { using namespace units::si::literals; using namespace units::cgs::literals; // static_assert(100cm == 1m); // ambiguous // static_assert(1'000g == 1kg); // ambiguous static_assert(1s == 1s); static_assert(100cmps == 1mps); static_assert(100Gal == 1mps2); static_assert(100'000dyn == 1N); static_assert(10'000'000_erg == 1_J); static_assert(10'000'000_ergps == 1W); static_assert(10Ba == quantity_cast(1Pa)); } namespace cgs_test { // addition // static_assert(100cm + si::length(1) == si::length(2)); // should not compile (different dimensions) // static_assert(si::length(1) + 100cm == si::length(2)); // should not compile (different dimensions) static_assert(quantity_cast>(100cm) + si::length(1) == si::length(2)); static_assert(si::length(1) + quantity_cast>(100cm) == si::length(2)); static_assert(100cm + quantity_cast>(si::length(1)) == 200cm); static_assert(quantity_cast>(si::length(1)) + 100cm == 200cm); // substraction // static_assert(500cm - si::length(1) == si::length(4)); // should not compile (different dimensions) // static_assert(si::length(5) - 100cm == si::length(4)); // should not compile (different dimensions) static_assert(quantity_cast>(500cm) - si::length(1) == si::length(4)); static_assert(si::length(5) - quantity_cast>(100cm) == si::length(4)); static_assert(500cm - quantity_cast>(si::length(1)) == 400cm); static_assert(quantity_cast>(si::length(5)) - 100cm == 400cm); // multiplication // static_assert(200cm * si::length(2) == si::area(4)); // should not compile (unknown dimension) static_assert(quantity_cast(200cm) * si::length(2) == si::area(4)); static_assert(200cm * quantity_cast(si::length(2)) == 40'000cm2); // TODO Add support for quantity_cast on an unknown_dimension? // static_assert(quantity_cast>(200cm * si::length(2)) == si::area(4)); // static_assert(quantity_cast(200cm * si::length(2)) == si::area(4)); // static_assert(quantity_cast>(200cm * si::length(2)) == 40'000sq_cm); // static_assert(quantity_cast(200cm * si::length(2)) == 40'000sq_cm); // division // static_assert(si::area(4) / 200cm == si::length(2)); // should not compile (unknown dimension) static_assert(si::area(4) / quantity_cast>(200cm) == si::length(2)); static_assert(quantity_cast>(si::area(4)) / 200cm == 200cm); } }