コード例 #1
0
def test_board_to_str() -> None:
    """Ensure board dictionary to comma string 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..')
    str_list = list(board_string)
    str_list = list(item.replace('.', '123456789') for item in str_list)
    expected_string = ','.join(str_list)

    board = SB.grid_values(board_string)
    string = SB.board_to_str(board)
    assert string == expected_string
コード例 #2
0
def test_search() -> None:
    """Ensure recursive search succeeds on supplied problem"""
    board_string = ('4.....8.5.3..........7......2.....6.....8.4......1.......'
                    '6.3.7.5..2.....1.4......')
    expected_string = ('4,1,7,3,6,9,8,2,5,6,3,2,1,5,8,9,4,7,9,5,8,7,2,4,3,1,6,'
                       '8,2,5,4,3,7,1,6,9,7,9,1,5,8,6,4,3,2,3,4,6,9,1,2,7,5,8,'
                       '2,8,9,6,4,3,5,7,1,5,7,3,2,9,1,6,8,4,1,6,4,8,7,5,2,9,3')
    board = SB.grid_values(board_string)
    sbrd = SB()
    solution = sbrd.search(board)
    SB.display(solution)
    solution_string = SB.board_to_str(solution)
    assert solution_string == expected_string
コード例 #3
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
コード例 #4
0
def test_only_choice() -> None:
    """Ensure board state after single only choice 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 = ('45,8,3,9,2,1,6,5789,57,9,6,47,3,4,5,8,278,1,2,257,1,8,'
                       '7,6,4,23579,2357,345,345,8,1,3456,2,9,34567,34567,7,2,'
                       '9,5,34569,4,1,13456,8,1345,13459,6,7,3459,8,2,1345,'
                       '345,134,1347,2,6,8,9,5,1478,47,8,1467,47,2,5,3,17,6,9,'
                       '6,9,5,4,1,7,3,8,2')
    board_dict = SB.grid_values(board_string)
    sbrd = SB()
    eliminated_board = sbrd.eliminate(board_dict)
    only_choice_board = sbrd.only_choice(eliminated_board)
    only_choice_string = SB.board_to_str(only_choice_board)
    assert only_choice_string == expected_string
コード例 #5
0
def test_eliminate() -> None:
    """Ensure board state after single elimination 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..')

    # eliminated board in comma separated format for easy comparison
    expected_string = ('45,4578,3,49,2,147,6,5789,57,9,24678,47,3,47,5,78,278,'
                       '1,25,257,1,8,79,6,4,23579,2357,345,345,8,1,3456,2,9,'
                       '34567,34567,7,123459,49,459,34569,4,1,13456,8,1345,'
                       '13459,6,7,3459,8,2,1345,345,134,1347,2,6,478,9,5,1478,'
                       '47,8,1467,47,2,457,3,17,1467,9,46,4679,5,4,1,47,3,'
                       '24678,2467')
    board = SB.grid_values(board_string)
    eliminated_board = SB().eliminate(board)
    eliminated_string = SB.board_to_str(eliminated_board)

    assert eliminated_string == expected_string
コード例 #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