-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgo_counting_test.py
87 lines (73 loc) · 3.65 KB
/
go_counting_test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/go-counting/canonical-data.json
# File last updated on 2023-07-19
import unittest
from go_counting import (
Board,
WHITE,
BLACK,
NONE,
)
class GoCountingTest(unittest.TestCase):
def test_black_corner_territory_on_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
stone, territory = board.territory(x=0, y=1)
self.assertEqual(stone, BLACK)
self.assertSetEqual(territory, {(0, 0), (0, 1), (1, 0)})
def test_white_center_territory_on_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
stone, territory = board.territory(x=2, y=3)
self.assertEqual(stone, WHITE)
self.assertSetEqual(territory, {(2, 3)})
def test_open_corner_territory_on_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
stone, territory = board.territory(x=1, y=4)
self.assertEqual(stone, NONE)
self.assertSetEqual(territory, {(0, 3), (0, 4), (1, 4)})
def test_a_stone_and_not_a_territory_on_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
stone, territory = board.territory(x=1, y=1)
self.assertEqual(stone, NONE)
self.assertSetEqual(territory, set())
def test_invalid_because_x_is_too_low_for_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
with self.assertRaises(ValueError) as err:
board.territory(x=-1, y=1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Invalid coordinate")
def test_invalid_because_x_is_too_high_for_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
with self.assertRaises(ValueError) as err:
board.territory(x=5, y=1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Invalid coordinate")
def test_invalid_because_y_is_too_low_for_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
with self.assertRaises(ValueError) as err:
board.territory(x=1, y=-1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Invalid coordinate")
def test_invalid_because_y_is_too_high_for_5x5_board(self):
board = Board([" B ", " B B ", "B W B", " W W ", " W "])
with self.assertRaises(ValueError) as err:
board.territory(x=1, y=5)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Invalid coordinate")
def test_one_territory_is_the_whole_board(self):
board = Board([" "])
territories = board.territories()
self.assertSetEqual(territories[BLACK], set())
self.assertSetEqual(territories[WHITE], set())
self.assertSetEqual(territories[NONE], {(0, 0)})
def test_two_territory_rectangular_board(self):
board = Board([" BW ", " BW "])
territories = board.territories()
self.assertSetEqual(territories[BLACK], {(0, 0), (0, 1)})
self.assertSetEqual(territories[WHITE], {(3, 0), (3, 1)})
self.assertSetEqual(territories[NONE], set())
def test_two_region_rectangular_board(self):
board = Board([" B "])
territories = board.territories()
self.assertSetEqual(territories[BLACK], {(0, 0), (2, 0)})
self.assertSetEqual(territories[WHITE], set())
self.assertSetEqual(territories[NONE], set())