game/tests/test.cpp
2020-07-27 18:59:00 +02:00

45 lines
1.2 KiB
C++

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "../sdlpp.hpp"
// sdlpp.hpp
TEST_CASE( "Rect collisions" ) {
SDLPP::Rect r(0,0,10,10);
REQUIRE(r.colidesWith(r));
SDLPP::Rect r2(100,100,10,10);
REQUIRE_FALSE(r.colidesWith(r2));
SDLPP::Rect r3(10,10,90,90);
REQUIRE(r.colidesWith(r3));
}
TEST_CASE( "Circle collisions" ) {
SDLPP::Circle c(0,0,10);
REQUIRE(c.colidesWith(c));
SDLPP::Circle c2(10,10,10);
REQUIRE(c.colidesWith(c2));
SDLPP::Circle c3(100,100,10);
REQUIRE_FALSE(c.colidesWith(c3));
SDLPP::Circle c4(5,5,2);
REQUIRE(c.colidesWith(c4));
SDLPP::Circle c5(10,0,5);
REQUIRE(c.colidesWith(c5));
}
TEST_CASE( "Multiple collisions" ) {
SDLPP::RectangleRender r(0,0,10,10);
r.addCollision(SDLPP::Circle(0,0,5));
r.addCollision(SDLPP::Circle(10,10,5));
SDLPP::RectangleRender r1(0,0,5,5);
r1.addCollision(SDLPP::Rect(0,0,5,5));
SDLPP::RectangleRender r2(5,5,5,5);
r2.addCollision(SDLPP::Rect(0,0,5,5));
SDLPP::RectangleRender r3(0,6,3,3);
r3.addCollision(SDLPP::Rect(0,0,3,3));
REQUIRE(r.colidesWith(r1));
REQUIRE(r.colidesWith(r2));
REQUIRE_FALSE(r.colidesWith(r3));
}