-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuduku_test.py
105 lines (84 loc) · 3.31 KB
/
suduku_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import suduku
def test_grid_size():
suduku.size = 3
assert suduku.grid_size() == 9
def test_is_contradiction():
grid = [[[v for v in range(1, suduku.grid_size()+1)]
for x in range(suduku.grid_size())] for y in range(suduku.grid_size())]
grid[0][0] = []
assert suduku.is_contradiction(grid)
grid[0][0] = [1]
assert not suduku.is_contradiction(grid)
def test_is_solved():
grid = [[[1] for x in range(suduku.grid_size())]
for y in range(suduku.grid_size())]
assert suduku.is_solved(grid)
grid[0][0] = [1, 2]
assert not suduku.is_solved(grid)
def test_remove_possibility_line():
suduku.size = 2
grid = [[[1, 2, 3, 4]
for x in range(suduku.grid_size())] for y in range(suduku.grid_size())]
grid[0][0] = [1]
suduku.remove_possibility_line(grid, 0, 0, 1)
assert grid[0][0] == [1]
assert grid[0][1] == [2, 3, 4]
assert grid[0][2] == [2, 3, 4]
assert grid[0][3] == [2, 3, 4]
assert grid[1][0] == [2, 3, 4]
assert grid[1][1] == [1, 2, 3, 4]
assert grid[1][2] == [1, 2, 3, 4]
assert grid[1][3] == [1, 2, 3, 4]
assert grid[2][0] == [2, 3, 4]
assert grid[2][1] == [1, 2, 3, 4]
assert grid[2][2] == [1, 2, 3, 4]
assert grid[2][3] == [1, 2, 3, 4]
assert grid[3][0] == [2, 3, 4]
assert grid[3][1] == [1, 2, 3, 4]
assert grid[3][2] == [1, 2, 3, 4]
assert grid[3][3] == [1, 2, 3, 4]
def test_remove_possibility_square():
suduku.size = 2
grid = [[[1, 2, 3, 4]
for x in range(suduku.grid_size())] for y in range(suduku.grid_size())]
grid[0][0] = [1]
suduku.remove_possibility_square(grid, 0, 0, 1)
assert grid[0][0] == [1]
assert grid[0][1] == [2, 3, 4]
assert grid[0][2] == [1, 2, 3, 4]
assert grid[0][3] == [1, 2, 3, 4]
assert grid[1][0] == [2, 3, 4]
assert grid[1][1] == [2, 3, 4]
assert grid[1][2] == [1, 2, 3, 4]
assert grid[1][3] == [1, 2, 3, 4]
assert grid[2][0] == [1, 2, 3, 4]
assert grid[2][1] == [1, 2, 3, 4]
assert grid[2][2] == [1, 2, 3, 4]
assert grid[2][3] == [1, 2, 3, 4]
assert grid[3][0] == [1, 2, 3, 4]
assert grid[3][1] == [1, 2, 3, 4]
assert grid[3][2] == [1, 2, 3, 4]
assert grid[3][3] == [1, 2, 3, 4]
def test_get_possible_values():
suduku.size = 2
grid = [[[1], [2, 3, 4], [2, 3, 4], [2, 3, 4]],
[[2, 3, 4], [2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
[[2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
[[2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]]
possible = suduku.get_possible_values(grid, 0, 0)
assert possible == [1, 2, 3, 4]
possible = suduku.get_possible_values(grid, 0, 1)
assert possible == [2, 3, 4]
def test_min_entropy_cells():
suduku.size = 2
grid = [[[1], [2, 3, 4], [2, 3, 4], [2, 3, 4]],
[[2, 3, 4], [2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
[[2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
[[2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]]
cells = suduku.min_entropy_cells(grid)
assert cells == [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (2, 0), (3, 0)]
def test_observe_cell():
grid = suduku.generate_initial_grid()
suduku.observe_cell(grid)
assert any(any(len(cell) == 1 for cell in row) for row in grid)
test_observe_cell()