Skip to content

Commit fa6f9f2

Browse files
committed
Adapt Catch2 test macros for coverage
Signed-off-by: Julien Jerphanion <[email protected]>
1 parent c42c3d0 commit fa6f9f2

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

libmamba/tests/src/util/test_cast.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,11 @@
1414

1515
using namespace mamba::util;
1616

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-
4517
namespace
4618
{
47-
template <typename T>
19+
template <typename From, typename To>
4820
void check_exact_num_cast_widen()
4921
{
50-
using From = typename T::first_type;
51-
using To = typename T::second_type;
5222
static constexpr auto from_lowest = std::numeric_limits<From>::lowest();
5323
static constexpr auto from_max = std::numeric_limits<From>::max();
5424

@@ -58,38 +28,73 @@ namespace
5828
REQUIRE(safe_num_cast<To>(from_max) == static_cast<To>(from_max));
5929
}
6030

61-
TEMPLATE_LIST_TEST_CASE("Exact num cast widen", "", WidenTypes)
31+
TEST_CASE("Exact num cast widen - integers")
6232
{
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>();
6439
}
6540

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>
6755
void check_exact_num_cast_narrow()
6856
{
69-
using From = typename T::second_type; // inversed
70-
using To = typename T::first_type; // inversed
7157
REQUIRE(safe_num_cast<To>(From(0)) == To(0));
7258
REQUIRE(safe_num_cast<To>(From(1)) == To(1));
7359
}
7460

75-
TEMPLATE_LIST_TEST_CASE("Exact num cast narrow", "", WidenTypes)
61+
TEST_CASE("Exact num cast narrow - integers")
7662
{
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>();
7867
}
7968

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>
8175
void check_exact_num_cast_overflow()
8276
{
83-
using From = typename T::first_type;
84-
using To = typename T::second_type;
8577
static constexpr auto from_lowest = std::numeric_limits<From>::lowest();
86-
8778
REQUIRE_THROWS_AS(safe_num_cast<To>(from_lowest), std::overflow_error);
8879
}
8980

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")
9195
{
92-
check_exact_num_cast_overflow<TestType>();
96+
check_exact_num_cast_overflow<double, int>();
97+
check_exact_num_cast_overflow<float, char>();
9398
}
9499

95100
TEST_CASE("precision")

0 commit comments

Comments
 (0)