FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Test class templates with multiple template types · criptych/SFML@9cb4a68 · GitHub

/ SFML Public
forked from SFML/SFML

Commit 9cb4a68

Browse files
committed
Test class templates with multiple template types
1 parent d3a79e6 commit 9cb4a68

3 files changed

Lines changed: 95 additions & 101 deletions

File tree

‎test/Graphics/Rect.test.cpp‎

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
#include <SFML/System/Vector2.hpp>
44

5-
#include <catch2/catch_test_macros.hpp>
5+
#include <catch2/catch_template_test_macros.hpp>
66

77
#include <GraphicsUtil.hpp>
88
#include <type_traits>
99

10-
TEST_CASE("[Graphics] sf::Rect")
10+
TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float)
1111
{
1212
SECTION("Type traits")
1313
{
14-
STATIC_CHECK(std::is_copy_constructible_v<sf::IntRect>);
15-
STATIC_CHECK(std::is_copy_assignable_v<sf::IntRect>);
16-
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::IntRect>);
17-
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::IntRect>);
14+
STATIC_CHECK(std::is_copy_constructible_v<sf::Rect<TestType>>);
15+
STATIC_CHECK(std::is_copy_assignable_v<sf::Rect<TestType>>);
16+
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Rect<TestType>>);
17+
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Rect<TestType>>);
1818
}
1919

2020
SECTION("Construction")
2121
{
2222
SECTION("Default constructor")
2323
{
24-
constexpr sf::IntRect rectangle;
24+
constexpr sf::Rect<TestType> rectangle;
2525
STATIC_CHECK(rectangle.left == 0);
2626
STATIC_CHECK(rectangle.top == 0);
2727
STATIC_CHECK(rectangle.width == 0);
@@ -30,7 +30,7 @@ TEST_CASE("[Graphics] sf::Rect")
3030

3131
SECTION("(left, top, width, height) constructor")
3232
{
33-
constexpr sf::IntRect rectangle({1, 2}, {3, 4});
33+
constexpr sf::Rect<TestType> rectangle({1, 2}, {3, 4});
3434
STATIC_CHECK(rectangle.left == 1);
3535
STATIC_CHECK(rectangle.top == 2);
3636
STATIC_CHECK(rectangle.width == 3);
@@ -39,9 +39,9 @@ TEST_CASE("[Graphics] sf::Rect")
3939

4040
SECTION("(Vector2, Vector2) constructor")
4141
{
42-
constexpr sf::Vector2i position(1, 2);
43-
constexpr sf::Vector2i dimension(3, 4);
44-
constexpr sf::IntRect rectangle(position, dimension);
42+
constexpr sf::Vector2<TestType> position(1, 2);
43+
constexpr sf::Vector2<TestType> dimension(3, 4);
44+
constexpr sf::Rect<TestType> rectangle(position, dimension);
4545

4646
STATIC_CHECK(rectangle.left == 1);
4747
STATIC_CHECK(rectangle.top == 2);
@@ -63,22 +63,22 @@ TEST_CASE("[Graphics] sf::Rect")
6363

6464
SECTION("contains(Vector2)")
6565
{
66-
constexpr sf::IntRect rectangle({0, 0}, {10, 10});
67-
68-
STATIC_CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true);
69-
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true);
70-
STATIC_CHECK(rectangle.contains(sf::Vector2i(0, 9)) == true);
71-
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 9)) == true);
72-
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 10)) == false);
73-
STATIC_CHECK(rectangle.contains(sf::Vector2i(10, 9)) == false);
74-
STATIC_CHECK(rectangle.contains(sf::Vector2i(10, 10)) == false);
75-
STATIC_CHECK(rectangle.contains(sf::Vector2i(15, 15)) == false);
66+
constexpr sf::Rect<TestType> rectangle({0, 0}, {10, 10});
67+
68+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(0, 0)) == true);
69+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(9, 0)) == true);
70+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(0, 9)) == true);
71+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(9, 9)) == true);
72+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(9, 10)) == false);
73+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(10, 9)) == false);
74+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(10, 10)) == false);
75+
STATIC_CHECK(rectangle.contains(sf::Vector2<TestType>(15, 15)) == false);
7676
}
7777

