Beispiel #1
0
def immediate_fills_candidates(immediate_fills_dicts, medium_sudoku):
    from sudoku_solver_hard import get_missing, get_starting_spots, get_candidates
    m = medium_sudoku
    dicts, square_coords = immediate_fills_dicts
    dicts = get_missing(dicts)
    candidates = get_candidates(m, dicts, square_coords)
    return candidates
Beispiel #2
0
def test_get_missing(immediate_fills_dicts):
    """Test that dicts with given numbers swap with missing numbers."""
    from sudoku_solver_hard import get_missing
    dicts, square_coords = immediate_fills_dicts
    dicts = get_missing(dicts)
    rows_missing, cols_missing, squares_missing = dicts
    assert rows_missing[0] == set([1, 2, 3, 4, 6, 7])
    assert cols_missing[8] == set([1, 2, 3, 5, 7, 9])
    assert squares_missing[9] == set([1, 3, 5, 6, 7, 8, 9])
Beispiel #3
0
def test_get_sorted_starting_spots(immediate_fills_dicts, medium_sudoku):
    """Test that function returns best starting spots given a sudoku dicts
    and square coordinates."""
    from sudoku_solver_hard import get_missing, get_starting_spots
    dicts, square_coords = immediate_fills_dicts
    dicts = get_missing(dicts)
    starting_spots = get_starting_spots(medium_sudoku, dicts, square_coords)
    starting_spots.sort(key=itemgetter(2))
    assert starting_spots[0] == (4, 4, 11)
    assert starting_spots[-1] == (2, 2, 21)
def naked_sets_dicts(naked_sets_sudoku):
    from sudoku_solver_hard import (initialize_dicts, initialize_d,
                                    fill_given_numbers, populate_dicts,
                                    get_missing, get_candidates)
    m = naked_sets_sudoku
    square_sides = int(sqrt(len(naked_sets_sudoku)))
    dicts = initialize_dicts(m, square_sides)
    dicts, square_coords = populate_dicts(m, square_sides, dicts)
    dicts = get_missing(dicts)
    return dicts, square_coords
Beispiel #5
0
def test_get_candidates_account_for_naked_sets(medium_sudoku,
                                               immediate_fills_dicts):
    """Test that function returns a dict of candidates per coordinate but omits
    numbers for coordinates from naked sets if provided."""
    from sudoku_solver_hard import get_missing, get_candidates
    dicts, square_coords = immediate_fills_dicts
    dicts = get_missing(dicts)
    naked_sets = {(3, 8): [(8, 7), (8, 6), (8, 2)]}
    c = get_candidates(medium_sudoku, dicts, square_coords, naked_sets)
    assert 3, 8 not in c[(8, 6)]
    assert 3, 8 not in c[(8, 2)]
    assert 3, 8 not in c[(8, 7)]
Beispiel #6
0
def test_fill_fit(medium_sudoku, immediate_fills_dicts):
    """Test that given single_candidates, the Sudoku is updated correctly and
    the fill is removed from Sudoku dicts."""
    from sudoku_solver_hard import get_missing, fill_fit
    m = medium_sudoku
    dicts, square_coords = immediate_fills_dicts
    dicts = get_missing(dicts)
    rm, cm, sm = dicts
    single_candidates = [(7, (0, 3)), (9, (3, 1)), (6, (5, 0)), (7, (5, 8)),
                         (9, (7, 5)), (2, (8, 3))]
    m, candidates = fill_fit(m,
                             dicts,
                             square_coords,
                             single_candidates=single_candidates)
    assert m[0][3] == 7
    assert m[5][0] == 6
    assert m[8][3] == 2
    assert 7 not in rm[0]