Exemple #1
0
def test_solve_one_tile_problem():
    tile = TETROMINOS["T"]
    tileset = many(tile)
    board = Irregular(tile)
    problem = board.tile_with_set(tileset)
    solution = problem.solve()
    assert solution is not None
Exemple #2
0
def test_solve_simple_tileset_with_0():
    squares = [(0, 0), (0, 1), (1, 1), (1, 2)]
    tileset = many(DOMINO).and_repeated_exactly(0, MONOMINO)
    problem = Irregular(squares).tile_with_set(tileset)
    solution = problem.solve()
    expected = [[(0, 0), (0, 1)], [(1, 1), (1, 2)]]
    assert solution.tiling == expected
Exemple #3
0
def test_solve_arbitrary_two_tile_problem(tile):
    tile = TETROMINOS["T"]
    tileset = many(tile)
    board = Irregular(tile + [(x, y + 100) for x, y in tile])
    problem = board.tile_with_set(tileset)
    solution = problem.solve()
    assert solution is not None
Exemple #4
0
def test_solve_rotated_one_tile_problem():
    tile = TETROMINOS["T"]
    tileset = many(tile)
    board = Irregular([(1, 0), (0, 1), (1, 1), (1, 2)])
    problem = board.tile_with_set(tileset)
    solution = problem.solve()
    assert solution is not None
Exemple #5
0
def test_rotated_one_tile_problem_is_correct():
    tile = TETROMINOS["T"]
    tileset = many(tile)
    board = Irregular([(1, 0), (0, 1), (1, 1), (1, 2)])
    problem = board.tile_with_set(tileset)
    problem.make_problem()
    a = problem.array
    assert a.shape == (1, 4)
Exemple #6
0
def test_one_tile_problem_is_correct_with_heuristics():
    tile = TETROMINOS["T"]
    tileset = many(tile)
    board = Irregular(tile)
    problem = board.tile_with_set(tileset).with_heuristics()
    problem.make_problem()
    a = problem.array
    assert a.shape == (1, 4)
Exemple #7
0
def test_13_cylinder_look_for_row():
    board = Irregular(make_13_cylinder())
    problem = board.tile_with_many(TETROMINOS["T"])
    problem.make_problem()
    a = problem.array
    expected = np.array([144, 145, 146, 160])
    assert any([(row.nonzero() == expected).all() for row in a])
    expected = np.array([128, 144, 145, 146])
    assert any([(row.nonzero() == expected).all() for row in a])
Exemple #8
0
def test_remove_from_irregular_gen():
    squares = [(0, 0), (0, 1), (1, 1), (1, 2), (1, 3)]

    def gen_sq():
        for sq in squares:
            yield sq

    board = Irregular(gen_sq())
    assert set(board.squares) == set(squares)
    trimmed = board.remove((1, 3))
    assert set(trimmed.squares) == set([(0, 0), (0, 1), (1, 1), (1, 2)])
Exemple #9
0
def test_not_too_many_tile_positions(tile, x, y):
    assume(x * y % len(tile) == 0)
    tileset = many(tile)
    rectangle = Rectangle(x, y)
    board = Irregular(set(rectangle.squares + tile))
    assume(len(board.squares) % len(tile) == 0)
    expected_size = x * y
    max_positions = 4 * expected_size
    problem = board.tile_with_set(tileset)
    problem.make_problem()
    a = problem.array
    n_positions, size = a.shape
    assert size == expected_size
    assert n_positions <= max_positions
Exemple #10
0
def test_13_cylinder_problem():
    board = Irregular(make_13_cylinder())
    problem = board.tile_with_many(TETROMINOS["T"])
    problem.make_problem()
    a = problem.array
    assert a.shape[1] == 16 * 13
    assert 16 * 13 < a.shape[0] < 8 * 16 * 13

    col_sums = np.sum(a, 0)
    assert min(col_sums) == 1
    assert max(col_sums) == 16

    row_sums = np.sum(a, 1)
    assert min(row_sums) == 4
    assert max(row_sums) == 4
Exemple #11
0
def test_13_cylinder():
    board = Irregular(make_13_cylinder())
    problem = board.tile_with_many(TETROMINOS["T"])
    solution = problem.solve()
    assert solution is not None
Exemple #12
0
def test_12_x_16_with_irregular():
    board = Irregular([(i, j) for i in range(0, 12) for j in range(0, 16)])
    problem = board.tile_with_many(TETROMINOS["T"])
    solution = problem.solve()
    assert solution is not None
Exemple #13
0
def test_remove_from_irregular():
    squares = [(0, 0), (0, 1), (1, 1), (1, 2), (1, 3)]
    board = Irregular(squares)
    assert set(board.squares) == set(squares)
    trimmed = board.remove((1, 3))
    assert set(trimmed.squares) == set([(0, 0), (0, 1), (1, 1), (1, 2)])
Exemple #14
0
def test_adjusted_square_irregular():
    squares = [(3, -2), (3, -1), (4, -1), (4, 0), (4, 1)]
    board = Irregular(squares)
    expected = [(0, 0), (0, 1), (1, 1), (1, 2), (1, 3)]
    assert board.adjusted == expected
Exemple #15
0
def test_solve_simple_with_negative():
    squares = [(0, -2), (0, -1), (1, -1), (1, 0)]
    problem = Irregular(squares).tile_with_many(DOMINO)
    solution = problem.solve()
    expected = [[(0, -2), (0, -1)], [(1, -1), (1, 0)]]
    assert solution.tiling == expected
Exemple #16
0
def test_solve_impossible_even_to_place_one_tile():
    squares = [(0, 0), (0, 1), (1, 0), (1, 1)]
    problem = Irregular(squares).tile_with_many(TETROMINOS["T"])
    with pytest.raises(PolyominoError):
        solution = problem.solve()
Exemple #17
0
def test_solve_impossible_not_wrong_modulus():
    squares = [(0, 0), (0, 1), (1, 1), (0, 2)]
    problem = Irregular(squares).tile_with_many(DOMINO)
    solution = problem.solve()
    assert solution == None
Exemple #18
0
def test_solve_impossible():
    squares = [(0, 0), (0, 1), (1, 1)]
    with pytest.raises(PolyominoError):
        problem = Irregular(squares).tile_with_many(DOMINO)