コード例 #1
0
def test_small_sudoku_problem():
    matrix = load_problem("tests/files/small_sudoku.csv")
    assert matrix.shape == (64, 64)
    col_sums = np.sum(matrix, axis=0)
    assert all(col_sums <= 4)
    row_sums = np.sum(matrix, axis=1)
    assert np.isin(row_sums, [0, 4]).all()
コード例 #2
0
def test_solve_impossible_sudoku_problem():
    matrix = load_problem("tests/files/impossible_sudoku.csv")
    with pytest.raises(NoSolution):
        get_exact_cover(matrix)
コード例 #3
0
def test_solve_very_hard_sudoku_problem_2():
    matrix = load_problem("tests/files/very_hard_sudoku_2.csv")
    solution = get_exact_cover(matrix)
    assert is_solution(solution, matrix)
コード例 #4
0
def test_solve_medium_sudoku_problem():
    matrix = load_problem("tests/files/medium_sudoku.csv")
    solution = get_exact_cover(matrix)
    assert is_solution(solution, matrix)
コード例 #5
0
def test_basic_roundtrip():
    _, filename = mkstemp()
    array = create_numpy_array([[0, 1, 0], [1, 0, 1]])
    save_problem(filename, array)
    problem = load_problem(filename)
    assert_array_equal(array, problem)
コード例 #6
0
    data = cover_data + dummy_data
    shuffled_data = draw(permutations(data))
    return np.array(shuffled_data, dtype=np.int32)


@composite
def array_with_trivial_solution(draw):
    array = draw(exact_cover_problem())
    height, width = array.shape
    row = draw(integers(min_value=0, max_value=height - 1))
    array[row] = 1
    return array


large_problems_with_solution = one_of(
    just(load_problem("tests/files/pentominos_chessboard.csv")), )

array_with_solution = one_of(
    array_with_trivial_solution(),
    array_with_exact_cover(),
    large_problems_with_solution,
)


@example(np.array([[1, 1, 1]], dtype=np.int32))
@example(np.array([[1, 0, 0], [0, 1, 1]], dtype=np.int32))
@given(array_with_solution)
@pytest.mark.skipif(GLOBAL_CONFIG["SKIP_SLOW"], reason="Skipping slow tests")
def test_exact_cover_with_solution(array_data):
    rowcount = len(array_data)
    actual = get_exact_cover(array_data)