From e846d40a331d4b0edf6a02b14bcf5431441f8348 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 2 Nov 2019 13:59:11 +0100 Subject: [PATCH] CGS test added --- test/unit_test/static/CMakeLists.txt | 1 + test/unit_test/static/cgs_test.cpp | 75 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 test/unit_test/static/cgs_test.cpp diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 94241c39..7aa64210 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -21,6 +21,7 @@ # SOFTWARE. add_library(unit_tests_static + cgs_test.cpp custom_unit_test.cpp dimension_test.cpp math_test.cpp diff --git a/test/unit_test/static/cgs_test.cpp b/test/unit_test/static/cgs_test.cpp new file mode 100644 index 00000000..42adada1 --- /dev/null +++ b/test/unit_test/static/cgs_test.cpp @@ -0,0 +1,75 @@ +// 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 + +namespace cgs { + + using units::centimetre; + using units::gram; + using units::second; + struct centimetre_per_second : units::deduced_derived_unit {}; + struct gal : units::deduced_derived_unit {}; + struct dyne : units::deduced_derived_unit {}; + struct erg : units::deduced_derived_unit {}; + struct ergps : units::deduced_derived_unit {}; + struct barye : units::deduced_derived_unit {}; + + + inline namespace literals { + + using namespace units::literals; + + constexpr auto operator""cmps(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""cmps(long double l) { return units::quantity(l); } + constexpr auto operator""Gal(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""Gal(long double l) { return units::quantity(l); } + constexpr auto operator""dyn(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""dyn(long double l) { return units::quantity(l); } + constexpr auto operator""_erg(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""_erg(long double l) { return units::quantity(l); } + constexpr auto operator""_ergps(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""_ergps(long double l) { return units::quantity(l); } + constexpr auto operator""Ba(unsigned long long l) { return units::quantity(l); } + constexpr auto operator""Ba(long double l) { return units::quantity(l); } + + } // namespace literals + +} + +namespace { + + using namespace cgs::literals; + + static_assert(100cm == 1m); + static_assert(1'000g == 1kg); + static_assert(100cmps == 1mps); + static_assert(100Gal == 1mps_sq); + static_assert(100'000dyn == 1N); + static_assert(10'000'000_erg == 1_J); + static_assert(10'000'000_ergps == 1W); + static_assert(10Ba == 1Pa); + +} \ No newline at end of file