-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for checking victory condition when base is destroyed.
- Loading branch information
Showing
4 changed files
with
143 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include <src/Config.h> | ||
#include <src/Point.h> | ||
|
||
namespace common | ||
{ | ||
const int tileCount{5}; | ||
|
||
inline std::string getTestMap() | ||
{ | ||
return { | ||
"E01TA\n" | ||
"01SL1\n" | ||
"E6010\n" | ||
"0213M\n" | ||
"50401\n"}; | ||
} | ||
|
||
inline Point tileToPoint(int tileX, int tileY) | ||
{ | ||
static const int tileSize{Config::getInstance().getTileSize()}; | ||
return {tileX * tileSize, tileY * tileSize}; | ||
} | ||
|
||
const int testHitStrength{10}; | ||
}; // namespace common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
#include <algorithm> | ||
#include <sstream> | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include <src/Config.h> | ||
#include <src/Game.h> | ||
#include <src/Map.h> | ||
#include <src/TankType.h> | ||
|
||
#include "src/Config.h" | ||
#include "src/TankType.h" | ||
#include "test/FakeDisplay.h" | ||
#include "Common.h" | ||
#include "FakeDisplay.h" | ||
|
||
TEST_CASE("Check winning conditions", "[Game]") | ||
{ | ||
FakeDisplay display; | ||
Config::getInstance().setDefaultSleepTimeInSeconds(0); | ||
|
||
std::list<Tank> tanks; | ||
Point point{0, 0}; | ||
Map map{3}; | ||
Map map(common::tileCount); | ||
std::stringstream stream(common::getTestMap()); | ||
std::list<Tank> tanks{map.loadMap(stream)}; | ||
|
||
SECTION("Check no more enemies") | ||
{ | ||
tanks.clear(); | ||
tanks.emplace_back(TankType::PLAYER_TIER_1, point); | ||
Game game(tanks, map); | ||
REQUIRE(game.isGameEnding(display)); | ||
} | ||
|
||
SECTION("Check game continues") | ||
{ | ||
tanks.emplace_back(TankType::PLAYER_TIER_1, point); | ||
tanks.emplace_back(TankType::ENEMY_TIER_1, point); | ||
Game game(tanks, map); | ||
REQUIRE(!game.isGameEnding(display)); | ||
} | ||
|
||
SECTION("Check base destroyed") | ||
{ | ||
Game game(tanks, map); | ||
map.hit(common::tileToPoint(1, 2), common::testHitStrength); | ||
REQUIRE(game.isGameEnding(display)); | ||
} | ||
} |
Oops, something went wrong.