make tests run again
This commit is contained in:
@@ -194,8 +194,7 @@ TEST_CASE("CombatSystem: no fire when target is out of range", "[combat]")
|
|||||||
|
|
||||||
TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]")
|
TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Find the player defence station.
|
// Find the player defence station.
|
||||||
EntityId stationId = kInvalidEntityId;
|
EntityId stationId = kInvalidEntityId;
|
||||||
@@ -223,7 +222,7 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find a combat ship blueprint for the enemy.
|
// Find a combat ship blueprint for the enemy.
|
||||||
const ShipDef* combatDef = findCombatShip(cfg);
|
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||||
REQUIRE(combatDef != nullptr);
|
REQUIRE(combatDef != nullptr);
|
||||||
|
|
||||||
const EntityId enemyId = sim.ships().spawn(
|
const EntityId enemyId = sim.ships().spawn(
|
||||||
@@ -246,8 +245,7 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]
|
|||||||
|
|
||||||
TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]")
|
TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Find the enemy defence station.
|
// Find the enemy defence station.
|
||||||
EntityId stationId = kInvalidEntityId;
|
EntityId stationId = kInvalidEntityId;
|
||||||
@@ -265,7 +263,7 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
|||||||
}
|
}
|
||||||
REQUIRE(stationId != kInvalidEntityId);
|
REQUIRE(stationId != kInvalidEntityId);
|
||||||
|
|
||||||
const ShipDef* combatDef = findCombatShip(cfg);
|
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||||
REQUIRE(combatDef != nullptr);
|
REQUIRE(combatDef != nullptr);
|
||||||
|
|
||||||
// Spawn a player ship right next to the enemy station.
|
// Spawn a player ship right next to the enemy station.
|
||||||
@@ -291,10 +289,9 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
|||||||
|
|
||||||
TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]")
|
TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const ShipDef* combatDef = findCombatShip(cfg);
|
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||||
REQUIRE(combatDef != nullptr);
|
REQUIRE(combatDef != nullptr);
|
||||||
|
|
||||||
const EntityId shipId = sim.ships().spawn(combatDef->id, 1,
|
const EntityId shipId = sim.ships().spawn(combatDef->id, 1,
|
||||||
@@ -310,12 +307,11 @@ TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]")
|
|||||||
|
|
||||||
TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Find a ship def that drops scrap.
|
// Find a ship def that drops scrap.
|
||||||
const ShipDef* droppingDef = nullptr;
|
const ShipDef* droppingDef = nullptr;
|
||||||
for (const ShipDef& def : cfg.ships.ships)
|
for (const ShipDef& def : sim.config().ships.ships)
|
||||||
{
|
{
|
||||||
if (def.loot.scrapDrop > 0)
|
if (def.loot.scrapDrop > 0)
|
||||||
{
|
{
|
||||||
@@ -337,8 +333,7 @@ TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
|||||||
|
|
||||||
TEST_CASE("CombatSystem: HQ death sets game over", "[combat]")
|
TEST_CASE("CombatSystem: HQ death sets game over", "[combat]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
sim.buildings().forEachBuilding([](Building& b)
|
sim.buildings().forEachBuilding([](Building& b)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,12 +73,11 @@ static void fillMaterials(Simulation& sim, EntityId yardId, const ShipDef& def)
|
|||||||
TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
||||||
"[shipyard]")
|
"[shipyard]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const ShipDef* def = findAvailableBlueprint(cfg);
|
const ShipDef* def = findAvailableBlueprint(sim.config());
|
||||||
REQUIRE(def != nullptr);
|
REQUIRE(def != nullptr);
|
||||||
const BuildingDef* yardDef = findShipyardDef(cfg);
|
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||||
REQUIRE(yardDef != nullptr);
|
REQUIRE(yardDef != nullptr);
|
||||||
|
|
||||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||||
@@ -119,10 +118,9 @@ TEST_CASE("Shipyard: spawns a player ship after production cycle completes",
|
|||||||
|
|
||||||
TEST_CASE("Shipyard: does not spawn without a blueprint set", "[shipyard]")
|
TEST_CASE("Shipyard: does not spawn without a blueprint set", "[shipyard]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const BuildingDef* yardDef = findShipyardDef(cfg);
|
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||||
REQUIRE(yardDef != nullptr);
|
REQUIRE(yardDef != nullptr);
|
||||||
|
|
||||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||||
@@ -136,12 +134,11 @@ TEST_CASE("Shipyard: does not spawn without a blueprint set", "[shipyard]")
|
|||||||
|
|
||||||
TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const ShipDef* def = findAvailableBlueprint(cfg);
|
const ShipDef* def = findAvailableBlueprint(sim.config());
|
||||||
REQUIRE(def != nullptr);
|
REQUIRE(def != nullptr);
|
||||||
const BuildingDef* yardDef = findShipyardDef(cfg);
|
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||||
REQUIRE(yardDef != nullptr);
|
REQUIRE(yardDef != nullptr);
|
||||||
|
|
||||||
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
const int shipsBefore = static_cast<int>(sim.ships().allShips().size());
|
||||||
@@ -161,12 +158,11 @@ TEST_CASE("Shipyard: does not spawn with insufficient materials", "[shipyard]")
|
|||||||
|
|
||||||
TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipyard]")
|
TEST_CASE("Shipyard: spawns a second ship after materials replenished", "[shipyard]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const ShipDef* def = findAvailableBlueprint(cfg);
|
const ShipDef* def = findAvailableBlueprint(sim.config());
|
||||||
REQUIRE(def != nullptr);
|
REQUIRE(def != nullptr);
|
||||||
const BuildingDef* yardDef = findShipyardDef(cfg);
|
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||||
REQUIRE(yardDef != nullptr);
|
REQUIRE(yardDef != nullptr);
|
||||||
|
|
||||||
const EntityId yardId = placeShipyard(sim, *yardDef);
|
const EntityId yardId = placeShipyard(sim, *yardDef);
|
||||||
|
|||||||
@@ -17,16 +17,14 @@ static GameConfig loadConfig()
|
|||||||
|
|
||||||
TEST_CASE("Simulation::currentTick starts at 0", "[simulation]")
|
TEST_CASE("Simulation::currentTick starts at 0", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
const Simulation sim(loadConfig());
|
||||||
const Simulation sim(config);
|
|
||||||
|
|
||||||
REQUIRE(sim.currentTick() == 0);
|
REQUIRE(sim.currentTick() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]")
|
TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
Simulation sim(loadConfig());
|
||||||
Simulation sim(config);
|
|
||||||
|
|
||||||
sim.tick();
|
sim.tick();
|
||||||
|
|
||||||
@@ -35,8 +33,7 @@ TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]")
|
|||||||
|
|
||||||
TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]")
|
TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
Simulation sim(loadConfig());
|
||||||
Simulation sim(config);
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
@@ -48,16 +45,14 @@ TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]")
|
|||||||
|
|
||||||
TEST_CASE("Simulation::drainFireEvents returns empty initially", "[simulation]")
|
TEST_CASE("Simulation::drainFireEvents returns empty initially", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
Simulation sim(loadConfig());
|
||||||
Simulation sim(config);
|
|
||||||
|
|
||||||
REQUIRE(sim.drainFireEvents().empty());
|
REQUIRE(sim.drainFireEvents().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]")
|
TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
Simulation sim(loadConfig());
|
||||||
Simulation sim(config);
|
|
||||||
|
|
||||||
// First drain: empty.
|
// First drain: empty.
|
||||||
sim.drainFireEvents();
|
sim.drainFireEvents();
|
||||||
@@ -68,8 +63,7 @@ TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]")
|
|||||||
|
|
||||||
TEST_CASE("Simulation::drainBlueprintDropEvents returns empty initially", "[simulation]")
|
TEST_CASE("Simulation::drainBlueprintDropEvents returns empty initially", "[simulation]")
|
||||||
{
|
{
|
||||||
const GameConfig config = loadConfig();
|
Simulation sim(loadConfig());
|
||||||
Simulation sim(config);
|
|
||||||
|
|
||||||
REQUIRE(sim.drainBlueprintDropEvents().empty());
|
REQUIRE(sim.drainBlueprintDropEvents().empty());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ TEST_CASE("WaveSystem: generation starts at 0 and increments on push", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations", "[wave]")
|
TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
const Simulation sim(loadConfig(), 42);
|
||||||
const Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
int hqCount = 0;
|
int hqCount = 0;
|
||||||
int playerCount = 0;
|
int playerCount = 0;
|
||||||
@@ -118,11 +117,10 @@ TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations",
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]")
|
TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
const Simulation sim(loadConfig(), 42);
|
||||||
const Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
const float expectedHp =
|
const float expectedHp =
|
||||||
static_cast<float>(cfg.stations.hq.hpFormula.evaluate(0.0));
|
static_cast<float>(sim.config().stations.hq.hpFormula.evaluate(0.0));
|
||||||
bool found = false;
|
bool found = false;
|
||||||
float actualHp = 0.0f;
|
float actualHp = 0.0f;
|
||||||
for (const Building& b : sim.buildings().allBuildings())
|
for (const Building& b : sim.buildings().allBuildings())
|
||||||
@@ -141,8 +139,7 @@ TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: HQ anchor is at asteroid right edge", "[wave]")
|
TEST_CASE("WaveSystem: HQ anchor is at asteroid right edge", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
const Simulation sim(loadConfig(), 42);
|
||||||
const Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
for (const Building& b : sim.buildings().allBuildings())
|
for (const Building& b : sim.buildings().allBuildings())
|
||||||
{
|
{
|
||||||
@@ -159,8 +156,7 @@ TEST_CASE("WaveSystem: HQ anchor is at asteroid right edge", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: player stations have weapon set", "[wave]")
|
TEST_CASE("WaveSystem: player stations have weapon set", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
const Simulation sim(loadConfig(), 42);
|
||||||
const Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
int armedPlayerStations = 0;
|
int armedPlayerStations = 0;
|
||||||
for (const Building& b : sim.buildings().allBuildings())
|
for (const Building& b : sim.buildings().allBuildings())
|
||||||
@@ -178,8 +174,7 @@ TEST_CASE("WaveSystem: player stations have weapon set", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]")
|
TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
const Simulation sim(loadConfig(), 42);
|
||||||
const Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
int armedEnemyStations = 0;
|
int armedEnemyStations = 0;
|
||||||
for (const Building& b : sim.buildings().allBuildings())
|
for (const Building& b : sim.buildings().allBuildings())
|
||||||
@@ -201,8 +196,7 @@ TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]")
|
TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// The maximum gap is gapMaxSeconds = 45s → 1350 ticks.
|
// The maximum gap is gapMaxSeconds = 45s → 1350 ticks.
|
||||||
// Run 1500 ticks to guarantee at least one wave has triggered.
|
// Run 1500 ticks to guarantee at least one wave has triggered.
|
||||||
@@ -226,8 +220,7 @@ TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]")
|
TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Run long enough for several waves.
|
// Run long enough for several waves.
|
||||||
const int limit = static_cast<int>(secondsToTicks(120.0));
|
const int limit = static_cast<int>(secondsToTicks(120.0));
|
||||||
@@ -251,8 +244,7 @@ TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]"
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]")
|
TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Damage both enemy stations to 0.
|
// Damage both enemy stations to 0.
|
||||||
sim.buildings().forEachBuilding([](Building& b)
|
sim.buildings().forEachBuilding([](Building& b)
|
||||||
@@ -276,8 +268,7 @@ TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]"
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: push emits exactly one BlueprintDropEvent", "[wave]")
|
TEST_CASE("WaveSystem: push emits exactly one BlueprintDropEvent", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
sim.buildings().forEachBuilding([](Building& b)
|
sim.buildings().forEachBuilding([](Building& b)
|
||||||
{
|
{
|
||||||
@@ -295,8 +286,7 @@ TEST_CASE("WaveSystem: push emits exactly one BlueprintDropEvent", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]")
|
TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
sim.buildings().forEachBuilding([](Building& b)
|
sim.buildings().forEachBuilding([](Building& b)
|
||||||
{
|
{
|
||||||
@@ -311,7 +301,7 @@ TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]")
|
|||||||
REQUIRE(events.size() == 1);
|
REQUIRE(events.size() == 1);
|
||||||
|
|
||||||
bool validId = false;
|
bool validId = false;
|
||||||
for (const ShipDef& def : cfg.ships.ships)
|
for (const ShipDef& def : sim.config().ships.ships)
|
||||||
{
|
{
|
||||||
if (def.id == events[0].blueprintId)
|
if (def.id == events[0].blueprintId)
|
||||||
{
|
{
|
||||||
@@ -325,8 +315,7 @@ TEST_CASE("WaveSystem: push blueprint drop awards a known ship id", "[wave]")
|
|||||||
|
|
||||||
TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]")
|
TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]")
|
||||||
{
|
{
|
||||||
const GameConfig cfg = loadConfig();
|
Simulation sim(loadConfig(), 42);
|
||||||
Simulation sim(cfg, 42);
|
|
||||||
|
|
||||||
// Record the X position of the initial enemy stations.
|
// Record the X position of the initial enemy stations.
|
||||||
int initialX = std::numeric_limits<int>::min();
|
int initialX = std::numeric_limits<int>::min();
|
||||||
|
|||||||
Reference in New Issue
Block a user