fix: unit tests fixed for DOWNCAST_MODE = OFF

This commit is contained in:
Mateusz Pusz
2020-09-10 11:33:58 +02:00
parent d24363af98
commit 58daacfd58
7 changed files with 49 additions and 16 deletions

View File

@@ -467,7 +467,11 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
SECTION("percents")
{
#if DOWNCAST_MODE == 0
const auto q = quantity_cast<dimensionless<percent>>(15._q_m / 100._q_m);
#else
const auto q = quantity_cast<percent>(15._q_m / 100._q_m);
#endif
os << q;
SECTION("iostream")

View File

@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "test_tools.h"
#include <units/physical/si/mass.h>
#include <units/physical/si/voltage.h>
#include <units/physical/si/time.h>
@@ -49,9 +50,6 @@ using amplitude_spectral_density = quantity<dim_amplitude_spectral_density, U, R
namespace {
template<typename T, typename U>
inline constexpr bool compare = DOWNCAST_MODE != 0 ? is_same_v<T, U> : (is_same_v<T, U> || units::equivalent<T, U>);
static_assert(compare<dimension_sqrt<dim_power_spectral_density>, dim_amplitude_spectral_density>);
static_assert(compare<dimension_pow<dim_amplitude_spectral_density, 2>, dim_power_spectral_density>);

View File

@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "test_tools.h"
#include "units/math.h"
#include "units/physical/international/area.h"
#include "units/physical/si/area.h"
@@ -33,9 +34,6 @@ using namespace units;
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
template<typename T, typename U>
inline constexpr bool compare = DOWNCAST_MODE != 0 ? is_same_v<T, U> : (is_same_v<T, U> || units::equivalent<T, U>);
static_assert(compare<decltype(pow<0>(2_q_m)), std::int64_t>);
static_assert(compare<decltype(pow<1>(2_q_m)), decltype(2_q_m)>);
static_assert(compare<decltype(pow<2>(2_q_m)), decltype(4_q_m2)>);

View File

@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "test_tools.h"
#include "units/math.h"
#include "units/physical/si/area.h"
#include "units/physical/si/frequency.h"
@@ -35,9 +36,6 @@ namespace {
using namespace units;
using namespace units::physical::si;
template<typename T, typename U>
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
// class invariants
template<typename DimLength>

View File

@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "test_tools.h"
#include "units/math.h"
#include "units/physical/si/area.h"
#include "units/physical/si/frequency.h"
@@ -34,9 +35,6 @@ namespace {
using namespace units;
using namespace units::physical::si;
template<typename T, typename U>
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
// class invariants
template<typename DimLength>
@@ -202,7 +200,11 @@ static_assert(q1.count() == 2);
constexpr dimensionless<one> q2 = q1;
static_assert(q2.count() == 2000);
#if DOWNCAST_MODE == 0
static_assert(quantity_cast<dimensionless<one>>(q1).count() == 2000);
#else
static_assert(quantity_cast<one>(q1).count() == 2000);
#endif
constexpr auto q3 = 10_q_s * 2_q_kHz;
static_assert(compare<decltype(q3), const dimensionless<scaled_unit<ratio(1, 1, 3), one>, std::int64_t>>);
@@ -310,7 +312,11 @@ static_assert(invalid_dimensionless_operations<int>);
static_assert(compare<decltype(10_q_km / 5_q_km), quantity<dim_one, one, std::int64_t>>);
#if DOWNCAST_MODE == 0
static_assert(quantity_cast<dimensionless<percent>>(50._q_m / 100._q_m).count() == 50);
#else
static_assert(quantity_cast<percent>(50._q_m / 100._q_m).count() == 50);
#endif
static_assert(50._q_m / 100._q_m == dimensionless<percent>(50));
static_assert(dimensionless<one>(dimensionless<percent>(50)).count() == 0.5);
@@ -345,7 +351,7 @@ static_assert(compare<decltype(pow<2>(2_q_m)), decltype(4_q_m2)>);
#if DOWNCAST_MODE == 0
static_assert(std::is_same_v<decltype(10_q_m / 5_q_s), quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, -1>>, scaled_unit<ratio(1), unknown_coherent_unit>, std::int64_t>>);
static_assert(std::is_same_v<decltype(10_q_m / 5_q_s), quantity<unknown_dimension<units::exponent<dim_length, 1>, units::exponent<dim_time, -1>>, scaled_unit<ratio(1), unknown_coherent_unit>, std::int64_t>>);
static_assert(std::is_same_v<decltype(1_q_mm + 1_q_km), length<scaled_unit<ratio(1, 1, -3), metre>, std::int64_t>>);
#else

View File

@@ -0,0 +1,31 @@
// 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 "units/bits/equivalent.h"
template<typename T, typename U>
inline constexpr bool compare_impl = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
template<typename T, typename U>
inline constexpr bool compare = compare_impl<std::remove_cvref_t<T>, std::remove_cvref_t<U>>;

View File

@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "test_tools.h"
#include "units/unit.h"
#include "units/bits/equivalent.h"
#include "units/physical/si/prefixes.h"
@@ -29,9 +30,6 @@ namespace {
using namespace units;
using namespace units::physical;
template<typename T, typename U>
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
struct metre : named_unit<metre, "m", si::prefix> {};
struct centimetre : prefixed_unit<centimetre, si::centi, metre> {};
struct kilometre : prefixed_unit<kilometre, si::kilo, metre> {};