Ejemplo n.º 1
0
 def test_ai_game(self):
     # set Options
     ttt.Options.o_is_computer = True
     ttt.Options.x_is_computer = True
     ttt.Options.load_previous_game = 'No'
     ttt.Options.plot_best_moves = True
     ttt.Options.plot_move_power = True
     # instantiate GUI
     self.gui = ttt.TicTacToeGui()
     # confirm that the game completed
     self.assertEqual(self.gui.state.cur_move, 9)
Ejemplo n.º 2
0
    def test_ask_game_load(self):
        ttt.Options.o_is_computer = True
        ttt.Options.x_is_computer = True
        ttt.Options.load_previous_game = 'Ask'
        self.gui = ttt.TicTacToeGui()
        # TODO: move focus to new window
        self.gui.load_widget.setFocus()
        buttons = self.gui.load_widget.findChildren(QPushButton)
        print(buttons)
        # click on Yes button
        QTest.mouseClick(self.load_widget, QtCore.Qt.LeftButton, delay=1)

        self._place_piece(1, 1)
        self.assertTrue(self.gui.state.board[1, 1] != n)
Ejemplo n.º 3
0
from PyQt5.QtWidgets import QApplication

import dstauffman2.games.tictactoe as ttt

#%% Argument parsing
if len(sys.argv) > 1:
    mode = sys.argv[1]
else:
    mode = 'run'

#%% Execution
if mode == 'run':
    # Runs the GUI application
    qapp = QApplication(sys.argv)
    # instatiates the GUI
    gui = ttt.TicTacToeGui()
    gui.show()
    sys.exit(qapp.exec_())
elif mode == 'test':
    # open a qapp
    if QApplication.instance() is None:
        qapp = QApplication(sys.argv)
    else:
        qapp = QApplication.instance()
    # find the test cases
    test_suite = unittest.TestLoader().discover(
        'dstauffman2.games.tictactoe.tests')
    # run the tests
    unittest.TextTestRunner(verbosity=1).run(test_suite)
    # run the docstrings
    verbose = False
Ejemplo n.º 4
0
 def test_sequence(self):
     # set Options
     ttt.Options.o_is_computer = False
     ttt.Options.x_is_computer = False
     ttt.Options.load_previous_game = 'No'
     # instantiate GUI
     self.gui = ttt.TicTacToeGui()
     # copy the state for reference
     self.state = copy.deepcopy(self.gui.state)
     # establish defaults
     self._default()
     new_board = self.state.board.copy()
     # place piece 1
     self._place_piece(0, 0)
     new_board[0, 0] = o
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 1)
     self.assertEqual(self.gui.state.cur_game, 0)
     # place piece 2
     self._place_piece(1, 0)
     new_board[1, 0] = x
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 2)
     # undo second move
     QTest.mouseClick(self.gui.btn_undo, QtCore.Qt.LeftButton, delay=1)
     new_board[1, 0] = n
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 1)
     # undo first move
     QTest.mouseClick(self.gui.btn_undo, QtCore.Qt.LeftButton, delay=1)
     new_board[0, 0] = n
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 0)
     # redo first move
     QTest.mouseClick(self.gui.btn_redo, QtCore.Qt.LeftButton, delay=1)
     new_board[0, 0] = o
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 1)
     # redo second move
     QTest.mouseClick(self.gui.btn_redo, QtCore.Qt.LeftButton, delay=1)
     new_board[1, 0] = x
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 2)
     # complete game
     self._place_piece(0, 1)
     new_board[0, 1] = o
     self._place_piece(1, 1)
     new_board[1, 1] = x
     self._place_piece(0, 2)
     new_board[0, 2] = o
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 5)
     # make extra click
     self._place_piece(2, 2)
     np.testing.assert_array_equal(self.gui.state.board, new_board)
     self.assertEqual(self.gui.state.cur_move, 5)
     # start new game
     QTest.mouseClick(self.gui.btn_new, QtCore.Qt.LeftButton, delay=1)
     new_board = self.state.board.copy()
     self.assertEqual(self.gui.state.cur_move, 0)
     self.assertEqual(self.gui.state.cur_game, 1)
     # place one piece
     self._place_piece(1, 2)
     new_board[1, 2] = x
     self.assertEqual(self.gui.state.cur_move, 1)
     # click on existing piece
     self._place_piece(1, 2)
     self.assertEqual(self.gui.state.cur_move, 1)
     # click off the board
     self._place_piece(-1, 2)
     self.assertEqual(self.gui.state.cur_move, 1)
Ejemplo n.º 5
0
 def test_ask_bad_option(self):
     ttt.Options.load_previous_game = 'Bad Option'
     with self.assertRaises(ValueError):
         self.gui = ttt.TicTacToeGui()
Ejemplo n.º 6
0
 def test_load_game(self):
     ttt.Options.o_is_computer = True
     ttt.Options.x_is_computer = True
     ttt.Options.load_previous_game = 'Yes'
     self.gui = ttt.TicTacToeGui()