Cover configured simulation effects

This commit is contained in:
2026-05-08 21:29:12 +02:00
parent 637e9f7fbc
commit 1587395174

View File

@@ -51,6 +51,31 @@ public sealed class SimulationEngineTests
Assert.True(next.GetCell(new(2, 3)).Hazards.Smoke > 0);
}
[Fact]
public void AdvanceTurnRunsConfiguredCellEffects()
{
var engine = new SimulationEngine([new TestCellEffect()], [], []);
var level = LevelState.Create("Custom effect", 6, 6)
.SetCell(new(2, 2), new() {
Hazards = new() { Heat = 1 }
});
var next = engine.AdvanceTurn(level);
Assert.Equal(5, next.GetCell(new(2, 2)).Hazards.Heat);
}
[Fact]
public void AdvanceTurnRunsConfiguredAreaEffects()
{
var engine = new SimulationEngine([], [new TestAreaEffect()], []);
var level = LevelState.Create("Custom area effect", 6, 6);
var next = engine.AdvanceTurn(level);
Assert.Equal(7, next.GetCell(new(2, 2)).Hazards.Smoke);
}
[Fact]
public void OverpressurePredictsPipeBurst()
{
@@ -174,4 +199,24 @@ public sealed class SimulationEngineTests
yield return new(EFailureKind.PipeBurst, new(turns, 0), turns, $"STEP {turns}");
}
}
private sealed class TestCellEffect : ISimulationEffect
{
public CellState Apply(CellState cell)
{
return cell with { Hazards = cell.Hazards with { Heat = 5 } };
}
}
private sealed class TestAreaEffect : IAreaSimulationEffect
{
public CellState[] Apply(LevelState level, CellState[] cells)
{
var next = cells.ToArray();
var position = new GridPosition(2, 2);
var cell = next[level.Index(position)];
next[level.Index(position)] = cell with { Hazards = cell.Hazards with { Smoke = 7 } };
return next;
}
}
}