diff --git a/tests/test_flatland_malfunction.py b/tests/test_flatland_malfunction.py index d1598d0d6c31974f74531c8ec7047a1382e1136e..278941b38537ad3a22b0210277baba2e3569e82c 100644 --- a/tests/test_flatland_malfunction.py +++ b/tests/test_flatland_malfunction.py @@ -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 diff --git a/tests/test_flatland_states_edge_cases.py b/tests/test_flatland_states_edge_cases.py index c0d5383880dc1df3c2e1e02eca6c535aa3de0c00..d1d22f26deeb6847e7d5f5690ddb471ebf441d48 100644 --- a/tests/test_flatland_states_edge_cases.py +++ b/tests/test_flatland_states_edge_cases.py @@ -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