def test_vertical_naked_pair(self): grid = Grid(StringIO("..516....\n6...73...\n3....57.6\n....3.691\n139756482\n862491..7\n4.1.....5\n...5....8\n.....72..\n")) prepareRemainingCandidates(grid) self.assertItemsEqual([2, 4, 7, 8, 9], grid.candidates[1][0]) self.assertItemsEqual([1, 2, 4, 8, 9], grid.candidates[1][1]) self.assertItemsEqual([1, 2, 4, 8, 9], grid.candidates[1][2]) self.assertItemsEqual([4, 8], grid.candidates[2][1]) self.assertItemsEqual([4, 8], grid.candidates[2][2]) self.assertEqual(0, self.nakedPairsResolution.vertical_naked_pair(grid, 2, 1))
def test_column_block_reduction(self): grid = Grid(StringIO("000023400004000100050084090601070902793206801000010760000000009800000004060000587")) prepareRemainingCandidates(grid) self.assertItemsEqual([1, 3, 4, 5, 6, 7, 8], grid.candidates[3][6]) self.assertItemsEqual([1, 3, 5, 6, 7, 9], grid.candidates[3][7]) self.assertItemsEqual([1, 3, 4, 9], grid.candidates[3][8]) self.assertEqual(0, self.lockedCandidatesResolution.column_block_reduction(grid, 3, 0)) self.assertItemsEqual([3, 4, 5, 6, 7, 8], grid.candidates[3][6]) self.assertItemsEqual([3, 5, 6, 7, 9], grid.candidates[3][7]) self.assertItemsEqual([3, 4, 9], grid.candidates[3][8])
def test_block_row_reduction(self): grid = Grid( StringIO( ".16..78.3\n.9.8.....\n87...1.6.\n.48...3..\n65...9.82\n239...65.\n.6.9...2.\n.8...2936\n9246..51.\n" ) ) prepareRemainingCandidates(grid) self.assertItemsEqual([2, 3, 4, 5], grid.candidates[3][2]) self.assertItemsEqual([2, 3, 4, 5, 6], grid.candidates[4][1]) self.assertItemsEqual([2, 3, 4, 5, 9], grid.candidates[4][2]) self.assertEqual(0, self.lockedCandidatesResolution.block_row_reduction(grid, 3, 0)) self.assertItemsEqual([3, 4, 5], grid.candidates[3][2]) self.assertItemsEqual([3, 4, 5, 6], grid.candidates[4][1]) self.assertItemsEqual([3, 4, 5, 9], grid.candidates[4][2])
def test_row_block_reduction(self): grid = Grid( StringIO( ".179.36..\n....8....\n9.....5.7\n.72.1.43.\n...4.2.7.\n.6437.25.\n7.1....65\n....3....\n..56.172.\n" ) ) prepareRemainingCandidates(grid) self.assertItemsEqual([2, 3, 4, 5, 6], grid.candidates[0][1]) self.assertItemsEqual([2, 3, 4, 5], grid.candidates[1][1]) self.assertItemsEqual([3, 6], grid.candidates[2][1]) self.assertEqual(1, self.lockedCandidatesResolution.row_block_reduction(grid, 6, 0)) self.assertItemsEqual([2, 4, 5, 6], grid.candidates[0][1]) self.assertItemsEqual([2, 4, 5], grid.candidates[1][1]) self.assertItemsEqual([6], grid.candidates[2][1]) self.assertEqual( ".179.36..\n..6.8....\n9.....5.7\n.72.1.43.\n...4.2.7.\n.6437.25.\n7.1....65\n....3....\n..56.172.\n", grid.display(), )
def test_block_column_reduction(self): grid = Grid(StringIO("500200010001900730000000800050020008062039000000004300000000000080467900007300000")) prepareRemainingCandidates(grid) self.assertItemsEqual([2, 4, 5, 6, 7, 8], grid.candidates[7][6]) self.assertItemsEqual([2, 5], grid.candidates[7][7]) self.assertItemsEqual([2, 4, 5, 6, 8], grid.candidates[7][8]) self.assertItemsEqual([1, 2, 3, 4, 5, 6, 7], grid.candidates[8][6]) self.assertItemsEqual([1, 2, 3, 5], grid.candidates[8][7]) self.assertItemsEqual([1, 2, 4, 5, 6], grid.candidates[8][8]) self.assertEqual(1, self.lockedCandidatesResolution.block_column_reduction(grid, 6, 6)) self.assertItemsEqual([4, 5, 6, 7, 8], grid.candidates[7][6]) self.assertItemsEqual([5], grid.candidates[7][7]) self.assertItemsEqual([4, 5, 6, 8], grid.candidates[7][8]) self.assertItemsEqual([1, 3, 4, 5, 6, 7], grid.candidates[8][6]) self.assertItemsEqual([1, 3, 5], grid.candidates[8][7]) self.assertItemsEqual([1, 4, 5, 6], grid.candidates[8][8]) self.assertEqual( "5..2...1...19..73.......8...5..2...8.62.39........43............8.46795...73.....", grid.display(lineBreak=False), )
def test_vertical_hidden_single(self): grid = Grid(StringIO(".5.......\n.1.......\n.........\n.3.......\n.9.......\n..5.2....\n..19.2...\n.8.......\n.6.......\n")) prepareRemainingCandidates(grid) self.assertEqual(True, self.hiddenSingleResolution.vertical_hidden_single(grid, 1, 2)) self.assertEqual(False, self.hiddenSingleResolution.vertical_hidden_single(grid, 1, 5)) self.assertEqual(".5.......\n.1.......\n.2.......\n.3.......\n.9.......\n..5.2....\n..19.2...\n.8.......\n.6.......\n", grid.display())
def test_horizontal_hidden_single(self): grid = Grid(StringIO(".1...3..8\n.2.51.9.3\n....29...\n.8....6.9\n279156834\n4.6....7.\n...27....\n3.2..1...\n6..3...9.\n")) prepareRemainingCandidates(grid) self.assertEqual(True, self.hiddenSingleResolution.horizontal_hidden_single(grid, 7, 1)) self.assertEqual(False, self.hiddenSingleResolution.horizontal_hidden_single(grid, 7, 2)) self.assertEqual(".1...3..8\n.2.51.963\n....29...\n.8....6.9\n279156834\n4.6....7.\n...27....\n3.2..1...\n6..3...9.\n", grid.display())