14
14
15
15
using namespace mamba ::util;
16
16
17
- using WidenTypes = std::tuple<
18
- // integers
19
- std::pair<char , int >,
20
- std::pair<unsigned char , int >,
21
- std::pair<unsigned char , unsigned int >,
22
- std::pair<int , long long int >,
23
- std::pair<unsigned int , long long int >,
24
- std::pair<unsigned int , unsigned long long int >,
25
- // floats
26
- std::pair<float , double >,
27
- // Mixed
28
- std::pair<char , float >,
29
- std::pair<unsigned char , float >,
30
- std::pair<int , double >,
31
- std::pair<unsigned int , double >>;
32
-
33
- using OverflowLowestTypes = std::tuple<
34
- // integers
35
- std::pair<char , unsigned char >,
36
- std::pair<char , unsigned int >,
37
- std::pair<int , char >,
38
- std::pair<int , unsigned long long int >,
39
- // floats
40
- std::pair<double , float >,
41
- // mixed
42
- std::pair<double , int >,
43
- std::pair<float , char >>;
44
-
45
17
namespace
46
18
{
47
- template <typename T >
19
+ template <typename From, typename To >
48
20
void check_exact_num_cast_widen ()
49
21
{
50
- using From = typename T::first_type;
51
- using To = typename T::second_type;
52
22
static constexpr auto from_lowest = std::numeric_limits<From>::lowest ();
53
23
static constexpr auto from_max = std::numeric_limits<From>::max ();
54
24
@@ -58,38 +28,73 @@ namespace
58
28
REQUIRE (safe_num_cast<To>(from_max) == static_cast <To>(from_max));
59
29
}
60
30
61
- TEMPLATE_LIST_TEST_CASE (" Exact num cast widen" , " " , WidenTypes )
31
+ TEST_CASE (" Exact num cast widen - integers " )
62
32
{
63
- check_exact_num_cast_widen<TestType>();
33
+ check_exact_num_cast_widen<char , int >();
34
+ check_exact_num_cast_widen<unsigned char , int >();
35
+ check_exact_num_cast_widen<unsigned char , unsigned int >();
36
+ check_exact_num_cast_widen<int , long long int >();
37
+ check_exact_num_cast_widen<unsigned int , long long int >();
38
+ check_exact_num_cast_widen<unsigned int , unsigned long long int >();
64
39
}
65
40
66
- template <typename T>
41
+ TEST_CASE (" Exact num cast widen - floats" )
42
+ {
43
+ check_exact_num_cast_widen<float , double >();
44
+ }
45
+
46
+ TEST_CASE (" Exact num cast widen - mixed" )
47
+ {
48
+ check_exact_num_cast_widen<char , float >();
49
+ check_exact_num_cast_widen<unsigned char , float >();
50
+ check_exact_num_cast_widen<int , double >();
51
+ check_exact_num_cast_widen<unsigned int , double >();
52
+ }
53
+
54
+ template <typename From, typename To>
67
55
void check_exact_num_cast_narrow ()
68
56
{
69
- using From = typename T::second_type; // inversed
70
- using To = typename T::first_type; // inversed
71
57
REQUIRE (safe_num_cast<To>(From (0 )) == To (0 ));
72
58
REQUIRE (safe_num_cast<To>(From (1 )) == To (1 ));
73
59
}
74
60
75
- TEMPLATE_LIST_TEST_CASE (" Exact num cast narrow" , " " , WidenTypes )
61
+ TEST_CASE (" Exact num cast narrow - integers " )
76
62
{
77
- check_exact_num_cast_narrow<TestType>();
63
+ check_exact_num_cast_narrow<int , char >();
64
+ check_exact_num_cast_narrow<unsigned int , unsigned char >();
65
+ check_exact_num_cast_narrow<long long int , int >();
66
+ check_exact_num_cast_narrow<unsigned long long int , unsigned int >();
78
67
}
79
68
80
- template <typename T>
69
+ TEST_CASE (" Exact num cast narrow - floats" )
70
+ {
71
+ check_exact_num_cast_narrow<double , float >();
72
+ }
73
+
74
+ template <typename From, typename To>
81
75
void check_exact_num_cast_overflow ()
82
76
{
83
- using From = typename T::first_type;
84
- using To = typename T::second_type;
85
77
static constexpr auto from_lowest = std::numeric_limits<From>::lowest ();
86
-
87
78
REQUIRE_THROWS_AS (safe_num_cast<To>(from_lowest), std::overflow_error);
88
79
}
89
80
90
- TEMPLATE_LIST_TEST_CASE (" Exact num cast overflow" , " " , OverflowLowestTypes)
81
+ TEST_CASE (" Exact num cast overflow - integers" )
82
+ {
83
+ check_exact_num_cast_overflow<char , unsigned char >();
84
+ check_exact_num_cast_overflow<char , unsigned int >();
85
+ check_exact_num_cast_overflow<int , char >();
86
+ check_exact_num_cast_overflow<int , unsigned long long int >();
87
+ }
88
+
89
+ TEST_CASE (" Exact num cast overflow - floats" )
90
+ {
91
+ check_exact_num_cast_overflow<double , float >();
92
+ }
93
+
94
+ TEST_CASE (" Exact num cast overflow - mixed" )
91
95
{
92
- check_exact_num_cast_overflow<TestType>();
96
+ check_exact_num_cast_overflow<double , int >();
97
+ check_exact_num_cast_overflow<float , char >();
93
98
}
94
99
95
100
TEST_CASE (" precision" )
0 commit comments