Cover configured simulation effects
This commit is contained in:
@@ -51,6 +51,31 @@ public sealed class SimulationEngineTests
|
|||||||
Assert.True(next.GetCell(new(2, 3)).Hazards.Smoke > 0);
|
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]
|
[Fact]
|
||||||
public void OverpressurePredictsPipeBurst()
|
public void OverpressurePredictsPipeBurst()
|
||||||
{
|
{
|
||||||
@@ -174,4 +199,24 @@ public sealed class SimulationEngineTests
|
|||||||
yield return new(EFailureKind.PipeBurst, new(turns, 0), turns, $"STEP {turns}");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user