def test_only_choice(self): self.grid.update({ "A1": "1", "A2": "32", "A3": "32", "B1": "432", "B2": "5", "B3": "789", "C1": "789", "C2": "789", "C3": "96", }) reduced_grid = solution.only_choice(self.grid) self.assertEqual(reduced_grid["B1"], "4") self.assertEqual(reduced_grid["C3"], "6") self.assertEqual(reduced_grid["B2"], "5") self.assertEqual(reduced_grid["A1"], "1")
def test_only_choice(self): # given t_values = solution.eliminate( solution.grid_values( '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..' )) # when print() lines = solution.display(solution.only_choice(t_values)) # then self.assertEquals( ' 345 345 8 | 1 3456 2 | 9 34567 34567 ', lines[4]) self.assertEquals( ' 7 2 9 | 5 34569 4 | 1 13456 8 ', lines[5]) self.assertEquals( ' 1345 13459 6 | 7 3459 8 | 2 1345 345 ', lines[6])
def test_onlychoice(self): puzzle = { 'A1': '45', 'A2': '4578', 'A3': '3', 'A4': '49', 'A5': '2', 'A6': '147', 'A7': '6', 'A8': '5789', 'A9': '57', 'B1': '9', 'B2': '24678', 'B3': '47', 'B4': '3', 'B5': '47', 'B6': '5', 'B7': '78', 'B8': '278', 'B9': '1', 'C1': '25', 'C2': '257', 'C3': '1', 'C4': '8', 'C5': '79', 'C6': '6', 'C7': '4', 'C8': '23579', 'C9': '2357', 'D1': '345', 'D2': '345', 'D3': '8', 'D4': '1', 'D5': '3456', 'D6': '2', 'D7': '9', 'D8': '34567', 'D9': '34567', 'E1': '7', 'E2': '123459', 'E3': '49', 'E4': '459', 'E5': '34569', 'E6': '4', 'E7': '1', 'E8': '13456', 'E9': '8', 'F1': '1345', 'F2': '13459', 'F3': '6', 'F4': '7', 'F5': '3459', 'F6': '8', 'F7': '2', 'F8': '1345', 'F9': '345', 'G1': '134', 'G2': '1347', 'G3': '2', 'G4': '6', 'G5': '478', 'G6': '9', 'G7': '5', 'G8': '1478', 'G9': '47', 'H1': '8', 'H2': '1467', 'H3': '47', 'H4': '2', 'H5': '457', 'H6': '3', 'H7': '17', 'H8': '1467', 'H9': '9', 'I1': '46', 'I2': '4679', 'I3': '5', 'I4': '4', 'I5': '1', 'I6': '47', 'I7': '3', 'I8': '24678', 'I9': '2467' } expected = { 'A1': '4', 'A2': '8', 'A3': '3', 'A4': '9', 'A5': '2', 'A6': '1', 'A7': '6', 'A8': '5789', 'A9': '5', 'B1': '9', 'B2': '6', 'B3': '47', 'B4': '3', 'B5': '4', 'B6': '5', 'B7': '8', 'B8': '8', 'B9': '1', 'C1': '2', 'C2': '257', 'C3': '1', 'C4': '8', 'C5': '7', 'C6': '6', 'C7': '4', 'C8': '23579', 'C9': '2357', 'D1': '345', 'D2': '345', 'D3': '8', 'D4': '1', 'D5': '3456', 'D6': '2', 'D7': '9', 'D8': '34567', 'D9': '34567', 'E1': '7', 'E2': '2', 'E3': '9', 'E4': '5', 'E5': '3', 'E6': '4', 'E7': '1', 'E8': '13456', 'E9': '8', 'F1': '1345', 'F2': '13459', 'F3': '6', 'F4': '7', 'F5': '3459', 'F6': '8', 'F7': '2', 'F8': '1345', 'F9': '345', 'G1': '134', 'G2': '1347', 'G3': '2', 'G4': '6', 'G5': '8', 'G6': '9', 'G7': '5', 'G8': '1478', 'G9': '47', 'H1': '8', 'H2': '1', 'H3': '47', 'H4': '2', 'H5': '5', 'H6': '3', 'H7': '17', 'H8': '6', 'H9': '9', 'I1': '6', 'I2': '9', 'I3': '5', 'I4': '4', 'I5': '1', 'I6': '7', 'I7': '3', 'I8': '8', 'I9': '2' } actual = solution.only_choice(puzzle) self.assertEqual(expected, actual)
def test_only_choice_001(self): grid = '2.............62....1....7...6..8...3...9...7...6..4...4....8....52.............3' values = grid_values(grid) values = eliminate(values) values = only_choice(values) # with the diagonal constraint self.assertEqual( { 'G7': '8', 'G6': '13579', 'G5': '13567', 'G4': '13579', 'G3': '2', 'G2': '4', 'G1': '1679', 'G9': '12569', 'G8': '12569', 'C9': '45689', 'C8': '7', 'C3': '1', 'C2': '35689', 'C1': '45689', 'C7': '35', 'C6': '23459', 'C5': '23458', 'C4': '34589', 'E5': '9', 'E4': '145', 'F1': '15789', 'F2': '125789', 'F3': '2789', 'F4': '6', 'F5': '12357', 'F6': '57', 'F7': '4', 'F8': '123589', 'F9': '12589', 'B4': '1345789', 'B5': '134578', 'B6': '6', 'B7': '2', 'B1': '45789', 'B2': '57', 'B3': '34789', 'B8': '1345', 'B9': '14589', 'I9': '3', 'I8': '124569', 'I1': '17', 'I3': '2789', 'I2': '126789', 'I5': '145678', 'I4': '145789', 'I7': '15679', 'I6': '14579', 'A1': '2', 'A3': '34789', 'A2': '356789', 'E9': '7', 'A4': '1345789', 'A7': '13569', 'A6': '134579', 'A9': '145', 'A8': '1345689', 'E7': '156', 'E6': '1245', 'E1': '3', 'E3': '248', 'E2': '1258', 'E8': '12568', 'A5': '134578', 'H8': '6', 'H9': '1469', 'H2': '137', 'H3': '5', 'H1': '16789', 'H6': '13479', 'H7': '1679', 'H4': '2', 'H5': '134678', 'D8': '12359', 'D9': '1259', 'D6': '8', 'D7': '1359', 'D4': '457', 'D5': '123457', 'D2': '12579', 'D3': '6', 'D1': '14579' }, values)
def test_only_choice1(self): display(self.only_choice_input1) actual = solution.only_choice(self.only_choice_input1) display(actual)
def test_only_choice_preserves_solved_values(self): only_choiced_values = solution.only_choice(self.values.copy()) self.assertEqual(only_choiced_values['F4'], '7')
def test_only_choice_in_square(self): only_choiced_values = solution.only_choice(self.values.copy()) self.assertEqual(only_choiced_values['A6'], '1')
def test_only_choice_in_col(self): only_choiced_values = solution.only_choice(self.values.copy()) self.assertEqual(only_choiced_values['E3'], '9')
def test_only_choice_in_row(self): only_choiced_values = solution.only_choice(self.values.copy()) self.assertEqual(only_choiced_values['B2'], '6')