Exemplo n.º 1
0
 def test_invalid_position_taken(self):
     with captured_output() as out:
         resp = self.game.validate_position_key("00")
     out = out.getvalue()
     self.assertFalse(resp)
     self.assertEqual(out,
                      "Invalid position key. Position already taken.\n\n")
Exemplo n.º 2
0
    def test_base_case(self):
        exp = "\nScoreboard:\nToothless: 3\nHiccup: 1\n"
        with captured_output() as out:
            self.game.show_scoreboard()

        resp = out.getvalue()
        self.assertEqual(resp, exp)
Exemplo n.º 3
0
    def test_key_not_digit(self):
        with captured_output() as out:
            resp = self.game.validate_position_key("a")

        out = out.getvalue()
        self.assertFalse(resp)
        self.assertEqual(out, "Invalid position key. Enter digits.\n\n")
Exemplo n.º 4
0
    def test_invalid_input(self):
        user_input = ["N", "Y"]
        exp = ["Invalid input"]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                resp = self.game.prompt_options()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))
        self.assertTrue(resp)
Exemplo n.º 5
0
    def test_valid_size_max(self):
        user_input = ["20", "4", 'Thor', 'Spiderman']
        exp = ["Tic-Tac-Toe", "Enter valid whole number."]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                self.game.main()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertTrue(self.start_game.called)
Exemplo n.º 6
0
    def test_tie_game(self):
        exp = ["No winners. Tie Game."]
        self.check_winning_board.return_value = False

        with captured_output() as out:
            self.game.start_game()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertEqual(self.turn.call_count, 9)
        self.assertEqual(self.check_winning_board.call_count, 9)
        self.assertTrue(self.reset_game.called)
Exemplo n.º 7
0
    def test_base_case(self):
        exp = ["Player: Toothless WON!"]
        self.check_winning_board.return_value = True

        with captured_output() as out:
            self.game.start_game()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertTrue(self.p1_add_win.called)
        self.assertFalse(self.p2_add_win.called)
        self.assertTrue(self.reset_game.called)
Exemplo n.º 8
0
    def test_exit(self):
        user_input = ["N"]
        exp = ["Game Over", "Thanks for playing!"]

        with patch('builtins.input', side_effect=user_input):
            with self.assertRaises(SystemExit):
                with captured_output() as out:
                    self.game.reset_game()

        resp = out.getvalue().split("\n")
        self.assertTrue(all(msg in resp for msg in exp))
        self.assertTrue(self.generate_board.called)
        self.assertFalse(self.show_scoreboard.called)
        self.assertFalse(self.start_game.called)
Exemplo n.º 9
0
    def test_invalid_token(self):
        user_input = ["|", '_', '*']
        exp = [
            "Invalid token. '|' or '_' not allowed.",
            "Invalid token. '|' or '_' not allowed."
        ]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                self.game.player1.change_token()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertEqual(self.game.player1.token, "*")
Exemplo n.º 10
0
    def test_base_case(self):
        user_input = ["Y"]
        exp = ["Game Over"]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                self.game.reset_game()

        resp = out.getvalue().split("\n")
        self.assertTrue(all(msg in resp for msg in exp))

        self.assertEqual(self.change_token.call_count, 2)
        self.assertTrue(self.generate_board.called)
        self.assertTrue(self.show_scoreboard.called)
        self.assertTrue(self.start_game.called)
Exemplo n.º 11
0
    def test_base_case(self):
        user_input = ["3", 'Thor', 'Spiderman']
        exp = ["Tic-Tac-Toe"]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                self.game.main()

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertEqual(self.game.board.size, 3)
        self.assertEqual(self.game.player1.name, "Thor")
        self.assertEqual(self.game.player2.name, "Spiderman")
        self.assertEqual(self.game.player1.token, "X")
        self.assertEqual(self.game.player2.token, "O")
        self.assertTrue(self.start_game.called)
Exemplo n.º 12
0
    def test_base_case(self):
        user_input = ["00"]
        exp = ["Thor's Turn"]

        with patch('builtins.input', side_effect=user_input):
            with captured_output() as out:
                location, position_key = self.game.turn(self.player)

        out = out.getvalue().split("\n")
        self.assertTrue(all(msg in out for msg in exp))

        self.assertTrue(self.generate_board.called)
        self.assertEqual(self.prompt_options.call_count, 1)
        self.assertEqual(self.validate_position_key.call_count, 2)
        self.add_position.called_with([0, 0], "X")
        self.assertEqual(location, "CORNER")
        self.assertEqual(position_key, [0, 0])
Exemplo n.º 13
0
 def test_invalid_out_of_range(self):
     with captured_output() as out:
         resp = self.game.validate_position_key("99")
     out = out.getvalue()
     self.assertFalse(resp)
     self.assertEqual(out, "Invalid position key. Out of range.\n\n")