Beispiel #1
0
    def test_play_game(self):

        #Create some players with a mock Play method
        player_1 = Player('test1')
        player_1.play = MagicMock(side_effect=['', '', '', True])

        player_2 = Player('test2')
        player_2.play = MagicMock(side_effect=['', '', '', ''])

        player_3 = Player('test3')
        player_3.play = MagicMock(side_effect=['', '', '', ''])

        # Test that play continues until a player returns True

        game.play([player_1, player_2, player_3])
Beispiel #2
0
    def test_play_game_roll_roll_pass(self):

        #3. player rolls 2-6 on first roll. does not accumulate enough points to win. player rolls again 2-6. Player elects to end turn. Score should increase, not winner

        test_player = Player('test')
        test_player.score = 10
        test_player.roll_dice = MagicMock(side_effect=[4, 3])
        test_player.user_roll_again = MagicMock(side_effect=[True, False])

        won = test_player.play()
        self.assertIsNone(won)

        self.assertFalse(test_player.winner)
        self.assertEqual(17, test_player.score)
Beispiel #3
0
    def test_play_game_lose(self):

        # 1. player rolls a 1 on first roll, turn ends . Score should stay same, not winner

        test_player = Player('test')

        test_player.score = 10
        test_player.roll_dice = MagicMock(return_value=1)

        won = test_player.play()
        self.assertIsNone(won)

        self.assertFalse(test_player.winner)
        self.assertEqual(10, test_player.score)
Beispiel #4
0
    def test_play_game_roll_win(self):

        # 6. player rolls 2-6 on first roll and accumulates enough points to win. Score should increase, user is winner

        test_player = Player('test')
        test_player.score = 99

        test_player.roll_dice = MagicMock(return_value=4)

        won = test_player.play()
        self.assertTrue(won)

        self.assertTrue(test_player.winner)
        self.assertEqual(103, test_player.score)
Beispiel #5
0
    def test_play_game_roll_lose(self):

        # 5. player rolls 2-6 on first roll. does not accumulate enough points to win. player rolls again 1. Score should stay the same, not winner

        test_player = Player('test')
        test_player.score = 10
        rolls = [4, 1]
        user_says = [True]
        test_player.roll_dice = MagicMock(side_effect=rolls)
        test_player.user_roll_again = MagicMock(side_effect=user_says)

        won = test_player.play()
        self.assertIsNone(won)

        self.assertFalse(test_player.winner)
        self.assertEqual(10, test_player.score)
Beispiel #6
0
    def test_play_game_roll_many(self):

        # 4. player rolls 2-6 on first roll. does not accumulate enough points to win. player rolls again 2-6. Player repeats several times, each time 2-6. Player elects to end turn. Score should increase, not winner

        test_player = Player('test')
        test_player.score = 10
        rolls = [4, 3, 6, 2, 3, 6, 5, 2]
        user_says = [True, True, True, True, True, True, True, False]
        test_player.roll_dice = MagicMock(side_effect=rolls)
        test_player.user_roll_again = MagicMock(side_effect=user_says)

        won = test_player.play()
        self.assertIsNone(won)

        self.assertFalse(test_player.winner)
        self.assertEqual(10 + sum(rolls), test_player.score)
Beispiel #7
0
    def test_play_game_roll_roll_win(self):

        # 7. player rolls 2-6 on first roll. does not accumulate enough points to win. player rolls again 2-6, accumulates enough points to win. Score should increase, user is winner

        test_player = Player('test')
        test_player.score = 91
        rolls = [6, 5]
        user_says = [True]
        test_player.roll_dice = MagicMock(side_effect=rolls)
        test_player.user_roll_again = MagicMock(side_effect=user_says)

        won = test_player.play()
        self.assertTrue(won)

        self.assertTrue(test_player.winner)
        self.assertEqual(102, test_player.score)