-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
58 lines (39 loc) · 1.83 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
import unittest
from game import *
from board import *
class TestBoardMethods(unittest.TestCase):
def test_is_solved(self):
constraints = {'A1':{'right': 3, 'down': 3}, 'B2': None, 'B3': None, 'C2': None, 'C3': None}
b = Board(3, constraints)
solutions = b.create_initial_solutions(3)
solutions['A2'] = '1'
solutions['A3'] = '2'
solutions['B1'] = '1'
solutions['C1'] = '2'
self.assertTrue(b.is_solved(solutions))
def test_is_solved_returns_false_for_initial_board_stage(self):
constraints = {'A1':{'right': 3, 'down': 3}, 'B2': None, 'B3': None, 'C2': None, 'C3': None}
b = Board(3, constraints)
solutions = b.create_initial_solutions(3)
self.assertFalse(b.is_solved(solutions))
def test_traverse_through_options(self):
constraints = {'A1':{'right': 3, 'down': 3}, 'B2': None, 'B3': None, 'C2': None, 'C3': None}
b = Board(3, constraints)
solutions = b.create_initial_solutions(3)
options = b.traverse_through_options(solutions)
self.assertEqual(len(options), 3)
for optional_board in options:
self.assertNotEqual(solutions, optional_board)
def test_constraint_remove_single_value_from_peers(self):
constraints = {'A1':{'right': 3, 'down': 3}, 'B2': None, 'B3': None, 'C2': None, 'C3': None}
b = Board(3, constraints)
solutions = b.create_initial_solutions(3)
solutions['A2'] = '1'
solutions['C1'] = '2'
expected = copy.copy(solutions)
expected['A3'] = '23'
expected['B1'] = '13'
reduced = b.constraint_remove_single_value_from_peers(solutions)
self.assertEqual(reduced, expected)
suite = unittest.TestLoader().loadTestsFromTestCase(TestBoardMethods)
unittest.TextTestRunner(verbosity=2).run(suite)