From 4d3e4aa1fc8883ef7ff1505e84a2b0512fdc0f4e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 4 Nov 2019 06:46:53 +0000 Subject: [PATCH] Surface tension added --- .../units/dimensions/surface_tension.h | 45 +++++++++++++++++++ test/unit_test/runtime/text_test.cpp | 6 +++ test/unit_test/static/unit_test.cpp | 6 +++ 3 files changed, 57 insertions(+) create mode 100644 src/include/units/dimensions/surface_tension.h diff --git a/src/include/units/dimensions/surface_tension.h b/src/include/units/dimensions/surface_tension.h new file mode 100644 index 00000000..8a106301 --- /dev/null +++ b/src/include/units/dimensions/surface_tension.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 + +namespace units { + + struct surface_tension : derived_dimension, exp> {}; + + template + concept SurfaceTension = QuantityOf; + + struct newton_per_metre : coherent_derived_unit {}; + + inline namespace literals { + + // Nm + constexpr auto operator""Npm(unsigned long long l) { return quantity(l); } + constexpr auto operator""Npm(long double l) { return quantity(l); } + + } // namespace literals + +} // namespace units diff --git a/test/unit_test/runtime/text_test.cpp b/test/unit_test/runtime/text_test.cpp index f7da3571..51f7501e 100644 --- a/test/unit_test/runtime/text_test.cpp +++ b/test/unit_test/runtime/text_test.cpp @@ -90,6 +90,12 @@ TEST_CASE("operator<< on a quantity", "[text][ostream]") stream << 20.km / 2h; REQUIRE(stream.str() == "10 km/h"); } + + SECTION("surface tension") + { + stream << 20.N / 2m; + REQUIRE(stream.str() == "10 N/m"); + } } } diff --git a/test/unit_test/static/unit_test.cpp b/test/unit_test/static/unit_test.cpp index fc52a059..91d910ac 100644 --- a/test/unit_test/static/unit_test.cpp +++ b/test/unit_test/static/unit_test.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -184,4 +185,9 @@ namespace { static_assert(10km * 10km * 10km == 1000cub_km); static_assert(1cub_m == 1'000'000cub_cm); + + /* ************** DERIVED DIMENSIONS IN TERMS OF OTHER UNITS **************** */ + + static_assert(10N / 2m == 5Npm); + } // namespace