First batch
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ReactorMaintenance.Simulation\ReactorMaintenance.Simulation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user