def perform_test(self, status_pair): """Test simulate by comparing simulated status""" dict_before, dict_after = status_pair # Build models map_obj = Map(dict_before["game"]["board"]["tiles"]) status_before = Status(dict_before["game"], map_obj) status_after = Status(dict_after["game"], map_obj) # Get actions actions_by_hero = [status_after.heroes[i].last_dir for i in range(4)] first_hero = status_before.current_hero() # Shift actions such that first_hero is the first to move actions = actions_by_hero[first_hero:] + actions_by_hero[:first_hero] # Run simulations simulated = simulate_actions(status_before, actions) # Compare self.assertEqual( status_after, simulated, msg=( "Before:\n{before}\n" + "Actions: {actions}\n" + "After:\n{after}\n" + "Simulated:\n{sim}\n" + "Round: {b_id} {b_turn} --> {a_id} {a_turn}" ).format( before=status_before, actions=actions, after=status_after, sim=simulated, b_id=status_before.id, b_turn=status_before.turn, a_id=status_after.id, a_turn=status_after.turn, ), )
class TestStatusRemainingTurnsOfHero(unittest.TestCase): def setUp(self): status_dict = get_status_samples_dict()["2nw864rp"][0] self.map = Map(status_dict["game"]["board"]["tiles"]) self.status = Status(status_dict["game"], self.map) def test_maxturns_2400(self): """Test when maxTurns=2400""" expected = [600, 600, 600, 600] # Check initial value for hero_id in range(4): self.assertEqual( self.status.remaining_turns_of_hero(hero_id), expected[hero_id], msg="Turn {t}, max_turns {m}, hero {h}".format( t=self.status.turn, m=self.status.max_turns, h=hero_id ) ) for turn in range(2400): # Similate a game turn expected[self.status.current_hero()] -= 1 self.status.turn += 1 # Check value for hero_id in range(4): self.assertEqual( self.status.remaining_turns_of_hero(hero_id), expected[hero_id], msg="Turn {t}, max_turns {m}, hero {h}".format( t=self.status.turn, m=self.status.max_turns, h=hero_id ) )