def test__hash__shouldReturnDifferentValues__whenLocationArgumentIsDifferent(self): player = anon_player() item = anon_item() target_a = Target(player, item, anon_location()) target_b = Target(player, item, anon_location()) # Act actual = hash(target_a) == hash(target_b) # Assert self.assertFalse(actual)
def test__hash__shouldReturnDifferentValues__whenPlayerArgumentIsDifferent(self): item = anon_item() location = anon_location() target_a = Target(anon_player(), item, location) target_b = Target(anon_player(), item, location) # Act actual = hash(target_a) == hash(target_b) # Assert self.assertFalse(actual)
def test__hash__shouldReturnSameValue__whenConstructionIsIdentical(self): player = anon_player() item = anon_item() location = anon_location() target_a = Target(player, item, location) target_b = Target(player, item, location) # Act actual = hash(target_a) == hash(target_b) # Assert self.assertTrue(actual)
def test__equals__shouldReturnTrue__whenConstructionIsIdentical(self): # Arrange player = anon_player() item = anon_item() location = anon_location() target_a = Target(player, item, location) target_b = Target(player, item, location) # Act actual = (target_a == target_b) # Assert self.assertTrue(actual)
def test__location__shouldReturnLocation__whenAccessing(self): # Arrange expected_location = anon_location() target = Target(anon_player(), anon_item(), expected_location) # Act actual = target.location # Assert self.assertEquals(expected_location, actual)
def test__item__shouldReturnItem__whenAccessing(self): # Arrange expected_item = anon_item() target = Target(anon_player(), expected_item, anon_location()) # Act actual = target.item # Assert self.assertEquals(expected_item, actual)
def test__player__shouldReturnPlayer__whenAccessing(self): # Arrange expected_player = anon_player() target = Target(expected_player, anon_item(), anon_location()) # Act actual = target.player # Assert self.assertEquals(expected_player, actual)
def test__mark_kill__shouldThrowException__whenTargetPlayerNotInGameAndGameStarted(self): # Arrange player = anon_player() game = anon_game(players={player, anon_player()}) valid_target = game.get_target(player) invalid_target = Target(anon_player(), valid_target.item, valid_target.location) game.start() # Act def action(): game.mark_kill(player, invalid_target) # Assert self.assertRaises(ValueError, action)
def test__get_score__shouldReturnOne__whenPlayerSuccessfullyKillsTarget(self): # Arrange first_player = anon_player() target_player = anon_player() target_item = anon_item() target_location = anon_location() game = Game({first_player, target_player}, {target_item}, {target_location}) game.start() game.mark_kill(first_player, Target(target_player, target_item, target_location)) # Act actual = game.get_score(first_player) # Assert self.assertEqual(1, actual)
def test__mark_kill__shouldNotModifyTarget__whenTargetIsIncorrectAndGameIsNotStarted(self): # Arrange player1 = anon_player() player2 = anon_player() player3 = anon_player() game = anon_game(players={player1, player2, player3}) target = game.get_target(player1) invalid_target = Target(player2 if target.player != player2 else player3, target.item, target.location) # Act try: game.mark_kill(player1, invalid_target) except IllegalActionError: pass # Assert p1_actual_target = game.get_target(player1) self.assertEqual(target, p1_actual_target)
def __init__(self, players: Set[Player], items: Set[Item], locations: Set[Location], num_targets: int = 1) -> None: # Type Checking if not isinstance(players, set) or any(not isinstance(player, Player) for player in players): raise TypeError("The 'players' argument must be a set of Player objects") elif not isinstance(items, set) or any(not isinstance(item, Item) for item in items): raise TypeError("The 'items' argument must be a set of Item objects") elif not isinstance(locations, set) or any(not isinstance(location, Location) for location in locations): raise TypeError("The 'locations' argument must be a set of Location objects") elif not isinstance(num_targets, int): raise TypeError("The 'num_targets' argument must be an int") if len(players) < 2: raise ValueError("A game cannot be constructed with fewer than 2 players") elif len(items) < 1: raise ValueError("A game cannot be constructed with fewer than 1 items") elif len(locations) < 1: raise ValueError("A game cannot be constructed with fewer than 1 locations") elif num_targets < 1: raise ValueError("A game cannot be constructed with fewer than 1 target per player") # TODO GH 2018-Sep-15: Add functionality to support multiple targets and remove this when done if num_targets != 1: raise NotImplementedError("The multiple-target game feature is not yet supported") # Game Initialization Logic self.__status = GameState.CREATED self.__id = uuid4() self.__scores = dict() self.__targets = dict() self.__players = players players = list(players) shuffle(players) for index, player in enumerate(players): self.__scores[player] = 0 self.__targets[player] = Target(players[(index + 1) % len(players)], sample(items, 1)[0], sample(locations, 1)[0])
def action(): Target(None, anon_item(), anon_location()) # Assert self.assertRaises(TypeError, action)
def action(): game.mark_kill(player1, Target(player2, other_item, location)) # Assert self.assertRaises(ValueError, action)
def action(): game.mark_kill(player1, Target(player2, item, location)) # Assert self.assertRaises(IllegalActionError, action)
def action(): game.mark_kill(player, Target(player, anon_item(), anon_location())) # Assert self.assertRaises(ValueError, action)
def action(): Target(anon_player(), None, anon_location()) # Assert self.assertRaises(TypeError, action)
def action(): Target(anon_player(), anon_item(), None) # Assert self.assertRaises(TypeError, action)
def anon_target() -> Target: return Target(anon_player(), anon_item(), anon_location())