Skip to content

Unit test example Player #163

@Longwater1234

Description

@Longwater1234

First add test lib gtest using cpm. The create a test/ dir. then add a sample:

#include "Player.hpp"
#include <gtest/gtest.h>

TEST(PlayerTests, CaptureEnemyWith_Success) {
    chk::Player player(chk::PlayerType::PLAYER_RED);
    // Mock or create a Piece and add it to player
    // Assuming you have a method to add mock pieces
    chk::PiecePtr piece = std::make_unique<chk::Piece>(1); // Mock piece
    player.receivePiece(piece);

    // Test capturing
    sf::Vector2f destination(1.0f, 2.0f);
    EXPECT_TRUE(player.captureEnemyWith(1, destination));
}

TEST(PlayerTests, LosePiece_RemovesPieceFromBasket) {
    chk::Player player(chk::PlayerType::PLAYER_RED);
    chk::PiecePtr piece = std::make_unique<chk::Piece>(1); // Mock piece
    player.receivePiece(piece);

    player.losePiece(1);
    EXPECT_FALSE(player.hasThisPiece(1));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions