def test__constructor__shouldThrowException__whenLessThanOneItemProvided(self): # Arrange players = {anon_player(), anon_player(), anon_player()} items = set() locations = {anon_location(), anon_location(), anon_location()} # Act def action(): Game(players, items, locations) # Assert self.assertRaises(ValueError, action)
def test__constructor__shouldThrowException__whenNumTargetArgIsLessThanOne(self): # Arrange players = {anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act def action(): Game(players, items, locations, num_targets=0) # Assert self.assertRaises(ValueError, action)
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__constructor__shouldThrowException__whenNumTargetArgIsNotOne(self): # TODO GH 2018-Sep-15: Add functionality to support multiple targets and change this test to match new behaviour # Arrange players = {anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act def action(): Game(players, items, locations, num_targets=2) # Assert self.assertRaises(NotImplementedError, action)
def test__constructor__shouldThrowException__whenNumTargetsArgIsNotAnInt(self): # Arrange players = {anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act # noinspection PyTypeChecker def action(): Game(players, items, locations, num_targets=None) # Assert self.assertRaises(TypeError, action)
def test__constructor__shouldThrowException__whenItemsArgIsNotSetOfItems(self): # Arrange players = {anon_player(), anon_player(), anon_player()} invalid_items = {2, 3, 4} locations = {anon_location(), anon_location(), anon_location()} # Act # noinspection PyTypeChecker def action(): Game(players, invalid_items, locations) # Assert self.assertRaises(TypeError, action)
def test__constructor__shouldGenerateUniqueIdentifiers__whenGameInfoIsOtherwiseIdentical(self): # Arrange players = {anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act game1 = Game(players, items, locations) game2 = Game(players, items, locations) # Assert self.assertNotEqual(game1.id, game2.id)
def test__equals__shouldReturnFalse__whenGamesCreatedWithIdenticalOptions(self): # Arrange players = {anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} game1 = Game(players, items, locations) game2 = Game(players, items, locations) # Act actual = (game1 == game2) # Assert self.assertFalse(actual)
def test__constructor__shouldGenerateSingleCompleteLoopOfPlayerTargets__whenNumTargetsArgIsOne(self): # Arrange initial_player = anon_player() players = {initial_player, anon_player(), anon_player(), anon_player(), anon_player(), anon_player()} items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act game = Game(players, items, locations, num_targets=1) # Assert current_player = initial_player seen_players = set() for index in range(0, len(players)): next_player = game.get_target(current_player).player self.assertNotIn(next_player, seen_players) seen_players.add(next_player) current_player = next_player self.assertEqual(current_player, initial_player)
def test__constructor__shouldGenerateTargetsForEachPlayerFromProvidedOptions__whenGameJustCreated(self): # Arrange player1 = anon_player() player2 = anon_player() items = {anon_item(), anon_item(), anon_item()} locations = {anon_location(), anon_location(), anon_location()} # Act game = Game({player1, player2}, items, locations) # Assert player1_target = game.get_target(player1) player2_target = game.get_target(player2) self.assertEqual(player2, player1_target.player) self.assertEqual(player1, player2_target.player) self.assertIn(player1_target.item, items) self.assertIn(player2_target.item, items) self.assertIn(player2_target.location, locations) self.assertIn(player2_target.location, locations)
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__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__name__shouldRaiseException__whenAttemptingToSet(self): # Arrange location = anon_location() # Act # noinspection PyPropertyAccess def action(): location.name = anon_string() # Assert self.assertRaises(AttributeError, action)
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__mark_kill__shouldThrowException__whenGameIsNotStarted(self): # Arrange player1 = anon_player() player2 = anon_player() location = anon_location() item = anon_item() game = Game({player1, player2}, {item}, {location}) # Act def action(): game.mark_kill(player1, Target(player2, item, location)) # Assert self.assertRaises(IllegalActionError, 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__shouldRaiseException__whenPlayerIsNotInGame(self): # Arrange player1 = anon_player() player2 = anon_player() location = anon_location() item1 = anon_item() item2 = anon_item() game = Game({player1, player2}, {item1, item2}, {location}) target = game.get_target(player1) game.start() # Act def action(): game.mark_kill(anon_player(), target) # Assert self.assertRaises(ValueError, action)
def test__mark_kill__shouldRaiseException__whenTargetIsIncorrect(self): # Arrange player1 = anon_player() player2 = anon_player() location = anon_location() item1 = anon_item() item2 = anon_item() game = Game({player1, player2}, {item1, item2}, {location}) target = game.get_target(player1) other_item = item1 if target.item != item1 else item2 game.start() # Act def action(): game.mark_kill(player1, Target(player2, other_item, location)) # Assert self.assertRaises(ValueError, action)
def test__mark_kill__shouldNotModifyTarget__whenTargetIsCorrectButGameIsNotStarted(self): # Arrange player1 = anon_player() players = {player1, anon_player(), anon_player()} location = anon_location() item = anon_item() game = Game(players, {item}, {location}) p1_initial_target = game.get_target(player1) # Act try: game.mark_kill(player1, p1_initial_target) except IllegalActionError: pass # Assert p1_actual_target_player = game.get_target(player1).player self.assertEqual(p1_initial_target.player, p1_actual_target_player)
def action(): Target(None, anon_item(), anon_location()) # Assert self.assertRaises(TypeError, action)
def action(): Target(anon_player(), None, anon_location()) # Assert self.assertRaises(TypeError, action)
def action(): target.location = anon_location() # Assert self.assertRaises(AttributeError, action)
def action(): game.mark_kill(player, Target(player, anon_item(), anon_location())) # Assert self.assertRaises(ValueError, action)