7878
SECTION("findIntersection()")
7979
{
80-
constexpr sf::IntRect rectangle({0, 0}, {10, 10});
81-
constexpr sf::IntRect intersectingRectangle({5, 5}, {10, 10});
80+
constexpr sf::Rect<TestType> rectangle({0, 0}, {10, 10});
81+
constexpr sf::Rect<TestType> intersectingRectangle({5, 5}, {10, 10});
8282

8383
constexpr auto intersectionResult = rectangle.findIntersection(intersectingRectangle);
8484
STATIC_REQUIRE(intersectionResult.has_value());
@@ -87,50 +87,50 @@ TEST_CASE("[Graphics] sf::Rect")
8787
STATIC_CHECK(intersectionResult->width == 5);
8888
STATIC_CHECK(intersectionResult->height == 5);
8989

90-
constexpr sf::IntRect nonIntersectingRectangle({-5, -5}, {5, 5});
90+
constexpr sf::Rect<TestType> nonIntersectingRectangle({-5, -5}, {5, 5});
9191
STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value());
9292
}
9393

9494
SECTION("getPosition()")
9595
{
96-
STATIC_CHECK(sf::IntRect({}, {}).getPosition() == sf::Vector2i());
97-
STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getPosition() == sf::Vector2i(1, 2));
96+
STATIC_CHECK(sf::Rect<TestType>({}, {}).getPosition() == sf::Vector2<TestType>());
97+
STATIC_CHECK(sf::Rect<TestType>({1, 2}, {3, 4}).getPosition() == sf::Vector2<TestType>(1, 2));
9898
}
9999

100100
SECTION("getSize()")
101101
{
102-
STATIC_CHECK(sf::IntRect({}, {}).getSize() == sf::Vector2i());
103-
STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4));
102+
STATIC_CHECK(sf::Rect<TestType>({}, {}).getSize() == sf::Vector2<TestType>());
103+
STATIC_CHECK(sf::Rect<TestType>({1, 2}, {3, 4}).getSize() == sf::Vector2<TestType>(3, 4));
104104
}
105105

106106
SECTION("getCenter()")
107107
{
108-
STATIC_CHECK(sf::IntRect({}, {}).getCenter() == sf::Vector2i());
109-
STATIC_CHECK(sf::IntRect({1, 2}, {4, 6}).getCenter() == sf::Vector2i(3, 5));
108+
STATIC_CHECK(sf::Rect<TestType>({}, {}).getCenter() == sf::Vector2<TestType>());
109+
STATIC_CHECK(sf::Rect<TestType>({1, 2}, {4, 6}).getCenter() == sf::Vector2<TestType>(3, 5));
110110
}
111111

