/
test_blocking_puzzle.py
102 lines (79 loc) · 1.76 KB
/
test_blocking_puzzle.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from unittest.case import TestCase
from blocking_puzzle import BlockingBoardGraph
from domino_puzzle import Board
class BlockingBoardGraphTest(TestCase):
def setUp(self):
TestCase.setUp(self)
self.addTypeEqualityFunc(str, self.assertMultiLineEqual)
def test_no_blocking(self):
board = Board.create("""\
1|2
3|4
""")
graph = BlockingBoardGraph()
expected_states = set("""\
1|2
3|4
---
1|2 x
x 3|4
---
x 1|2
3|4 x
""".split('---\n'))
states = graph.walk(board)
self.assertEqual(expected_states, states)
def test_blocking(self):
board = Board.create("""\
1|2
2|4
""")
graph = BlockingBoardGraph()
expected_states = set("""\
1|2
2|4
---
x 1|2
2|4 x
""".split('---\n'))
states = graph.walk(board)
self.assertEqual(expected_states, states)
def test_start_and_last(self):
expected_start = """\
x x 1|2
2|4 3 x
-
x x 2 x
"""
expected_last = """\
1|2 3
-
2|4 2
"""
board = Board.create(expected_last)
graph = BlockingBoardGraph()
graph.walk(board)
self.assertEqual(expected_start, graph.start)
self.assertEqual(expected_last, graph.last)
def test_solution(self):
board = Board.create("""\
1|2 3
-
2|4 2
""")
graph = BlockingBoardGraph()
expected_solution = ['12l', '12l', '32u']
graph.walk(board)
solution = graph.get_solution()
self.assertEqual(expected_solution, solution)
def test_choice_counts(self):
board = Board.create("""\
1|2 3
-
2|4 2
""")
graph = BlockingBoardGraph()
expected_counts = [1, 2, 2]
graph.walk(board)
counts = graph.get_choice_counts()
self.assertEqual(expected_counts, counts)