game/tests/test.cpp

93 lines
2.6 KiB
C++

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "../sdlpp/sdlpp.hpp"
#include <iostream>
// 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));
}*/
TEST_CASE( "Point distances" ) {
SDLPP::Vec2D p1(0,0);
SDLPP::Vec2D p2(1,0);
auto dist = vecDistance(p1, p2);
REQUIRE( dist > 0.99 );
REQUIRE( dist < 1.01 );
dist = vecDistance(p2, p1);
REQUIRE( dist > 0.99 );
REQUIRE( dist < 1.01 );
p2 = SDLPP::Vec2D(0,1);
dist = vecDistance(p1, p2);
REQUIRE( dist > 0.99 );
REQUIRE( dist < 1.01 );
dist = vecDistance(p2, p1);
REQUIRE( dist > 0.99 );
REQUIRE( dist < 1.01 );
p2 = SDLPP::Vec2D(1,1);
dist = vecDistance(p1, p2);
REQUIRE( dist > 1.4142 );
REQUIRE( dist < 1.41422 );
}
TEST_CASE( "Point line distances" ) {
SDLPP::Vec2D p1(0,0);
SDLPP::Line line({-1,-1}, {1, -1});
auto dist = pointLineDistance(p1, line);
REQUIRE( dist > 0.99 );
REQUIRE( dist < 1.01 );
line = SDLPP::Line({-3,-1}, {-1,-1});
dist = pointLineDistance(p1, line);
REQUIRE( dist > 1.4142 );
REQUIRE( dist < 1.41422 );
line = SDLPP::Line({-3,-2}, {-2,-2});
dist = pointLineDistance(p1, line);
REQUIRE( dist > 2.8284 );
REQUIRE( dist < 2.82843 );
line = SDLPP::Line({-3,-1}, {-2,-2});
dist = pointLineDistance(p1, line);
std::cout << dist << std::endl;
line = SDLPP::Line({-3,-1}, {-2,-180});
dist = pointLineDistance(p1, line);
std::cout << dist << std::endl;
SDLPP::Vec2D p2(-3, -1);
dist = vecDistance(p1, p2);
std::cout << dist << std::endl;
}