-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOthello_unittest.py
62 lines (46 loc) · 1.88 KB
/
Othello_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import unittest
from Othello import Player, Board, Othello
class TestPlayer(unittest.TestCase):
def test_get_name(self):
player = Player("Alice", "black")
self.assertEqual(player.get_name(), "Alice")
def test_get_color(self):
player = Player("Bob", "white")
self.assertEqual(player.get_color(), "white")
class TestBoard(unittest.TestCase):
def test_update_board(self):
board = Board()
board.update_board("black", 4, 3)
game_board = board.get_board()
self.assertEqual(game_board[4][3], "X")
def test_piece_counts(self):
board = Board()
black_counts, white_counts = board.piece_counts()
self.assertEqual(black_counts, 2)
self.assertEqual(white_counts, 2)
class TestOthello(unittest.TestCase):
def test_create_player(self):
othello = Othello()
othello.create_player("Alice", "black")
self.assertEqual(len(othello._players), 1)
self.assertEqual(othello._players[0].get_name(), "Alice")
def test_return_available_positions(self):
othello = Othello()
othello.create_player("Alice", "black")
othello.create_player("Bob", "white")
available_pos = othello.return_available_positions("black")
self.assertEqual(len(available_pos), 4)
def test_make_move(self):
othello = Othello()
othello.create_player("Alice", "black")
othello.make_move("black", (4, 3))
game_board = othello._board.get_board()
self.assertEqual(game_board[4][3], "X")
def test_play_game(self):
othello = Othello()
othello.create_player("Alice", "black")
othello.create_player("Bob", "white")
result = othello.play_game("black", (4, 3))
self.assertIsNone(result)
if __name__ == '__main__':
unittest.main()