Improve persistence and reactor dynamics
This commit is contained in:
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from reactor_sim import constants
|
||||
from reactor_sim.failures import HealthMonitor
|
||||
from reactor_sim.reactor import Reactor
|
||||
from reactor_sim.simulation import ReactorSimulation
|
||||
|
||||
@@ -13,7 +14,7 @@ def test_reactor_initial_state_is_cold():
|
||||
state = reactor.initial_state()
|
||||
assert state.core.fuel_temperature == constants.ENVIRONMENT_TEMPERATURE
|
||||
assert state.primary_loop.mass_flow_rate == 0.0
|
||||
assert state.turbine.electrical_output_mw == 0.0
|
||||
assert state.total_electrical_output() == 0.0
|
||||
|
||||
|
||||
def test_state_save_and_load_roundtrip(tmp_path: Path):
|
||||
@@ -36,7 +37,18 @@ def test_health_monitor_flags_core_failure():
|
||||
reactor = Reactor.default()
|
||||
state = reactor.initial_state()
|
||||
state.core.fuel_temperature = constants.MAX_CORE_TEMPERATURE
|
||||
failures = reactor.health_monitor.evaluate(state, True, True, True, dt=200.0)
|
||||
failures = reactor.health_monitor.evaluate(state, True, True, [True, True, True], dt=200.0)
|
||||
assert "core" in failures
|
||||
reactor._handle_failure("core")
|
||||
assert reactor.shutdown is True
|
||||
|
||||
|
||||
def test_maintenance_recovers_component_health():
|
||||
monitor = HealthMonitor()
|
||||
pump = monitor.component("secondary_pump")
|
||||
pump.integrity = 0.3
|
||||
pump.fail()
|
||||
restored = monitor.maintain("secondary_pump", amount=0.5)
|
||||
assert restored is True
|
||||
assert pump.integrity == pytest.approx(0.8)
|
||||
assert pump.failed is False
|
||||
|
||||
Reference in New Issue
Block a user