Exemplo n.º 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
Exemplo n.º 2
0
def test_build_possible_naked_sets(naked_sets_sudoku, naked_sets_dicts):
    """Given a Sudoku test that function returns possible naked sets."""
    from sudoku_solver_hard import get_candidates, build_possible_naked_sets
    m = naked_sets_sudoku
    dicts, square_coords = naked_sets_dicts
    candidates = get_candidates(m, dicts, square_coords)
    possible_naked_sets = build_possible_naked_sets(candidates)
    assert possible_naked_sets[(7, 3)] == [3, 8]
    assert possible_naked_sets[(8, 5)] == [3, 8]
def test_get_candidates_account_for_naked_sets(medium_sudoku):
    """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 setup, get_missing, get_candidates
    c, dicts, square_coords = setup(medium_sudoku)
    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)]
Exemplo n.º 4
0
def test_find_naked_sets(naked_sets_sudoku, naked_sets_dicts):
    """Given a dict of naked sets, test that function returns a list
    of coordinates from which a naked set can be removed from."""
    from sudoku_solver_hard import get_candidates, find_naked_sets
    m = naked_sets_sudoku
    dicts, square_coords = naked_sets_dicts
    c = get_candidates(m, dicts, square_coords)
    rows, cols = find_naked_sets(c, dicts)
    assert (8, 6) in rows[(3, 8)]
    assert (8, 2) in rows[(3, 8)]
    assert (8, 7) in rows[(3, 8)]
    assert cols == {}
Exemplo n.º 5
0
def test_coords_per_naked_set(naked_sets_sudoku, naked_sets_dicts):
    """Given a dict of possible naked sets, test that function returns the inverted dict."""
    from sudoku_solver_hard import (get_candidates, build_possible_naked_sets,
                                    build_coords_per_naked_set)
    m = naked_sets_sudoku
    dicts, square_coords = naked_sets_dicts
    c = get_candidates(m, dicts, square_coords)
    possible_naked_sets = build_possible_naked_sets(c)
    coords_per_naked_set = build_coords_per_naked_set(possible_naked_sets)
    for k, v in coords_per_naked_set.items():
        assert len(v) == len(
            [1 for nums in possible_naked_sets.values() if nums == list(k)])
Exemplo n.º 6
0
def test_remove_naked_sets_from_candidates(naked_sets_sudoku,
                                           naked_sets_dicts):
    """Given a dict of naked sets, test that function returns a list
    of coordinates from which a naked set can be removed from."""
    from sudoku_solver_hard import (get_candidates, find_naked_sets,
                                    remove_naked_sets_from_candidates)
    m = naked_sets_sudoku
    dicts, square_coords = naked_sets_dicts
    c = get_candidates(m, dicts, square_coords)
    rows, cols = find_naked_sets(c, dicts)
    c = remove_naked_sets_from_candidates(c, rows, cols)
    assert 3, 8 not in c[(8, 6)]
    assert 3, 8 not in c[(8, 2)]
    assert 3, 8 not in c[(8, 7)]
Exemplo n.º 7
0
def test_update_naked_set(naked_sets_sudoku, naked_sets_dicts):
    """Given a dict of possible naked sets and it inverse dict, test that the
    function returns an updated dict."""
    from sudoku_solver_hard import (get_candidates, build_possible_naked_sets,
                                    build_coords_per_naked_set,
                                    update_naked_set)
    m = naked_sets_sudoku
    dicts, square_coords = naked_sets_dicts
    c = get_candidates(m, dicts, square_coords)
    possible_naked_sets = build_possible_naked_sets(c)
    coords_per_naked_set = build_coords_per_naked_set(possible_naked_sets)
    naked_sets = update_naked_set(possible_naked_sets, coords_per_naked_set)
    vals = []
    for v in naked_sets.values():
        if v not in vals: vals.append(v)
    assert len(vals) == 1