Skip to content

Commit

Permalink
Add test for checking victory condition when player is destroyed.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 7, 2024
1 parent c461b7b commit 1ed0358
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inline std::string getTestMap()
"E01TA\n"
"01SL1\n"
"E6010\n"
"0213M\n"
"02M31\n"
"50401\n"};
}

Expand Down
24 changes: 24 additions & 0 deletions test/GameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ TEST_CASE("Check winning conditions", "[Game]")
map.hit(common::tileToPoint(1, 2), common::testHitStrength);
REQUIRE(game.isGameEnding(display));
}

SECTION("Check player destroyed")
{
auto playerTankIt{std::find_if(tanks.begin(), tanks.end(),
[](const Tank& tank)
{ return tank.isPlayerControlled(); })};

// Decrease lives to one.
playerTankIt->hit(playerTankIt->getStats().shield_);

// Place enemy tank above player tank.
point = common::tileToPoint(2, 2);
tanks.emplace_back(TankType::ENEMY_TIER_4, point);
Game game(tanks, map);

// Let enenymy tank fire.
game.moveEnemyTanks();

// Let bullet destroy player tank.
for (int i{0}; i < 5; ++i)
game.moveBullets();

REQUIRE(game.isGameEnding(display));
}
}
10 changes: 5 additions & 5 deletions test/MapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_CASE("Map loading", "[map]")
REQUIRE(tankIter->getLocation() == Point{0, 0});
REQUIRE((++tankIter)->getLocation() == Point{0, 2 * tileSize});
REQUIRE((++tankIter)->getLocation() ==
Point{4 * tileSize, 3 * tileSize});
Point{2 * tileSize, 3 * tileSize});
}
}

Expand Down Expand Up @@ -75,9 +75,9 @@ TEST_CASE("Check driving and flying", "[map]")
TestData{common::tileToPoint(4, 2), true}, // plain
TestData{common::tileToPoint(0, 3), true}, // plain
TestData{common::tileToPoint(1, 3), false}, // water
TestData{common::tileToPoint(2, 3), false}, // brick
TestData{common::tileToPoint(2, 3), true}, // plain
TestData{common::tileToPoint(3, 3), true}, // plant
TestData{common::tileToPoint(4, 3), true}, // playe
TestData{common::tileToPoint(4, 3), false}, // brick
TestData{common::tileToPoint(0, 4), false}, // steel
TestData{common::tileToPoint(1, 4), true}, // plain
TestData{common::tileToPoint(2, 4), true}, // ice
Expand Down Expand Up @@ -109,9 +109,9 @@ TEST_CASE("Check driving and flying", "[map]")
TestData{common::tileToPoint(4, 2), true}, // plain
TestData{common::tileToPoint(0, 3), true}, // plain
TestData{common::tileToPoint(1, 3), true}, // water
TestData{common::tileToPoint(2, 3), false}, // brick
TestData{common::tileToPoint(2, 3), true}, // plain
TestData{common::tileToPoint(3, 3), true}, // plant
TestData{common::tileToPoint(4, 3), true}, // player
TestData{common::tileToPoint(4, 3), false}, // brick
TestData{common::tileToPoint(0, 4), false}, // steel
TestData{common::tileToPoint(1, 4), true}, // plain
TestData{common::tileToPoint(2, 4), true}, // ice
Expand Down

0 comments on commit 1ed0358

Please sign in to comment.