112112
SECTION("Operators")
113113
{
114114
SECTION("operator==")
115115
{
116-
STATIC_CHECK(sf::IntRect() == sf::IntRect());
117-
STATIC_CHECK(sf::IntRect({1, 3}, {2, 5}) == sf::IntRect({1, 3}, {2, 5}));
116+
STATIC_CHECK(sf::Rect<TestType>() == sf::Rect<TestType>());
117+
STATIC_CHECK(sf::Rect<TestType>({1, 3}, {2, 5}) == sf::Rect<TestType>({1, 3}, {2, 5}));
118118

119-
STATIC_CHECK_FALSE(sf::IntRect({1, 0}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
120-
STATIC_CHECK_FALSE(sf::IntRect({0, 1}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
121-
STATIC_CHECK_FALSE(sf::IntRect({0, 0}, {1, 0}) == sf::IntRect({0, 0}, {0, 0}));
122-
STATIC_CHECK_FALSE(sf::IntRect({0, 0}, {0, 1}) == sf::IntRect({0, 0}, {0, 0}));
119+
STATIC_CHECK_FALSE(sf::Rect<TestType>({1, 0}, {0, 0}) == sf::Rect<TestType>({0, 0}, {0, 0}));
120+
STATIC_CHECK_FALSE(sf::Rect<TestType>({0, 1}, {0, 0}) == sf::Rect<TestType>({0, 0}, {0, 0}));
121+
STATIC_CHECK_FALSE(sf::Rect<TestType>({0, 0}, {1, 0}) == sf::Rect<TestType>({0, 0}, {0, 0}));
122+
STATIC_CHECK_FALSE(sf::Rect<TestType>({0, 0}, {0, 1}) == sf::Rect<TestType>({0, 0}, {0, 0}));
123123
}
124124

125125
SECTION("operator!=")
126126
{
127-
STATIC_CHECK(sf::IntRect({1, 0}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
128-
STATIC_CHECK(sf::IntRect({0, 1}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
129-
STATIC_CHECK(sf::IntRect({0, 0}, {1, 0}) != sf::IntRect({0, 0}, {0, 0}));
130-
STATIC_CHECK(sf::IntRect({0, 0}, {0, 1}) != sf::IntRect({0, 0}, {0, 0}));
127+
STATIC_CHECK(sf::Rect<TestType>({1, 0}, {0, 0}) != sf::Rect<TestType>({0, 0}, {0, 0}));
128+
STATIC_CHECK(sf::Rect<TestType>({0, 1}, {0, 0}) != sf::Rect<TestType>({0, 0}, {0, 0}));
129+
STATIC_CHECK(sf::Rect<TestType>({0, 0}, {1, 0}) != sf::Rect<TestType>({0, 0}, {0, 0}));
130+
STATIC_CHECK(sf::Rect<TestType>({0, 0}, {0, 1}) != sf::Rect<TestType>({0, 0}, {0, 0}));
131131

132-
STATIC_CHECK_FALSE(sf::IntRect() != sf::IntRect());
133-
STATIC_CHECK_FALSE(sf::IntRect({1, 3}, {2, 5}) != sf::IntRect({1, 3}, {2, 5}));
132+
STATIC_CHECK_FALSE(sf::Rect<TestType>() != sf::Rect<TestType>());
133+
STATIC_CHECK_FALSE(sf::Rect<TestType>({1, 3}, {2, 5}) != sf::Rect<TestType>({1, 3}, {2, 5}));
134134
}
135135
}
136136
}

‎test/System/Vector2.test.cpp‎

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <SFML/System/Vector2.hpp>
22

3-
#include <catch2/catch_test_macros.hpp>
3+
#include <catch2/catch_template_test_macros.hpp>
44

55
#include <SystemUtil.hpp>
66
#include <type_traits>
@@ -9,31 +9,28 @@
99

1010
using namespace sf::Literals;
1111

12-
// Use sf::Vector2i for tests (except for float vector algebra).
13-
// Test coverage is given, as there are no template specializations.
14-
15-
TEST_CASE("[System] sf::Vector2")
12+
TEMPLATE_TEST_CASE("[System] sf::Vector2", "", int, float)
1613
{
1714
SECTION("Type traits")
1815
{
19-
STATIC_CHECK(std::is_copy_constructible_v<sf::Vector2i>);
20-
STATIC_CHECK(std::is_copy_assignable_v<sf::Vector2i>);
21-
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Vector2i>);
22-
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Vector2i>);
16+
STATIC_CHECK(std::is_copy_constructible_v<sf::Vector2<TestType>>);
17+
STATIC_CHECK(std::is_copy_assignable_v<sf::Vector2<TestType>>);
18+
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Vector2<TestType>>);
19+
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Vector2<TestType>>);
2320
}
2421

2522
SECTION("Construction")
2623
{
2724
SECTION("Default constructor")
2825
{
29-
constexpr sf::Vector2i vector;
26+
constexpr sf::Vector2<TestType> vector;
3027
STATIC_CHECK(vector.x == 0);
3128
STATIC_CHECK(vector.y == 0);
3229
}
3330

3431
SECTION("(x, y) coordinate constructor")
3532
{
36-
constexpr sf::Vector2i vector(1, 2);
33+
constexpr sf::Vector2<TestType> vector(1, 2);
3734
STATIC_CHECK(vector.x == 1);
3835
STATIC_CHECK(vector.y == 2);
3936
}
@@ -105,8 +102,8 @@ TEST_CASE("[System] sf::Vector2")
105102
{
106103
SECTION("-vector")
107104
{
108-
constexpr sf::Vector2i vector(1, 2);
109-
constexpr sf::Vector2i negatedVector = -vector;
105+
constexpr sf::Vector2<TestType> vector(1, 2);
106+
constexpr sf::Vector2<TestType> negatedVector = -vector;
110107

111108
STATIC_CHECK(negatedVector.x == -1);
112109
STATIC_CHECK(negatedVector.y == -2);
@@ -115,8 +112,8 @@ TEST_CASE("[System] sf::Vector2")
115112

116113
SECTION("Arithmetic operations between two vectors")
117114
{
118-
sf::Vector2i firstVector(2, 5);
119-
constexpr sf::Vector2i secondVector(8, 3);
115+
sf::Vector2<TestType> firstVector(2, 5);
116+
constexpr sf::Vector2<TestType> secondVector(8, 3);
120117

121118
SECTION("vector += vector")
122119
{
@@ -136,15 +133,15 @@ TEST_CASE("[System] sf::Vector2")
136133

137134
SECTION("vector + vector")
138135
{
139-
const sf::Vector2i result = firstVector + secondVector;
136+
const sf::Vector2<TestType> result = firstVector + secondVector;
140137

141138
CHECK(result.x == 10);
142139
CHECK(result.y == 8);
143140
}
144141

145142
SECTION("vector - vector")
146143
{
147-
const sf::Vector2i result = firstVector - secondVector;
144+
const sf::Vector2<TestType> result = firstVector - secondVector;
148145

149146
CHECK(result.x == -6);
150147
CHECK(result.y == 2);
@@ -153,20 +150,20 @@ TEST_CASE("[System] sf::Vector2")
153150

154151
SECTION("Arithmetic operations between vector and scalar value")
155152
{
156-
sf::Vector2i vector(26, 12);
157-
const int scalar = 2;
153+
sf::Vector2<TestType> vector(26, 12);
154+
const TestType scalar = 2;
158155

159156
SECTION("vector * scalar")
160157
{
161-
const sf::Vector2i result = vector * scalar;
158+
const sf::Vector2<TestType> result = vector * scalar;
162159

163160
CHECK(result.x == 52);
164161
CHECK(result.y == 24);
165162
}
166163

167164
SECTION("scalar * vector")
168165
{
169-
const sf::Vector2i result = scalar * vector;
166+
const sf::Vector2<TestType> result = scalar * vector;
170167

171168
CHECK(result.x == 52);
172169
CHECK(result.y == 24);
@@ -182,7 +179,7 @@ TEST_CASE("[System] sf::Vector2")
182179

183180
SECTION("vector / scalar")
184181
{
185-
const sf::Vector2i result = vector / scalar;
182+
const sf::Vector2<TestType> result = vector / scalar;
186183

187184
CHECK(result.x == 13);
188185
CHECK(result.y == 6);
@@ -199,9 +196,9 @@ TEST_CASE("[System] sf::Vector2")
199196

200197
SECTION("Comparison operations (two equal and one different vector)")
201198
{
202-
constexpr sf::Vector2i firstEqualVector(1, 5);
203-
constexpr sf::Vector2i secondEqualVector(1, 5);
204-
constexpr sf::Vector2i differentVector(6, 9);
199+
constexpr sf::Vector2<TestType> firstEqualVector(1, 5);
200+
constexpr sf::Vector2<TestType> secondEqualVector(1, 5);
201+
constexpr sf::Vector2<TestType> differentVector(6, 9);
205202

206203
SECTION("vector == vector")
207204
{
@@ -218,7 +215,7 @@ TEST_CASE("[System] sf::Vector2")
218215

219216
SECTION("Structured bindings")
220217
{
221-
sf::Vector2i vector(1, 2); // NOLINT(misc-const-correctness)
218+
sf::Vector2<TestType> vector(1, 2); // NOLINT(misc-const-correctness)
222219

223220
SECTION("destructure by value")
224221
{
@@ -329,19 +326,19 @@ TEST_CASE("[System] sf::Vector2")
329326

330327
SECTION("Constexpr support")
331328
{
332-
constexpr sf::Vector2i v(1, 2);
333-
constexpr sf::Vector2i w(2, -3);
329+
constexpr sf::Vector2<TestType> v(1, 2);
330+
constexpr sf::Vector2<TestType> w(2, -6);
334331

335332
STATIC_CHECK(v.x == 1);
336333
STATIC_CHECK(v.y == 2);
337-
STATIC_CHECK(v + w == sf::Vector2i(3, -1));
334+
STATIC_CHECK(v + w == sf::Vector2<TestType>(3, -4));
338335

339336
STATIC_CHECK(v.lengthSq() == 5);
340-
STATIC_CHECK(v.perpendicular() == sf::Vector2i(-2, 1));
337+
STATIC_CHECK(v.perpendicular() == sf::Vector2<TestType>(-2, 1));
341338

342-
STATIC_CHECK(v.dot(w) == -4);
343-
STATIC_CHECK(v.cross(w) == -7);
344-
STATIC_CHECK(v.cwiseMul(w) == sf::Vector2i(2, -6));
345-
STATIC_CHECK(w.cwiseDiv(v) == sf::Vector2i(2, -1));
339+
STATIC_CHECK(v.dot(w) == -10);
340+
STATIC_CHECK(v.cross(w) == -10);
341+
STATIC_CHECK(v.cwiseMul(w) == sf::Vector2<TestType>(2, -12));
342+
STATIC_CHECK(w.cwiseDiv(v) == sf::Vector2<TestType>(2, -3));
346343
}
347344
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL