def test_ma_intersection_reward_sign():
    """
    If agent is simply moving forward without any steering, it will at least gain ~100 rewards, since we have a long
    straight road before coming into intersection.
    However, some bugs cause the vehicles receive negative reward by doing this behavior!
    """
    class TestEnv(MultiAgentIntersectionEnv):
        _respawn_count = 0

        @property
        def _safe_places(self):
            safe_places = []
            for c, bid in enumerate(self.engine.spawn_manager.safe_spawn_places.keys()):
                safe_places.append((bid, self.engine.spawn_manager.safe_spawn_places[bid]))
            return safe_places

    env = TestEnv({"num_agents": 1})
    np.random.seed(10)
    try:
        _check_spaces_before_reset(env)
        obs, _ = env.reset()
        _check_spaces_after_reset(env)
        ep_reward = 0.0
        for step in range(1000):
            act = {k: [0, 1] for k in env.agents.keys()}
            o, r, tm, tc, i = env.step(act)
            ep_reward += next(iter(r.values()))
            if any(tm.values()):
                # print("Finish respawn count: {}, reward {}".format(env._respawn_count, ep_reward))
                env._respawn_count += 1
                assert ep_reward > 10, ep_reward
                ep_reward = 0
            if env._respawn_count >= len(env._safe_places):
                break
            if tm["__all__"]:
                break
    finally:
        env.close()

    If agent is simply moving forward without any steering, it will at least gain ~100 rewards, since we have a long
    straight road before coming into intersection.
    However, some bugs cause the vehicles receive negative reward by doing this behavior!
    
metadrive/tests/test_env/test_ma_intersection.py