def test_rejects_incorrect_number(self) -> None: for number in [-1, 0, 97]: with self.assertRaises( AssertionError, msg="Should only accept numbers in range 1...96"): by_booklet_entry("alpha", number)
def test_rejects_incorrect_alphabet(self) -> None: with self.assertRaises( AssertionError, msg= "Should only accept alphabets in ['alpha', 'beta', 'gamma', 'delta', 'epsilon']" ): by_booklet_entry("A", 2)
def test_accepts_proper_alphabets(self) -> None: alphabets = ["alpha", "beta", "gamma", "delta", "epsilon"] for alpha in alphabets: try: by_booklet_entry(alpha, 2) except Exception: self.fail("Proper alphabet {} was not accepted".format(alpha))
def test_accepts_proper_number_as_argument(self) -> None: for number in range(1, 97, 1): try: by_booklet_entry("alpha", number) except Exception as e: if (type(e).__name__ == "AssertionError") and ("Number should in range" in e): self.fail( "Proper number {} was not accepted".format(number))
def setUp(self) -> None: # Redefine for every test as state persists otherwise PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] self.game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES)
def setUp(self) -> None: PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] self.game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES)
def test_known_clues_return_a_single_tile(self) -> None: PLAYER_1 = Player("red", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("orange", clues.by_booklet_entry("beta", 79), teamname="beta") PLAYER_3 = Player("purple", clues.by_booklet_entry("epsilon", 28), teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) possible_tiles = game.possible_tiles() self.assertTrue( len(possible_tiles) == 1, msg= "Should always return a single maptile when, all clues are known")
def test_cougar_clue_accepts_tile_next_to_cougar_zone(self) -> None: # Encountered during manual testing PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) self.assertIn(game.map[1, 1], clues.TWO_FROM_COUGAR.accepted_tiles(game.map), msg="2 from cougar should accept tile next to cougar zone")
def test_accepted_tiles_maintains_hash(self) -> None: a = Clue(1, set(["bear", "cougar"]), clue_type="animal") b = Clue(1, set(["bear", "cougar"]), clue_type="animal") self.assertEqual(hash(a), hash(b), msg="Fresh clues with same parameters should be comparable") PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = b.accepted_tiles(game.map) self.assertEqual(hash(a), hash(b), msg="Invoking class methods should not change the hash of a clue")
def test_accepted_tiles_comparison(self) -> None: a = Clue(1, set(["bear", "cougar"]), clue_type="animal") b = Clue(1, set(["bear", "cougar"]), clue_type="animal") self.assertEqual(a, b, msg="Instances of same clue should evaluate to be equal") PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = b.accepted_tiles(game.map) self.assertEqual(a, b, msg="Invoking class methods should not change equality comparison of Clue instance")
def test_repeated_calls_are_cached(self) -> None: two_from_cougar = deepcopy(clues.TWO_FROM_COUGAR) PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = two_from_cougar.accepted_tiles(game.map) before_call = two_from_cougar.accepted_tiles.cache_info() _ = two_from_cougar.accepted_tiles(game.map) after_call = two_from_cougar.accepted_tiles.cache_info() self.assertEqual(after_call[0], before_call[0] + 1, msg="Number of cache hits should increase when called with same parameters")
def parse_player(stringified: str) -> Player: alphabet_lookup = { "a": "alpha", "b": "beta", "g": "gamma", "d": "delta", "e": "epsilon" } if stringified.startswith("@"): acting_player = True stringified = stringified[1:] else: acting_player = False color, booklet = stringified.split("_") (booklet_alpha, booklet_num) = (alphabet_lookup[booklet[0].lower()], int(booklet[1:])) if acting_player: return Player(color, by_booklet_entry(booklet_alpha, booklet_num)) else: return Player(color, clue=None)
def test_fails_on_inverted_clues(self) -> None: with self.assertRaises(NotImplementedError, msg="Should fail on inverted clues"): # Epsilon 4 is clue: 'not_forest/mountain' by_booklet_entry("epsilon", 4)