|
15 | 15 | #include <boxed-cpp/boxed.hpp> |
16 | 16 | #include <catch2/catch.hpp> |
17 | 17 | #include <limits> |
| 18 | +#include <type_traits> |
18 | 19 |
|
19 | 20 | namespace tags { struct Length{}; struct From{}; struct To{}; } |
20 | 21 |
|
@@ -80,3 +81,32 @@ TEST_CASE("function with boxed variables") |
80 | 81 | auto value = std::abs(unbox( wave_speed(vacuum_permittivity, vacuum_permeability) - speed_of_light )); |
81 | 82 | REQUIRE(value < std::numeric_limits<double>::epsilon()); |
82 | 83 | } |
| 84 | + |
| 85 | +TEST_CASE("unbox types check") |
| 86 | +{ |
| 87 | + auto speed_of_light = Speed(299792458.0); |
| 88 | + auto speed_value_native = unbox(speed_of_light); |
| 89 | + static_assert(std::is_same_v<decltype(speed_value_native),double>); |
| 90 | + auto speed_value_float = unbox<float>(speed_of_light); |
| 91 | + static_assert(std::is_same_v<decltype(speed_value_float),float>); |
| 92 | + auto speed_value_int = unbox<int>(speed_of_light); |
| 93 | + static_assert(std::is_same_v<decltype(speed_value_int),int>); |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +TEST_CASE("unbox without template parameters to initial type") |
| 98 | +{ |
| 99 | + auto speed_of_light = Speed(299792458.0); |
| 100 | + REQUIRE( std::abs(unbox(speed_of_light) - 299792458.0) < std::numeric_limits<double>::epsilon()); |
| 101 | +} |
| 102 | + |
| 103 | +TEST_CASE("cast inside rvalue") |
| 104 | +{ |
| 105 | + auto speed_of_light = Speed(299792458.0); |
| 106 | + |
| 107 | + auto distance_auto = speed_of_light * 2.0; |
| 108 | + static_assert(std::is_same_v<decltype(distance_auto),Speed>); |
| 109 | + |
| 110 | + double distance_d = speed_of_light * 2.0; |
| 111 | + REQUIRE(distance_d - 2.0 * 299792458.0 < std::numeric_limits<double>::epsilon()); |
| 112 | +} |
0 commit comments