Files
spacetris/tests/test_board.cpp
Gregor Klevze 45086e58d8 Add pure game model + GTest board tests and scaffolding
Add SDL-free Board model: Board.h, Board.cpp
Add unit tests for Board using Google Test: test_board.cpp
Integrate test_board into CMake and register with CTest: update CMakeLists.txt
Add gtest to vcpkg.json so CMake can find GTest
Add high-level refactor plan: plan-spacetrisRefactor.prompt.md
Update internal TODOs to mark logic extraction complete
This scaffolds deterministic, testable game logic and CI-friendly tests without changing existing runtime behavior.
2025-12-25 10:27:35 +01:00

39 lines
1022 B
C++

#include "../src/logic/Board.h"
#include <gtest/gtest.h>
using logic::Board;
TEST(BoardTests, InitiallyEmpty)
{
Board b;
for (int y = 0; y < Board::Height; ++y)
for (int x = 0; x < Board::Width; ++x)
EXPECT_EQ(b.at(x, y), Board::Cell::Empty);
}
TEST(BoardTests, ClearSingleFullLine)
{
Board b;
int y = Board::Height - 1;
for (int x = 0; x < Board::Width; ++x) b.set(x, y, Board::Cell::Filled);
int cleared = b.clearFullLines();
EXPECT_EQ(cleared, 1);
for (int x = 0; x < Board::Width; ++x) EXPECT_EQ(b.at(x, Board::Height - 1), Board::Cell::Empty);
}
TEST(BoardTests, ClearTwoNonAdjacentLines)
{
Board b;
int y1 = Board::Height - 1;
int y2 = Board::Height - 3;
for (int x = 0; x < Board::Width; ++x) { b.set(x, y1, Board::Cell::Filled); b.set(x, y2, Board::Cell::Filled); }
int cleared = b.clearFullLines();
EXPECT_EQ(cleared, 2);
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}