Files
dota_factory/src/test/SimulationTest.cpp
Malte Langkabel 997aecf9f8 Prefix all getters with "get"
Rename bare-noun value accessors to start with "get", per the coding
guideline that a getter's name should begin with "get". Covers simple
nullary accessors across the simulation, balancing, and UI layers
(e.g. currentTick -> getCurrentTick, config -> getConfig,
buildings/belts/ships/scraps/admin, threatLevel, artifactCount,
tilePx, viewportRect, Hasher::value -> getValue, Formula::source ->
getSource).

Left untouched by design: boolean predicates (is*/has*/can*),
verb-named lookups/computations (find*/compute*/peek*/create*),
coordinate transforms, and existing set*-prefixed setters. Test-only
helpers and std/toml++ accessors (optional::value, parse_error::source)
were deliberately not renamed.

Builds clean; all 406 test cases (3222 assertions) pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y7N59FsLA5e2kuVdqe4Uhc
2026-07-19 16:19:28 +02:00

134 lines
3.3 KiB
C++

#include "catch.hpp"
#include "ConfigLoader.h"
#include "GameConfig.h"
#include "Simulation.h"
#include "Tick.h"
#include "TickDriver.h"
static GameConfig loadConfig()
{
return ConfigLoader::loadFromDirectory(CONFIG_DIR);
}
// ---------------------------------------------------------------------------
// Simulation
// ---------------------------------------------------------------------------
TEST_CASE("Simulation::currentTick starts at 0", "[simulation]")
{
const Simulation sim(loadConfig());
REQUIRE(sim.getCurrentTick() == 0);
}
TEST_CASE("Simulation::tick increments currentTick by 1", "[simulation]")
{
Simulation sim(loadConfig());
sim.tick();
REQUIRE(sim.getCurrentTick() == 1);
}
TEST_CASE("Simulation::tick 10 times yields currentTick == 10", "[simulation]")
{
Simulation sim(loadConfig());
for (int i = 0; i < 10; ++i)
{
sim.tick();
}
REQUIRE(sim.getCurrentTick() == 10);
}
TEST_CASE("Simulation::drainBeamFiredEvents returns empty initially", "[simulation]")
{
Simulation sim(loadConfig());
REQUIRE(sim.drainBeamFiredEvents().empty());
}
TEST_CASE("Simulation::drainBeamFiredEvents clears queue on drain", "[simulation]")
{
Simulation sim(loadConfig());
// First drain: empty.
sim.drainBeamFiredEvents();
// Second drain must also be empty (not a double-return).
REQUIRE(sim.drainBeamFiredEvents().empty());
}
TEST_CASE("Simulation::hasSchematicChoicesPending returns false initially", "[simulation]")
{
Simulation sim(loadConfig());
REQUIRE_FALSE(sim.hasSchematicChoicesPending());
}
// ---------------------------------------------------------------------------
// TickDriver
// ---------------------------------------------------------------------------
TEST_CASE("TickDriver: 0x speed never produces ticks", "[simulation]")
{
TickDriver driver;
REQUIRE(driver.advance(100.0, 0.0) == 0);
REQUIRE(driver.advance(1000.0, 0.0) == 0);
}
TEST_CASE("TickDriver: exactly one tick duration at 1x produces 1 tick", "[simulation]")
{
TickDriver driver;
REQUIRE(driver.advance(kTickDurationMs, 1.0) == 1);
}
TEST_CASE("TickDriver: two tick durations at 1x produces 2 ticks", "[simulation]")
{
TickDriver driver;
REQUIRE(driver.advance(2.0 * kTickDurationMs, 1.0) == 2);
}
TEST_CASE("TickDriver: 4x speed with quarter tick duration produces 1 tick", "[simulation]")
{
TickDriver driver;
REQUIRE(driver.advance(kTickDurationMs / 4.0, 4.0) == 1);
}
TEST_CASE("TickDriver: 0.5x speed with double tick duration produces 1 tick", "[simulation]")
{
TickDriver driver;
REQUIRE(driver.advance(kTickDurationMs / 0.5, 0.5) == 1);
}
TEST_CASE("TickDriver: accumulator carries partial progress across frames", "[simulation]")
{
TickDriver driver;
// 60% of a tick — not enough to fire yet.
REQUIRE(driver.advance(kTickDurationMs * 0.6, 1.0) == 0);
// Another 60% — cumulative 120%, so exactly 1 tick fires.
REQUIRE(driver.advance(kTickDurationMs * 0.6, 1.0) == 1);
}
TEST_CASE("TickDriver::reset clears the accumulator", "[simulation]")
{
TickDriver driver;
// Advance to just below one tick.
driver.advance(kTickDurationMs * 0.9, 1.0);
driver.reset();
// Nothing in the accumulator: zero elapsed time should not fire.
REQUIRE(driver.advance(0.0, 1.0) == 0);
}