First batch

This commit is contained in:
2026-05-08 20:46:17 +02:00
parent 83edcfed8a
commit 07d35a49a3
20 changed files with 2509 additions and 1 deletions

View File

@@ -0,0 +1,95 @@
using ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation.Tests;
public sealed class SimulationEngineTests
{
private readonly SimulationEngine _engine = new();
[Fact]
public void FuelLeakNearPoweredGeneratorCreatesIgnitionForecast()
{
var level = LevelState.Create("Fuel leak", 6, 6)
.SetCell(new GridPosition(2, 2), new CellState
{
Kind = CellKind.Generator,
Pipe = PipeMedium.Fuel,
LeakRate = 4,
Pressure = 8,
Integrity = 8,
Powered = true
});
var forecasts = _engine.Forecast(level);
Assert.Contains(forecasts, forecast =>
forecast.Kind == FailureKind.Ignition &&
forecast.Position == new GridPosition(2, 2));
}
[Fact]
public void CoolantLeakOnPoweredCellRaisesElectricalCharge()
{
var level = LevelState.Create("Wet cable", 6, 6)
.SetCell(new GridPosition(3, 3), new CellState
{
Pipe = PipeMedium.Coolant,
LeakRate = 3,
Powered = true
});
var next = _engine.AdvanceTurn(level);
Assert.True(next.GetCell(new GridPosition(3, 3)).Hazards.ElectricalCharge >= 2);
}
[Fact]
public void OverpressurePredictsPipeBurst()
{
var level = LevelState.Create("Pressure", 6, 6)
.SetCell(new GridPosition(1, 2), new CellState
{
Pipe = PipeMedium.Pressure,
Pressure = 10,
Integrity = 6
});
var forecasts = _engine.Forecast(level);
Assert.Contains(forecasts, forecast =>
forecast.Kind == FailureKind.PipeBurst &&
forecast.Turns == 2);
}
[Fact]
public void StableReactorWithPowerAndCoolingCanActivate()
{
var level = LevelState.Create("Ready", 8, 6)
.SetCell(new GridPosition(2, 2), new CellState { Kind = CellKind.Reactor, Hazards = new HazardState { Heat = 3 } })
.SetCell(new GridPosition(3, 2), new CellState { Kind = CellKind.Generator, Powered = true })
.SetCell(new GridPosition(4, 2), new CellState { Kind = CellKind.CoolingPump, Powered = true });
var next = _engine.AdvanceTurn(level);
var activated = _engine.ActivateReactor(next);
Assert.Equal("REACTOR ONLINE", activated.Global.Status);
Assert.True(activated.Global.ReactorActivated);
}
[Fact]
public void LevelSerializationRoundTripsEditableState()
{
var level = LevelState.Create("Round trip", 5, 5);
level = LevelEditor.Apply(level, new GridPosition(2, 2), EditorTool.Reactor);
level = LevelEditor.Apply(level, new GridPosition(1, 2), EditorTool.CoolantPipe);
level = LevelEditor.Apply(level, new GridPosition(1, 2), EditorTool.Leak);
var json = LevelSerializer.Serialize(level);
var loaded = LevelSerializer.Deserialize(json);
Assert.Equal(level.Name, loaded.Name);
Assert.Equal(CellKind.Reactor, loaded.GetCell(new GridPosition(2, 2)).Kind);
Assert.Equal(PipeMedium.Coolant, loaded.GetCell(new GridPosition(1, 2)).Pipe);
Assert.Equal(1, loaded.GetCell(new GridPosition(1, 2)).LeakRate);
}
}