def test_error_finishes_game(team_errors, team_wins): # the mapping is as follows: # [(num_fatal_0, num_errors_0), (num_fatal_1, num_errors_1), result_flag] # the result flag: 0/1: team 0/1 wins, 2: draw, False: no winner yet (fatal_0, errors_0), (fatal_1, errors_1) = team_errors # just faking a bunch of errors in our game state state = { "error_limit": 5, "fatal_errors": [[None] * fatal_0, [None] * fatal_1], "errors": [[None] * errors_0, [None] * errors_1] } res = game.check_gameover(state) if team_wins is False: assert res["whowins"] is None assert res["gameover"] is False else: assert res["whowins"] == team_wins assert res["gameover"] is True
def test_last_round_check(): # (max_rounds, current_round, turn): gameover test_map = { (1, None, None): False, (1, 1, 0): False, (1, 1, 3): True, } for test_val, test_res in test_map.items(): max_rounds, current_round, current_turn = test_val state = { 'max_rounds': max_rounds, 'round': current_round, 'turn': current_turn, 'fatal_errors': [[],[]], 'errors': [[],[]], 'gameover': False, 'score': [0, 0], 'food': [{(1,1)}, {(1,1)}] # dummy food } res = game.check_gameover(state, detect_final_move=True) assert res['gameover'] == test_res