-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nongramsolver.py
More file actions
65 lines (61 loc) · 1.79 KB
/
test_nongramsolver.py
File metadata and controls
65 lines (61 loc) · 1.79 KB
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
import pytest
import glob
import json
from nonogramsolver import NonogramSolver
import nonogramgenerator
'''
send all json files
'''
def test_solver():
for path in sorted(glob.glob('examples/*.json')):
print(path)
solver = NonogramSolver(path)
solver.set_verbose(True)
solver.solve()
test_res = solver.__str__().replace('\n', '')
res_path = path.replace('.json', '.res')
with open(res_path, 'r') as f:
res = ''.join(f.readlines()).replace('\n', '')
assert(test_res == res)
print('....checked')
'''
send all nonograms request in array format
'''
def test_generator_array():
for path in sorted(glob.glob('examples/*.res')):
print(path)
with open(path) as f:
ar = [line.strip() for line in f.readlines()]
test_res = nonogramgenerator.array_to_nonogram(ar)
res_path = path.replace('.res', '.json')
with open(res_path, 'r') as f:
res = json.load(f)
assert(json.dumps(test_res) == json.dumps(res))
print('....checked')
'''
send all nonograms request in string format
'''
def test_generator_str():
for path in sorted(glob.glob('examples/*.res')):
print(path)
with open(path) as f:
ar = '\n'.join([line.strip() for line in f.readlines()])
test_res = nonogramgenerator.str_to_nonogram(ar)
res_path = path.replace('.res', '.json')
with open(res_path, 'r') as f:
res = json.load(f)
assert(json.dumps(test_res) == json.dumps(res))
print('....checked')
'''
solve all nonogram jsons then send result to nonogramgenerator to generate initial nonogram jsons
'''
def test_cross_check():
for path in sorted(glob.glob('examples/*.json')):
print(path)
solver = NonogramSolver(path)
solver.solve()
solver_res = solver.NONO < 2
with open(path) as f:
solver_inp = json.load(f)
assert(solver_inp == nonogramgenerator.array_to_nonogram(solver_res))
print('....checked')