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]])
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)
def test_out_of_bounds(self): tt = TicTacToe() tt._init_board(3) self.assertFalse(tt._out_of_bounds((0, 2)))
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]])
def test_board_2x2(self): tt = TicTacToe() with self.assertRaises(ValueError, msg='Board size 2x2 is invalid.'): tt._init_board(2)
def test_board_neg(self): tt = TicTacToe() with self.assertRaises(ValueError, msg='Board size -1x-1 is invalid.'): tt._init_board(-1)
def test_out_of_bounds_upper(self): tt = TicTacToe() tt._init_board(3) self.assertTrue(tt._out_of_bounds((0, 3)))
def test_out_of_bounds_lower(self): tt = TicTacToe() tt._init_board(3) self.assertTrue(tt._out_of_bounds((-1, 0)))