コード例 #1
0
 def test_board_5x5(self):
     tt = TicTacToe()
     tt._init_board(5)
     self.assertEqual(tt.size, 5)
     self.assertEqual(tt.board,
                      [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                       [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
コード例 #2
0
 def test_init(self):
     tt = TicTacToe()
     self.assertIsNone(tt.board)
     self.assertIsNone(tt.size)
     self.assertEqual(tt.turn, Player.X)
     self.assertFalse(tt.game_over)
     self.assertIsNone(tt.winner)
コード例 #3
0
 def test_display_new_game(self):
     tt = TicTacToe()
     tt._init_board(3)
     expected = "  |   |  \n" \
          "---------\n" \
          "  |   |  \n" \
          "---------\n" \
          "  |   |  \n"
     with patch('sys.stdout', new=StringIO()) as mock_out:
         tt._display_board()
         self.assertEqual(mock_out.getvalue(), expected)
コード例 #4
0
 def test_display_end_game(self):
     tt = TicTacToe()
     tt.size = 3
     tt.board = [[0, 1, 1], [2, 1, 2], [2, 2, 1]]
     expected = "  | X | X\n" \
          "---------\n" \
          "O | X | O\n" \
          "---------\n" \
          "O | O | X\n"
     with patch('sys.stdout', new=StringIO()) as mock_out:
         tt._display_board()
         self.assertEqual(mock_out.getvalue(), expected)
コード例 #5
0
 def test_out_of_bounds(self):
     tt = TicTacToe()
     tt._init_board(3)
     self.assertFalse(tt._out_of_bounds((0, 2)))
コード例 #6
0
 def test_space_o(self):
     tt = TicTacToe()
     self.assertEqual(tt._space_to_ascii(2), 'O')
コード例 #7
0
 def test_space_x(self):
     tt = TicTacToe()
     self.assertEqual(tt._space_to_ascii(1), 'X')
コード例 #8
0
 def test_space(self):
     tt = TicTacToe()
     self.assertEqual(tt._space_to_ascii(0), ' ')
コード例 #9
0
 def test_board_3x3(self):
     tt = TicTacToe()
     tt._init_board(3)
     self.assertEqual(tt.size, 3)
     self.assertEqual(tt.board, [[0, 0, 0], [0, 0, 0], [0, 0, 0]])
コード例 #10
0
 def test_board_2x2(self):
     tt = TicTacToe()
     with self.assertRaises(ValueError, msg='Board size 2x2 is invalid.'):
         tt._init_board(2)
コード例 #11
0
 def test_board_neg(self):
     tt = TicTacToe()
     with self.assertRaises(ValueError, msg='Board size -1x-1 is invalid.'):
         tt._init_board(-1)
コード例 #12
0
 def test_out_of_bounds_upper(self):
     tt = TicTacToe()
     tt._init_board(3)
     self.assertTrue(tt._out_of_bounds((0, 3)))
コード例 #13
0
 def test_out_of_bounds_lower(self):
     tt = TicTacToe()
     tt._init_board(3)
     self.assertTrue(tt._out_of_bounds((-1, 0)))