Browse Source

Replace gtest by catch

des/loadfont
Corentin Jabot 11 months ago committed by Patricia Aas
parent
commit
d49e1efbc1
  1. 8
      test/CMakeLists.txt
  2. 10
      test/testGameState.cpp
  3. 29
      test/testGhost.cpp
  4. 8
      test/testPacMan.cpp
  5. 38
      test/testPosition.cpp
  6. 8
      test/tests.cpp
  7. 2
      vcpkg.json

8
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)

10
test/testGameState.cpp

@ -1,8 +1,11 @@
#include "GameState.hpp"
#include <fmt/format.h>
#include <gtest/gtest.h>
#include <catch2/catch.hpp>
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());
}
}
*/

29
test/testGhost.cpp

@ -2,21 +2,22 @@
#include "Clyde.hpp"
#include "Inky.hpp"
#include "Pinky.hpp"
#include <gtest/gtest.h>
#include <catch2/catch.hpp>
template<typename T>
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<typename T>
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<typename T>
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);

8
test/testPacMan.cpp

@ -1,8 +1,8 @@
#include "PacMan.hpp"
#include <gtest/gtest.h>
#include <catch2/catch.hpp>
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);
}

38
test/testPosition.cpp

@ -1,46 +1,46 @@
#include "Position.hpp"
#include <gtest/gtest.h>
#include <catch2/catch.hpp>
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);
}

8
test/tests.cpp

@ -1,6 +1,2 @@
#include <gtest/gtest.h>
int main(int argc, char * argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

2
vcpkg.json

@ -5,6 +5,6 @@
"dependencies": [
"sfml",
"fmt",
"gtest"
"catch2"
]
}
Loading…
Cancel
Save