-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
149 lines (118 loc) · 4.48 KB
/
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
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
import unittest
import numpy as np
from app.dfs.depthFirstSearch import depth_first_search
from app.dfs import stateFactory, state
from app.dfs.state import State
from app.cnn.convNet import one_hot_encode, decode_output
from app.utilites import string_to_np_array, np_array_to_string
class TestState(unittest.TestCase):
def test_has_duplicate_false(self):
lst = [1, 2, 3, 4, 5, 6, 7]
act = state.has_duplicate(lst)
self.assertFalse(act)
def test_has_duplicate_true(self):
lst = [1, 1, 3, 4, 5, 6, 7]
act = state.has_duplicate(lst)
self.assertTrue(act)
def test_get_missing_all(self):
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
exp = []
act = state.get_missing(lst)
self.assertEqual(exp, act)
def test_get_missing_none(self):
lst = []
exp = [1, 2, 3, 4, 5, 6, 7, 8, 9]
act = state.get_missing(lst)
self.assertEqual(exp, act)
def test_get_missing_alternate(self):
lst = [1, 3, 5, 7, 9]
exp = [2, 4, 6, 8]
act = state.get_missing(lst)
self.assertEqual(exp, act)
def test_valid_row_empty(self):
b = stateFactory.generate_empty_state()
for i in range(1, 9):
self.assertTrue(b.check_row(i))
def test_valid_row_true(self):
b = stateFactory.generate_valid_state()
for i in range(1, 9):
self.assertTrue(b.check_row(i))
def test_valid_row_neg(self):
b = stateFactory.generate_invalid_row_state()
for i in range(1, 9):
self.assertFalse(b.check_row(i))
def test_valid_col_empty(self):
b = stateFactory.generate_empty_state()
for i in range(1, 9):
self.assertTrue(b.check_col(i))
def test_valid_col_true(self):
b = stateFactory.generate_valid_state()
for i in range(1, 9):
self.assertTrue(b.check_col(i))
def test_valid_col_neg(self):
b = stateFactory.generate_invalid_col_state()
for i in range(1, 9):
self.assertFalse(b.check_col(i))
def test_valid_box_empty(self):
b = stateFactory.generate_empty_state()
for i in range(1, 9):
self.assertTrue(b.check_box(i))
def test_valid_box_true(self):
b = stateFactory.generate_valid_state()
for i in range(1, 9):
self.assertTrue(b.check_box(i))
def test_valid_box_neg(self):
b = stateFactory.generate_invalid_box_state()
print(b)
for i in range(1, 9):
print(i)
self.assertFalse(b.check_box(i))
def test_is_legal_empty(self):
b = stateFactory.generate_empty_state()
self.assertTrue(b.is_legal())
def test_is_legal_complete(self):
b = stateFactory.generate_complete_state()
self.assertTrue(b.is_legal())
def test_is_legal_invalid_box(self):
b = stateFactory.generate_invalid_box_state()
self.assertFalse(b.is_legal())
def test_is_legal_invalid_row(self):
b = stateFactory.generate_invalid_row_state()
self.assertFalse(b.is_legal())
def test_is_legal_invalid_col(self):
b = stateFactory.generate_invalid_col_state()
self.assertFalse(b.is_legal())
def test_lookup_box(self):
b = stateFactory.generate_empty_state()
exp = 1
act = b.look_up_box(2, 2)
self.assertEqual(exp, act)
def test_lookup_box_zero(self):
b = stateFactory.generate_empty_state()
exp = 1
act = b.look_up_box(0, 0)
self.assertEqual(exp, act)
def test_copy(self):
a = stateFactory.generate_empty_state()
b = a.copy()
self.assertNotEqual(a, b)
def test_set(self):
a = stateFactory.generate_empty_state()
self.assertEqual(0, a.get(1, 1))
a.set(1, 1, 1)
self.assertEqual(1, a.get(1, 1))
def test_decoding(self):
a = stateFactory.generate_complete_state()
enc = one_hot_encode(a.board) # Encoded board
dec = decode_output(enc) # Decoded board
b = State(dec)
for i in range(len(a.board)):
for j in range(len(a.board[0])):
self.assertEqual(a.board[i, j], b.board[i, j]) # Compare each index
def test_string_to_np_array(self):
string = "000000000000000000000000000000000000000000000000000000000000000000000000000000000"
exp = np.zeros((9, 9))
act = string_to_np_array(string)
self.assertEqual(exp.shape, act.shape)
if __name__ == '__main__':
unittest.main()