cleanup code
This commit is contained in:
@@ -1,73 +1,71 @@
|
||||
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 level = LevelState.Create("Fuel leak", 6, 6).SetCell(new(2, 2), new()
|
||||
{
|
||||
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));
|
||||
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 level = LevelState.Create("Wet cable", 6, 6).SetCell(new(3, 3), new()
|
||||
{
|
||||
Pipe = PipeMedium.Coolant,
|
||||
LeakRate = 3,
|
||||
Powered = true
|
||||
});
|
||||
|
||||
var next = _engine.AdvanceTurn(level);
|
||||
|
||||
Assert.True(next.GetCell(new GridPosition(3, 3)).Hazards.ElectricalCharge >= 2);
|
||||
Assert.True(next.GetCell(new(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 level = LevelState.Create("Pressure", 6, 6).SetCell(new(1, 2), new()
|
||||
{
|
||||
Pipe = PipeMedium.Pressure,
|
||||
Pressure = 10,
|
||||
Integrity = 6
|
||||
});
|
||||
|
||||
var forecasts = _engine.Forecast(level);
|
||||
|
||||
Assert.Contains(forecasts, forecast =>
|
||||
forecast.Kind == FailureKind.PipeBurst &&
|
||||
forecast.Turns == 2);
|
||||
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 level = LevelState.Create("Ready", 8, 6).SetCell(new(2, 2), new()
|
||||
{
|
||||
Kind = CellKind.Reactor,
|
||||
Hazards = new() { Heat = 3 }
|
||||
}).SetCell(new(3, 2), new()
|
||||
{
|
||||
Kind = CellKind.Generator,
|
||||
Powered = true
|
||||
}).SetCell(new(4, 2), new()
|
||||
{
|
||||
Kind = CellKind.CoolingPump,
|
||||
Powered = true
|
||||
});
|
||||
|
||||
var next = _engine.AdvanceTurn(level);
|
||||
var activated = _engine.ActivateReactor(next);
|
||||
@@ -80,16 +78,18 @@ public sealed class SimulationEngineTests
|
||||
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);
|
||||
level = LevelEditor.Apply(level, new(2, 2), EditorTool.Reactor);
|
||||
level = LevelEditor.Apply(level, new(1, 2), EditorTool.CoolantPipe);
|
||||
level = LevelEditor.Apply(level, new(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);
|
||||
Assert.Equal(CellKind.Reactor, loaded.GetCell(new(2, 2)).Kind);
|
||||
Assert.Equal(PipeMedium.Coolant, loaded.GetCell(new(1, 2)).Pipe);
|
||||
Assert.Equal(1, loaded.GetCell(new(1, 2)).LeakRate);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly SimulationEngine _engine = new();
|
||||
}
|
||||
Reference in New Issue
Block a user