Replace gtest by catch

This commit is contained in:
Corentin Jabot 2021-09-11 10:09:59 +02:00 committed by Patricia Aas
parent f385036bee
commit d49e1efbc1
7 changed files with 50 additions and 53 deletions

View file

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

View file

@ -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());
}
}
*/

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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>

View file

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