diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d54d688..9815763 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,12 +1,8 @@ enable_testing() -find_package(GTest REQUIRED) - -include(GoogleTest) +find_package(Catch2 REQUIRED) file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") add_executable(pacman_tests ${sources}) -target_link_libraries(pacman_tests GTest::GTest libpacman) +target_link_libraries(pacman_tests Catch2::Catch2 libpacman) add_test(NAME pacman_tests COMMAND pacman_tests) - -gtest_discover_tests(pacman_tests) diff --git a/test/testGameState.cpp b/test/testGameState.cpp index c43ed0e..51cdc9e 100644 --- a/test/testGameState.cpp +++ b/test/testGameState.cpp @@ -1,8 +1,11 @@ #include "GameState.hpp" #include -#include +#include -TEST(GameStateTest, Fuzz) { +// TODO: Fuzzing + +/* +TEST_CASE("GameStateTest") { pacman::GameState gameState; //fmt::print("{}\n", gameState.pellets.currentPositions().size()); @@ -23,4 +26,5 @@ TEST(GameStateTest, Fuzz) { //fmt::print("{}\n", pacManDeathCount); //fmt::print("{}\n", gameState.pellets.currentPositions().size()); -} \ No newline at end of file +} +*/ diff --git a/test/testGhost.cpp b/test/testGhost.cpp index b73e85c..148219e 100644 --- a/test/testGhost.cpp +++ b/test/testGhost.cpp @@ -2,21 +2,22 @@ #include "Clyde.hpp" #include "Inky.hpp" #include "Pinky.hpp" -#include +#include + template static void ghostInitHelper(const T & ghost, double x, double y) { const pacman::Position pos{ x, y }; - EXPECT_EQ(ghost.position(), pos); + REQUIRE(ghost.position() == pos); const pacman::GridPosition gridPos = pacman::positionToGridPosition(pos); - EXPECT_EQ(ghost.positionInGrid(), gridPos); + REQUIRE(ghost.positionInGrid() == gridPos); - EXPECT_FALSE(ghost.isEyes()); - EXPECT_FALSE(ghost.isFrightened()); + REQUIRE_FALSE(ghost.isEyes()); + REQUIRE_FALSE(ghost.isFrightened()); } -TEST(GhostTest, Init) { +TEST_CASE("Ghosts start in the correct position", "[ghosts]") { pacman::Blinky blinky; ghostInitHelper(blinky, 13.5, 11); @@ -32,14 +33,14 @@ TEST(GhostTest, Init) { template static void ghostFrightenHelper(T & ghost) { - EXPECT_FALSE(ghost.isFrightened()); + REQUIRE_FALSE(ghost.isFrightened()); ghost.frighten(); - EXPECT_TRUE(ghost.isFrightened()); + REQUIRE(ghost.isFrightened()); ghost.reset(); - EXPECT_FALSE(ghost.isFrightened()); + REQUIRE_FALSE(ghost.isFrightened()); } -TEST(GhostTest, Frighten) { +TEST_CASE("Ghosts are frighten", "[ghosts]") { pacman::Blinky blinky; ghostFrightenHelper(blinky); @@ -55,14 +56,14 @@ TEST(GhostTest, Frighten) { template static void ghostDeadHelper(T & ghost) { - EXPECT_FALSE(ghost.isEyes()); + REQUIRE_FALSE(ghost.isEyes()); ghost.die(); - EXPECT_TRUE(ghost.isEyes()); + REQUIRE(ghost.isEyes()); ghost.reset(); - EXPECT_FALSE(ghost.isEyes()); + REQUIRE_FALSE(ghost.isEyes()); } -TEST(GhostTest, Dead) { +TEST_CASE("Ghosts can die", "[ghosts]") { pacman::Blinky blinky; ghostDeadHelper(blinky); diff --git a/test/testPacMan.cpp b/test/testPacMan.cpp index 573df68..207a9ec 100644 --- a/test/testPacMan.cpp +++ b/test/testPacMan.cpp @@ -1,8 +1,8 @@ #include "PacMan.hpp" -#include +#include -TEST(PacManTest, InitialPosition) { +TEST_CASE("Pacman has the correct initial position") { pacman::PacMan pacMan; - EXPECT_EQ(pacMan.position().x, 13.5); - EXPECT_EQ(pacMan.position().y, 23); + REQUIRE(pacMan.position().x == 13.5); + REQUIRE(pacMan.position().y == 23); } diff --git a/test/testPosition.cpp b/test/testPosition.cpp index fbc8503..8935d69 100644 --- a/test/testPosition.cpp +++ b/test/testPosition.cpp @@ -1,46 +1,46 @@ #include "Position.hpp" -#include +#include -TEST(PositionTest, PositionInit) { +TEST_CASE("Position are properly initialized", "[positions]") { pacman::Position pos; - EXPECT_DOUBLE_EQ(pos.x, 0.0); - EXPECT_DOUBLE_EQ(pos.y, 0.0); + REQUIRE(pos.x == Approx(0.0)); + REQUIRE(pos.y == Approx(0.0)); pacman::Position pos2{ 10.0, 20.0 }; - EXPECT_DOUBLE_EQ(pos2.x, 10.0); - EXPECT_DOUBLE_EQ(pos2.y, 20.0); + REQUIRE(pos2.x == Approx(10.0)); + REQUIRE(pos2.y == Approx(20.0)); } -TEST(PositionTest, GridPositionInit) { +TEST_CASE("GridPosition are properly initialized", "[positions]") { pacman::GridPosition gridPos{ 10, 20 }; - EXPECT_EQ(gridPos.x, 10); - EXPECT_EQ(gridPos.y, 20); + REQUIRE(gridPos.x == 10); + REQUIRE(gridPos.y == 20); } -TEST(PositionTest, ConvertPositionToGridPosition) { +TEST_CASE("Position converts to GridPosition", "[positions]") { pacman::Position pos{ 10.0, 20.0 }; const auto gridPos = pacman::positionToGridPosition(pos); - EXPECT_EQ(gridPos.x, 10); - EXPECT_EQ(gridPos.y, 20); + REQUIRE(gridPos.x == 10); + REQUIRE(gridPos.y == 20); } -TEST(PositionTest, ConvertGridPositionToPosition) { +TEST_CASE("GridPosition converts to Position", "[positions]") { pacman::GridPosition gridPos{ 10, 20 }; const auto pos = pacman::gridPositionToPosition(gridPos); - EXPECT_DOUBLE_EQ(pos.x, 10.0); - EXPECT_DOUBLE_EQ(pos.y, 20.0); + REQUIRE(pos.x == Approx(10.0)); + REQUIRE(pos.y == Approx(20.0)); } -TEST(PositionTest, PositionEquality) { +TEST_CASE("Positions compare equal", "[positions]") { pacman::Position pos1{ 10.0, 20.0 }; pacman::Position pos2{ 10.0, 20.0 }; - EXPECT_TRUE(pos1 == pos2); + REQUIRE(pos1 == pos2); pacman::Position pos3{ 9.9, 19.9 }; - EXPECT_FALSE(pos1 == pos3); + REQUIRE_FALSE(pos1 == pos3); pos3.x += 0.1; pos3.y += 0.1; - EXPECT_TRUE(pos1 == pos3); + REQUIRE(pos1 == pos3); } diff --git a/test/tests.cpp b/test/tests.cpp index e61612e..4ed06df 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,6 +1,2 @@ -#include - -int main(int argc, char * argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +#define CATCH_CONFIG_MAIN +#include diff --git a/vcpkg.json b/vcpkg.json index 5941183..9400f80 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -5,6 +5,6 @@ "dependencies": [ "sfml", "fmt", - "gtest" + "catch2" ] } \ No newline at end of file