Esempio n. 1
0
def test_reduce_puzzle_fail() -> None:
    """Given an empty board reduce will fail and return none"""
    board_string = '.' * SB.num_boxes()
    board = SB.grid_values(board_string)

    sbrd = SB()
    solution = sbrd.reduce_puzzle(board)

    assert solution is None
Esempio n. 2
0
def test_validate_fail() -> None:
    """Validation function correctly fails on incomplete board"""
    board_string = ('4.....8.5.3..........7......2.....6.....8.4......1.......'
                    '6.3.7.5..2.....1.4......')
    board = SB.grid_values(board_string)
    sbrd = SB()
    solution = sbrd.reduce_puzzle(board)
    valid = sbrd.validate(solution)

    assert valid is False
Esempio n. 3
0
def test_validate() -> None:
    """Validation function correctly validates complete board"""
    board_string = ('..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82..'
                    '..26.95..8..2.3..9..5.1.3..')
    board = SB.grid_values(board_string)
    sbrd = SB()
    solution = sbrd.reduce_puzzle(board)
    valid = sbrd.validate(solution)

    assert valid is True
Esempio n. 4
0
def test_reduce_puzzle() -> None:
    """Ensure board state after recursive reduce is correct"""
    board_string = ('..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82..'
                    '..26.95..8..2.3..9..5.1.3..')
    expected_string = ('4,8,3,9,2,1,6,5,7,9,6,7,3,4,5,8,2,1,2,5,1,8,7,6,4,9,3,'
                       '5,4,8,1,3,2,9,7,6,7,2,9,5,6,4,1,3,8,1,3,6,7,9,8,2,4,5,'
                       '3,7,2,6,8,9,5,1,4,8,1,4,2,5,3,7,6,9,6,9,5,4,1,7,3,8,2')

    board = SB.grid_values(board_string)
    sbrd = SB()
    solution = sbrd.reduce_puzzle(board)
    solution_string = sbrd.board_to_str(solution)
    assert solution_string == expected_string
Esempio n. 5
0
def test_sorted_box_possibilities() -> None:
    """Ensure order of sorted box possibilities with given reduced board"""
    board_string = ('4.....8.5.3..........7......2.....6.....8.4......1.......'
                    '6.3.7.5..2.....1.4......')
    expected_sort = ['G2', 'H7', 'A4', 'A6', 'E4', 'F4', 'G1', 'G3', 'G5',
                     'H5', 'H8', 'I4', 'I5', 'A2', 'A5', 'A8', 'B8', 'C1',
                     'D1', 'D4', 'D6', 'E1', 'G7', 'H2', 'H9', 'I2', 'I6',
                     'A3', 'B1', 'B4', 'B5', 'B7', 'C2', 'C7', 'C8', 'D3',
                     'D5', 'D7', 'D9', 'E2', 'E3', 'E6', 'E8', 'E9', 'F1',
                     'F3', 'F6', 'F7', 'F8', 'F9', 'G9', 'I7', 'I8', 'I9',
                     'B6', 'B9', 'C3', 'C5', 'C6', 'C9', 'B3']
    board = SB.grid_values(board_string)
    sbrd = SB()
    reduced = sbrd.reduce_puzzle(board)
    SB.display(reduced)
    sorted_boxes = SB.sorted_box_possibilities(reduced)
    assert sorted_boxes == expected_sort
Esempio n. 6
0
def test_reduce_puzzle_incomplete() -> None:
    """Ensure given a more complex puzzle reduce terminates incomplete"""
    board_string = ('4.....8.5.3..........7......2.....6.....8.4......1.......'
                    '6.3.7.5..2.....1.4......')
    expected_string = ('4,1679,12679,139,2369,269,8,1239,5,26789,3,1256789,'
                       '14589,24569,245689,12679,1249,124679,2689,15689,'
                       '125689,7,234569,245689,12369,12349,123469,3789,2,'
                       '15789,3459,34579,4579,13579,6,13789,3679,15679,15679,'
                       '359,8,25679,4,12359,12379,36789,4,56789,359,1,25679,'
                       '23579,23589,23789,289,89,289,6,459,3,1259,7,12489,5,'
                       '6789,3,2,479,1,69,489,4689,1,6789,4,589,579,5789,'
                       '23569,23589,23689')

    board = SB.grid_values(board_string)
    sbrd = SB()
    solution = sbrd.reduce_puzzle(board)
    solution_string = sbrd.board_to_str(solution)
    assert solution_string == expected_string