-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
181 lines (160 loc) · 9.67 KB
/
tests.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from unittest.mock import patch
from io import StringIO
import unittest
import main
class TestSolvablity(unittest.TestCase):
@patch('sys.stdout', new_callable=StringIO)
def test_grid1_solvable(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid1.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid1_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid1.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n1"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_solvable(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid2_2ineq.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_2ineq2.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_2val.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_4ineq.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_base.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_ineq_down.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_ineq_left.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_ineq_right.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_ineq_up.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid2_val.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_2ineq_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid2_2ineq.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2 1"
"\nv ^"
"\n1 2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_4ineq_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid2_4ineq.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2>1"
"\nv ^"
"\n1<2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_val_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid2_val.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2 1"
"\n. ."
"\n1 2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_2val_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid2_2val.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n1 2"
"\n. ."
"\n2 1"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid2_unsolvable(self, mock_stdout):
self.assertIsNone(main.solve_with_file("boards/grid2_2ineq_fail.txt"))
self.assertIsNone(main.solve_with_file("boards/grid2_ineq_val_fail1.txt"))
self.assertIsNone(main.solve_with_file("boards/grid2_ineq_val_fail2.txt"))
self.assertIsNone(main.solve_with_file("boards/grid2_val_fail.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_solvable(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid3_3ineq.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_val2.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_val_3ineq2.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_base.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_2ineq.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_val1.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_val_3ineq1.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid3_val_4ineq.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_base_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid3_val1.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2 3 1"
"\n. . ."
"\n1 2 3"
"\n. . ."
"\n3 1 2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_3ineq_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid3_3ineq.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n1 2<3"
"\n^ . ."
"\n2 3 1"
"\n^ . ."
"\n3 1 2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_val2_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid3_val2.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2 3 1"
"\n. . ."
"\n3 1 2"
"\n. . ."
"\n1 2 3"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_val_4ineq_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid3_val_4ineq.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n2 3>1"
"\n. . ^"
"\n3 1 2"
"\n. ^ ."
"\n1 2<3"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid3_unsolvable(self, mock_stdout):
self.assertIsNone(main.solve_with_file("boards/grid3_val_2ineq_fail1.txt"))
self.assertIsNone(main.solve_with_file("boards/grid3_val_fail.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid5(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid5_1.txt"))
self.assertIsNotNone(main.solve_with_file("boards/grid5_2.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid5_1_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid5_1.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n5 2>1 3 4"
"\n. . . . ."
"\n3 5 2 4 1"
"\n. . . v ."
"\n4 1<3 2 5"
"\n. . . . ."
"\n1 3 4 5 2"
"\n^ ^ . . ."
"\n2 4<5 1 3"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid7(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid7.txt"))
@patch('sys.stdout', new_callable=StringIO)
def test_grid7_solvable_solution(self, mock_stdout):
main.solve_with_file("boards/grid7.txt")
self.assertEqual(mock_stdout.getvalue(), "---------------SOLUTION----------------"
"\n5>4>1<2<7 3 6"
"\n. . . . . . v"
"\n1 7 6>4>2<5 3"
"\n. v . ^ . . ."
"\n4 3 5 6 1<2 7"
"\nv v ^ . . . v"
"\n3>2 7 5 6 4 1"
"\n. . . . . . ."
"\n7>6 2 3 5 1 4"
"\n. . . . . . ^"
"\n2 1 3 7 4 6>5"
"\n. . ^ v . ^ ."
"\n6>5>4 1 3 7 2"
"\n")
@patch('sys.stdout', new_callable=StringIO)
def test_grid9(self, mock_stdout):
self.assertIsNotNone(main.solve_with_file("boards/grid9.txt"))