mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-08 06:48:56 -04:00
Since this is constexpr test, use static_asserts
This commit is contained in:
parent
4e1042c12f
commit
913b219256
@ -3,13 +3,9 @@
|
|||||||
#include <SDL2pp/Point.hh>
|
#include <SDL2pp/Point.hh>
|
||||||
#include <SDL2pp/Rect.hh>
|
#include <SDL2pp/Rect.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
BEGIN_TEST(int, char*[])
|
int main(int, char*[]) {
|
||||||
// note that this is merely a compilation test; EXPECT_s are mainly
|
|
||||||
// used to silence `unused variable' warnings
|
|
||||||
{
|
{
|
||||||
constexpr SDL_Point sp{1, 2};
|
constexpr SDL_Point sp{1, 2};
|
||||||
constexpr Point p1;
|
constexpr Point p1;
|
||||||
@ -20,13 +16,13 @@ BEGIN_TEST(int, char*[])
|
|||||||
constexpr bool b1 = p2 == p4;
|
constexpr bool b1 = p2 == p4;
|
||||||
constexpr bool b2 = p1 != p2;
|
constexpr bool b2 = p1 != p2;
|
||||||
|
|
||||||
EXPECT_TRUE(b1);
|
static_assert(b1, "");
|
||||||
EXPECT_TRUE(b2);
|
static_assert(b2, "");
|
||||||
|
|
||||||
constexpr int x = p1.GetX();
|
constexpr int x = p1.GetX();
|
||||||
constexpr int y = p1.GetY();
|
constexpr int y = p1.GetY();
|
||||||
|
|
||||||
EXPECT_TRUE(x == 0 && y == 0);
|
static_assert(x == 0 && y == 0, "");
|
||||||
|
|
||||||
constexpr Point neg = -p1;
|
constexpr Point neg = -p1;
|
||||||
constexpr Point sum = p1 + p2;
|
constexpr Point sum = p1 + p2;
|
||||||
@ -38,7 +34,7 @@ BEGIN_TEST(int, char*[])
|
|||||||
constexpr Point rem1 = p1 % p2;
|
constexpr Point rem1 = p1 % p2;
|
||||||
constexpr Point rem2 = p1 % 2;
|
constexpr Point rem2 = p1 % 2;
|
||||||
|
|
||||||
EXPECT_EQUAL(neg + sum + diff + mul1 + mul2 + div1 + div2 + rem1 + rem2, Point(0, 0));
|
static_assert(neg + sum + diff + mul1 + mul2 + div1 + div2 + rem1 + rem2 == Point(0, 0), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -49,14 +45,14 @@ BEGIN_TEST(int, char*[])
|
|||||||
constexpr Rect r4(0, 0, 1, 1);
|
constexpr Rect r4(0, 0, 1, 1);
|
||||||
constexpr Rect r5(r4);
|
constexpr Rect r5(r4);
|
||||||
|
|
||||||
EXPECT_EQUAL(r4, r2);
|
static_assert(r4 == r2, "");
|
||||||
EXPECT_EQUAL(r5, r3);
|
static_assert(r5 == r3, "");
|
||||||
|
|
||||||
constexpr bool b1 = r2 == r3;
|
constexpr bool b1 = r2 == r3;
|
||||||
constexpr bool b2 = r1 != r3;
|
constexpr bool b2 = r1 != r3;
|
||||||
|
|
||||||
EXPECT_TRUE(b1);
|
static_assert(b1, "");
|
||||||
EXPECT_TRUE(b2);
|
static_assert(b2, "");
|
||||||
|
|
||||||
constexpr int x = r5.GetX();
|
constexpr int x = r5.GetX();
|
||||||
constexpr int y = r5.GetY();
|
constexpr int y = r5.GetY();
|
||||||
@ -65,20 +61,20 @@ BEGIN_TEST(int, char*[])
|
|||||||
constexpr int x2 = r5.GetX2();
|
constexpr int x2 = r5.GetX2();
|
||||||
constexpr int y2 = r5.GetY2();
|
constexpr int y2 = r5.GetY2();
|
||||||
|
|
||||||
EXPECT_TRUE(x == y);
|
static_assert(x == y, "");
|
||||||
EXPECT_TRUE(w == h);
|
static_assert(w == h, "");
|
||||||
EXPECT_TRUE(x2 == y2);
|
static_assert(x2 == y2, "");
|
||||||
|
|
||||||
constexpr Rect add = r1 + Point(1, 1);
|
constexpr Rect add = r1 + Point(1, 1);
|
||||||
constexpr Rect sub = r1 - Point(1, 1);
|
constexpr Rect sub = r1 - Point(1, 1);
|
||||||
|
|
||||||
EXPECT_EQUAL(add - Point(2, 2), sub);
|
static_assert(add - Point(2, 2) == sub, "");
|
||||||
|
|
||||||
constexpr bool b3 = r2.Contains(0, 0);
|
constexpr bool b3 = r2.Contains(0, 0);
|
||||||
constexpr bool b4 = r2.Contains(Point(0, 0));
|
constexpr bool b4 = r2.Contains(Point(0, 0));
|
||||||
constexpr bool b5 = r2.Contains(Rect(0, 0, 1, 1));
|
constexpr bool b5 = r2.Contains(Rect(0, 0, 1, 1));
|
||||||
constexpr bool b6 = r2.Intersects(Rect(0, 0, 1, 1));
|
constexpr bool b6 = r2.Intersects(Rect(0, 0, 1, 1));
|
||||||
|
|
||||||
EXPECT_TRUE(b3 && b4 && b5 && b6);
|
static_assert(b3 && b4 && b5 && b6, "");
|
||||||
}
|
}
|
||||||
END_TEST()
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user