示例#1
0
    def test__hash__shouldReturnDifferentValues__whenItemArgumentIsDifferent(self):
        player = anon_player()
        location = anon_location()
        target_a = Target(player, anon_item(), location)
        target_b = Target(player, anon_item(), location)

        # Act
        actual = hash(target_a) == hash(target_b)

        # Assert
        self.assertFalse(actual)
示例#2
0
    def test__constructor__shouldThrowException__whenLessThanOneLocationProvided(self):
        # Arrange
        players = {anon_player(), anon_player(), anon_player()}
        items = {anon_item(), anon_item(), anon_item()}
        locations = set()

        # Act
        def action(): Game(players, items, locations)

        # Assert
        self.assertRaises(ValueError, action)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    def test__constructor__shouldThrowException__whenLocationsArgIsNotSetOfLocations(self):
        # Arrange
        players = {anon_player(), anon_player(), anon_player()}
        items = {anon_item(), anon_item(), anon_item()}
        invalid_locations = {2, 3, 4}

        # Act
        # noinspection PyTypeChecker
        def action(): Game(players, items, invalid_locations)

        # Assert
        self.assertRaises(TypeError, action)
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
    def test__delete__shouldThrowException__whenRepositoryContainsItemsButNotTheDeletedOne(
            self):

        # Arrange
        self._item_repo.save(anon_item())
        self._item_repo.save(anon_item())

        # Act
        def action():
            self._item_repo.delete(anon_item())

        # Assert
        self.assertRaises(KeyError, action)
示例#10
0
    def test__save__shouldNotThrowException__whenProvidedValidItemArg(self):

        # Arrange
        item = anon_item()

        # Act
        self._item_repo.save(item)
示例#11
0
    def test__retrieve_all__shouldReturnAllSavedItems__whenMultipleItemsStored(
            self):

        # Arrange
        item1 = anon_item()
        item2 = anon_item()
        item3 = anon_item()
        self._item_repo.save(item1)
        self._item_repo.save(item2)
        self._item_repo.save(item3)

        # Act
        items = self._item_repo.retrieve_all()

        # Assert
        self.assertEqual({item1, item2, item3}, items)
示例#12
0
    def test__save__shouldNotThrowException__whenItemAlreadyExistsInRepo(self):
        # Arrange
        item = anon_item()
        self._item_repo.save(item)

        # Act
        self._item_repo.save(item)
示例#13
0
    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)
示例#14
0
    def test__delete__shouldRemoveItem__whenItemExistsInRepository(self):

        # Arrange
        item = anon_item()
        expected_item1 = anon_item()
        expected_item2 = anon_item()
        self._item_repo.save(expected_item1)
        self._item_repo.save(expected_item2)
        self._item_repo.save(item)

        # Act
        self._item_repo.delete(item)

        # Assert
        items = self._item_repo.retrieve_all()
        self.assertEqual({expected_item1, expected_item2}, items)
示例#15
0
    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)
示例#16
0
    def test__delete__shouldNotModifyEntries__whenDeleteCalledWithItemNotInRepo(
            self):

        # Arrange
        item1 = anon_item()
        item2 = anon_item()
        self._item_repo.save(item1)
        self._item_repo.save(item2)

        # Act
        try:
            self._item_repo.delete(anon_item())
        except KeyError:
            pass

        # Assert
        items = self._item_repo.retrieve_all()
        self.assertEqual({item1, item2}, items)
示例#17
0
    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)
示例#18
0
    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)
示例#19
0
    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)
示例#20
0
    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)
示例#21
0
    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)
示例#22
0
    def test__name__shouldRaiseException__whenAttemptingToSet(self):
        # Arrange
        item = anon_item()

        # Act
        # noinspection PyPropertyAccess
        def action():
            item.name = anon_string()

        # Assert
        self.assertRaises(AttributeError, action)
示例#23
0
    def test__retrieve_all__shouldReturnSavedItem__whenOnlyOneItemStored(self):

        # Arrange
        expected_item = anon_item()
        self._item_repo.save(expected_item)

        # Act
        items = list(self._item_repo.retrieve_all())

        # Assert
        self.assertEqual(1, len(items))
        self.assertEqual(expected_item, items[0])
示例#24
0
    def test__save__shouldNotSaveDuplicateItem__whenItemAlreadyExistsInRepo(
            self):
        # Arrange
        item = anon_item()
        self._item_repo.save(item)

        # Act
        self._item_repo.save(item)

        # Assert
        items = self._item_repo.retrieve_all()
        self.assertEqual(1, len(items))
示例#25
0
    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)
示例#26
0
    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)
示例#27
0
    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)
示例#28
0
    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)
示例#29
0
    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)
示例#30
0
        def action(): game.mark_kill(player, Target(player, anon_item(), anon_location()))

        # Assert
        self.assertRaises(ValueError, action)