Ejemplo n.º 1
0
    def test_evaluate_guess_0_0(self):
        """Test no matches at all."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'Gmcw'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(0, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 2
0
    def test_evaluate_double_color_guess(self):
        """Test that a double color in the guess only counts once."""
        guess = Guess('rbwr')
        mm = MasterMind(8)
        mm.secret = 'grgy'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(1, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 3
0
    def test_evaluate_guess_4_0(self):
        """Test 4 matches in wrong spots."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'gbyr'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(4, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 4
0
    def test_evaluate_double_color_guess(self):
        """Test that a double color in the guess only counts once."""
        guess = Guess('rbwr')
        mm = MasterMind(8)
        mm.secret = 'grgy'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(1, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 5
0
    def test_evaluate_guess_4_0(self):
        """Test 4 matches in wrong spots."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'gbyr'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(4, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 6
0
    def test_evaluate_guess_0_0(self):
        """Test no matches at all."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'Gmcw'
        mm.guesses.append(guess)

        mm.evaluate_guess()

        self.assertEqual(0, mm.guesses[0].black)
        self.assertEqual(0, mm.guesses[0].white)
Ejemplo n.º 7
0
    def test_evaluate_guess_win(self):
        """Test 4 matches in wrong spots."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'rgby'
        mm.guesses.append(guess)
        mm.display_game_over = MagicMock()

        mm.evaluate_guess()

        self.assertTrue(mm.game_over)
        self.assertTrue(mm.winner)
Ejemplo n.º 8
0
    def test_evaluate_guess_win(self):
        """Test 4 matches in wrong spots."""
        guess = Guess('rgby')
        mm = MasterMind(8)
        mm.secret = 'rgby'
        mm.guesses.append(guess)
        mm.display_game_over = MagicMock()

        mm.evaluate_guess()

        self.assertTrue(mm.game_over)
        self.assertTrue(mm.winner)
Ejemplo n.º 9
0
    def test_display_game(self, mock_print):
        """Test that the output of display game matches history."""
        mm = MasterMind(8)
        mm.secret = 'ywwr'
        guess_1 = Guess('rbwr')
        mm.guesses.append(guess_1)
        mm.evaluate_guess()
        guess_2 = Guess('wwrr')
        mm.guesses.append(guess_2)
        mm.evaluate_guess()
        guess_3 = Guess('ywrr')
        mm.guesses.append(guess_3)
        mm.evaluate_guess()

        mm.display_game()

        self.assertEqual(5, mock_print.call_count)
        expected = [
            call('------------------------'),
            call(guess_1),
            call(guess_2),
            call(guess_3),
            call('------------------------'),
        ]
        mock_print.assert_has_calls(expected)
Ejemplo n.º 10
0
    def test_play_game_over(self):
        """Test that the game ends  when game_over is False."""
        mm = MasterMind(3)
        mm.display_game = MagicMock()
        mm.get_next_guess = MagicMock()
        mm.evaluate_guess = MagicMock()
        mm.update_points = MagicMock()
        mm.game_over = True

        mm.play()

        self.assertEqual(0, mm.display_game.call_count)
        self.assertEqual(0, mm.get_next_guess.call_count)
        self.assertEqual(0, mm.evaluate_guess.call_count)
        self.assertEqual(0, mm.update_points.call_count)
Ejemplo n.º 11
0
    def test_play_game_over(self):
        """Test that the game ends  when game_over is False."""
        mm = MasterMind(3)
        mm.display_game = MagicMock()
        mm.get_next_guess = MagicMock()
        mm.evaluate_guess = MagicMock()
        mm.update_points = MagicMock()
        mm.game_over = True

        mm.play()

        self.assertEqual(0, mm.display_game.call_count)
        self.assertEqual(0, mm.get_next_guess.call_count)
        self.assertEqual(0, mm.evaluate_guess.call_count)
        self.assertEqual(0, mm.update_points.call_count)
Ejemplo n.º 12
0
    def test_play(self):
        """Test that the  game continues when game_over is False."""
        mm = MasterMind(3)
        mm.display_game = MagicMock()
        mm.get_next_guess = MagicMock()
        mm.evaluate_guess = MagicMock()
        mm.update_points = MagicMock()
        mm.game_over = False

        def side_effect():
            mm.game_over = True
        mm.evaluate_guess.side_effect = side_effect

        mm.play()

        self.assertEqual(1, mm.display_game.call_count)
        self.assertEqual(1, mm.get_next_guess.call_count)
        self.assertEqual(1, mm.evaluate_guess.call_count)
        self.assertEqual(1, mm.update_points.call_count)
Ejemplo n.º 13
0
    def test_play(self):
        """Test that the  game continues when game_over is False."""
        mm = MasterMind(3)
        mm.display_game = MagicMock()
        mm.get_next_guess = MagicMock()
        mm.evaluate_guess = MagicMock()
        mm.update_points = MagicMock()
        mm.game_over = False

        def side_effect():
            mm.game_over = True

        mm.evaluate_guess.side_effect = side_effect

        mm.play()

        self.assertEqual(1, mm.display_game.call_count)
        self.assertEqual(1, mm.get_next_guess.call_count)
        self.assertEqual(1, mm.evaluate_guess.call_count)
        self.assertEqual(1, mm.update_points.call_count)
Ejemplo n.º 14
0
    def test_display_game(self, mock_print):
        """Test that the output of display game matches history."""
        mm = MasterMind(8)
        mm.secret = 'ywwr'
        guess_1 = Guess('rbwr')
        mm.guesses.append(guess_1)
        mm.evaluate_guess()
        guess_2 = Guess('wwrr')
        mm.guesses.append(guess_2)
        mm.evaluate_guess()
        guess_3 = Guess('ywrr')
        mm.guesses.append(guess_3)
        mm.evaluate_guess()

        mm.display_game()

        self.assertEqual(5, mock_print.call_count)
        expected = [call('------------------------'),
                    call(guess_1),
                    call(guess_2),
                    call(guess_3),
                    call('------------------------'),
                    ]
        mock_print.assert_has_calls(expected)