示例#1
0
def test_no_solution():
    table = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 'lt', 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)
    assert puzzle.solve() == False
示例#2
0
def test_satisfies_constraints():
    table = [[2, 3, 4, 1], [1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 0, 2]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    assert puzzle.satisfies_constraints(1, 3, 2) == True
示例#3
0
def test_not_fits_in_row():
    table = [[2, 3, 4, 1], [1, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    assert puzzle.fits_in_row(2, 1) == False
示例#4
0
def test_fits_in_col():
    table = [[2, 3, 4, 1], [1, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    assert puzzle.fits_in_col(3, 0) == True
示例#5
0
def test_puzzle_full():
    table = [[2, 3, 4, 1], [1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    assert puzzle.find_next_empty() == False
示例#6
0
def test_not_satisfies_constraints5():
    table = [[0, 3, 4, 1], [1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2]]
    row_constraints = [['lt', 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    assert puzzle.satisfies_constraints(4, 0, 0) == False
示例#7
0
def test_find_next_empty():
    table = [[2, 3, 4, 1], [1, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    expected = (1, 2)
    assert puzzle.find_next_empty() == expected
示例#8
0
def test_solve():
    table = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 0, 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)

    expected = [[2, 3, 4, 1], [1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2]]
    assert puzzle.solve() == expected
示例#9
0
def test_no_solution_verbose(capsys):
    # https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function
    table = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    row_constraints = [[0, 'lt', 0], [0, 0, 0], [0, 'lt', 0], [0, 0, 'lt']]
    col_constraints = [[0, 'gt', 0, 0], ['lt', 0, 0, 0], [0, 0, 'lt', 'gt']]

    puzzle = Futoshiki(table, row_constraints, col_constraints)
    puzzle.solve(verbose=True)
    captured = capsys.readouterr()
    assert captured.out.rstrip() == 'No solution :('