|
1 | 1 | import unittest
|
2 | 2 | import gocounting
|
3 | 3 |
|
| 4 | + |
4 | 5 | # Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
|
5 | 6 |
|
6 | 7 | board5x5 = "\n".join([
|
|
26 | 27 |
|
27 | 28 | class GoCountingTest(unittest.TestCase):
|
28 | 29 | def test_5x5_for_black(self):
|
29 |
| - board = gocounting.GoCounting(board5x5) |
| 30 | + board = gocounting.Board(board5x5) |
30 | 31 | stone, territory = board.territoryFor((0, 1))
|
31 |
| - self.assertEqual(stone, board.black) |
| 32 | + self.assertEqual(stone, gocounting.BLACK) |
32 | 33 | self.assertEqual(territory, set([(0, 0), (0, 1), (1, 0)]))
|
33 | 34 |
|
34 | 35 | def test_5x5_for_white(self):
|
35 |
| - board = gocounting.GoCounting(board5x5) |
| 36 | + board = gocounting.Board(board5x5) |
36 | 37 | stone, territory = board.territoryFor((2, 3))
|
37 |
| - self.assertEqual(stone, board.white) |
| 38 | + self.assertEqual(stone, gocounting.WHITE) |
38 | 39 | self.assertEqual(territory, set([(2, 3)]))
|
39 | 40 |
|
40 | 41 | def test_5x5_for_open_territory(self):
|
41 |
| - board = gocounting.GoCounting(board5x5) |
| 42 | + board = gocounting.Board(board5x5) |
42 | 43 | stone, territory = board.territoryFor((1, 4))
|
43 |
| - self.assertEqual(stone, board.none) |
| 44 | + self.assertEqual(stone, gocounting.NONE) |
44 | 45 | self.assertEqual(territory, set([(0, 3), (0, 4), (1, 4)]))
|
45 | 46 |
|
46 | 47 | def test_5x5_for_non_territory(self):
|
47 |
| - board = gocounting.GoCounting(board5x5) |
| 48 | + board = gocounting.Board(board5x5) |
48 | 49 | stone, territory = board.territoryFor((1, 1))
|
49 |
| - self.assertEqual(stone, board.none) |
| 50 | + self.assertEqual(stone, gocounting.NONE) |
50 | 51 | self.assertEqual(territory, set())
|
51 | 52 |
|
52 | 53 | def test_5x5_for_valid_coordinate(self):
|
53 |
| - board = gocounting.GoCounting(board5x5) |
| 54 | + board = gocounting.Board(board5x5) |
54 | 55 | stone, territory = board.territoryFor((-1, 1))
|
55 |
| - self.assertEqual(stone, board.none) |
| 56 | + self.assertEqual(stone, gocounting.NONE) |
56 | 57 | self.assertEqual(territory, set())
|
57 | 58 |
|
58 | 59 | def test_5x5_for_valid_coordinate2(self):
|
59 |
| - board = gocounting.GoCounting(board5x5) |
| 60 | + board = gocounting.Board(board5x5) |
60 | 61 | stone, territory = board.territoryFor((1, 5))
|
61 |
| - self.assertEqual(stone, board.none) |
| 62 | + self.assertEqual(stone, gocounting.NONE) |
62 | 63 | self.assertEqual(territory, set())
|
63 | 64 |
|
64 | 65 | def test_one_territory_whole_board(self):
|
65 |
| - board = gocounting.GoCounting(" ") |
| 66 | + board = gocounting.Board(" ") |
66 | 67 | territories = board.territories()
|
67 |
| - self.assertEqual(territories[board.black], set()) |
68 |
| - self.assertEqual(territories[board.white], set()) |
69 |
| - self.assertEqual(territories[board.none], set([(0, 0)])) |
| 68 | + self.assertEqual(territories[gocounting.BLACK], set()) |
| 69 | + self.assertEqual(territories[gocounting.WHITE], set()) |
| 70 | + self.assertEqual(territories[gocounting.NONE], set([(0, 0)])) |
70 | 71 |
|
71 | 72 | def test_two_territories_rectangular_board(self):
|
72 | 73 | input_board = "\n".join([
|
73 | 74 | " BW ",
|
74 | 75 | " BW "
|
75 | 76 | ])
|
76 |
| - board = gocounting.GoCounting(input_board) |
| 77 | + board = gocounting.Board(input_board) |
77 | 78 | territories = board.territories()
|
78 |
| - self.assertEqual(territories[board.black], set([(0, 0), (0, 1)])) |
79 |
| - self.assertEqual(territories[board.white], set([(3, 0), (3, 1)])) |
80 |
| - self.assertEqual(territories[board.none], set()) |
| 79 | + self.assertEqual(territories[gocounting.BLACK], set([(0, 0), (0, 1)])) |
| 80 | + self.assertEqual(territories[gocounting.WHITE], set([(3, 0), (3, 1)])) |
| 81 | + self.assertEqual(territories[gocounting.NONE], set()) |
81 | 82 |
|
82 | 83 | def test_9x9_for_open_territory(self):
|
83 |
| - board = gocounting.GoCounting(board9x9) |
| 84 | + board = gocounting.Board(board9x9) |
84 | 85 | stone, territory = board.territoryFor((0, 8))
|
85 |
| - self.assertEqual(stone, board.none) |
| 86 | + self.assertEqual(stone, gocounting.NONE) |
86 | 87 | self.assertEqual(territory,
|
87 | 88 | set([(2, 7), (2, 8), (1, 8), (0, 8), (0, 7)]))
|
88 | 89 |
|
|
0 commit comments