Commit 9cd3c863 authored by Dipam Chakraborty's avatar Dipam Chakraborty
Browse files

add test for malfunction phase through

parent 5f80e96d
Pipeline #8787 failed with stages
in 7 minutes and 52 seconds
......@@ -119,7 +119,7 @@ def test_malfunction_process():
total_down_time += env.agents[0].malfunction_handler.malfunction_down_counter
# Check that the appropriate number of malfunctions is achieved
# Dipam: The number of malfunctions varies by seed
assert env.agents[0].malfunction_handler.num_malfunctions == 46, "Actual {}".format(
assert env.agents[0].malfunction_handler.num_malfunctions == 28, "Actual {}".format(
env.agents[0].malfunction_handler.num_malfunctions)
# Check that malfunctioning data was standing around
......
......@@ -80,4 +80,36 @@ def test_ready_to_depart_to_stopped():
env.step({0: RailEnvActions.STOP_MOVING})
assert env.agents[0].state == TrainState.STOPPED
\ No newline at end of file
assert env.agents[0].state == TrainState.STOPPED
def test_malfunction_no_phase_through():
"""
A moving train shouldn't phase through a malfunctioning train
"""
stochastic_data = MalfunctionParameters(malfunction_rate=0, # Rate of malfunction occurence
min_duration=0, # Minimal duration of malfunction
max_duration=0 # Max duration of malfunction
)
rail, _, optionals = make_simple_rail()
env = RailEnv(width=25,
height=30,
rail_generator=rail_from_grid_transition_map(rail, optionals),
line_generator=sparse_line_generator(seed=10),
number_of_agents=2,
malfunction_generator_and_process_data=malfunction_from_params(stochastic_data),
)
env.reset(False, False, random_seed=10)
for _ in range(5):
env.step({0: RailEnvActions.MOVE_FORWARD, 1: RailEnvActions.MOVE_FORWARD})
env.agents[1].malfunction_handler._set_malfunction_down_counter(10)
for _ in range(3):
env.step({0: RailEnvActions.MOVE_FORWARD, 1: RailEnvActions.DO_NOTHING})
assert env.agents[0].state == TrainState.STOPPED
assert env.agents[0].position == (3, 5)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment