예제 #1
0
def test_problem_with_no_mandatory_tiles():
    tileset = Tileset([], ALL_PENTOMINOS, [DOMINO])
    board = Rectangle(20, 20)
    problem = board.tile_with_set(tileset)
    problem.make_problem()
    a = problem.array
    assert a is not None
예제 #2
0
def test_remove_from_rectangle():
    board = Rectangle(2, 3)
    assert set(board.squares) == set([(0, 0), (1, 0), (0, 1), (1, 1), (0, 2),
                                      (1, 2)])
    trimmed = board.remove((1, 1))
    assert set(trimmed.squares) == set([(0, 0), (1, 0), (0, 1), (0, 2),
                                        (1, 2)])
예제 #3
0
def test_not_a_single_tile_fits():
    tile = [(0, 0), (1, 0), (2, 0), (3, 0)]
    tileset = many(tile)
    board = Rectangle(2, 2)
    with pytest.raises(PolyominoError):
        problem = board.tile_with_set(tileset)
        problem.make_problem()
예제 #4
0
def test_simple_problem_check_array():
    tile = TETROMINOS["T"]
    tileset = many(tile).and_repeated_exactly(3, MONOMINO)
    board = Rectangle(3, 5)
    problem = board.tile_with_set(tileset)
    problem.make_problem()
    a = problem.array
    assert a.shape == (65, 18)
    expected_sums = np.array([2] * 45 + [4] * 20)
    np.testing.assert_array_equal(a.sum(axis=1), expected_sums)
예제 #5
0
def test_right_number_of_tile_positions(l, x, y):
    assume(l < x and l < y)
    assume(x * y % l == 0)
    tile = [(0, i) for i in range(0, l)]
    tileset = many(tile)
    board = Rectangle(x, y)
    size = x * y
    n_positions = (x - l + 1) * y + x * (y - l + 1)
    problem = board.tile_with_set(tileset)
    problem.make_problem()
    a = problem.array
    assert a.shape == (n_positions, size)
예제 #6
0
def test_tile_chessboard():
    board = Rectangle(8, 8)
    TILES = list(PENTOMINOS.values()) + [TETROMINOS["Square"]]
    problem = TilingProblem(board, exactly(TILES))
    solution = problem.solve()
    actual = solution.tiling
    assert len(actual) == 13
예제 #7
0
def test_export_to_python():
    board = Rectangle(4, 4)
    tiling = [
        [(0, 0), (0, 1), (0, 2), (0, 3)],
        [(1, 0), (1, 1), (1, 2), (1, 3)],
        [(2, 0), (2, 1), (2, 2), (2, 3)],
        [(3, 0), (3, 1), (3, 2), (3, 3)],
    ]
    solution = Solution(tiling, board)
    with open("tests/temp.py", "w") as out:
        out.write(solution.python())
    from tests.temp import TILING

    assert TILING == tiling
예제 #8
0
def test_tile_chessboard_check_problem():
    board = Rectangle(8, 8)
    TILES = list(PENTOMINOS.values()) + [TETROMINOS["Square"]]
    problem = TilingProblem(board, exactly(TILES))
    problem.make_problem()

    assert 37 * 16 < problem.array.shape[0] < 4 * 49 * 13
    assert problem.array.shape[1] == 77

    row_sums = np.sum(problem.array, 1)
    assert min(row_sums) == 5
    assert max(row_sums) == 6

    assert len(problem.key) == problem.array.shape[0]
예제 #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
예제 #10
0
def test_not_enough_tiles():
    board = Rectangle(3, 3)
    tile = TETROMINOS["T"]
    tileset = Tileset([tile, tile], [], [])
    with pytest.raises(CoverWithWrongSize):
        tileset.check(board)
예제 #11
0
def test_optional_tiles():
    tileset = Tileset([], ALL_PENTOMINOS, [DOMINO])
    board = Rectangle(20, 20)
    tileset.check(board)
예제 #12
0
def test_error_if_removing_not_present():
    board = Rectangle(2, 3)
    assert set(board.squares) == set([(0, 0), (1, 0), (0, 1), (1, 1), (0, 2),
                                      (1, 2)])
    with pytest.raises(Exception):
        board.remove((2, 4))
예제 #13
0
def test_too_many_tiles():
    board = Rectangle(3, 4)
    tile = TETROMINOS["T"]
    tileset = Tileset([tile] * 4, [], [])
    with pytest.raises(CoverWithWrongSize):
        tileset.check(board)
예제 #14
0
def test_tile_chessboard_minus_square(x, y):
    board = Rectangle(8, 8).remove_all([(x, y), (x + 1, y), (x, y + 1), (x + 1, y + 1)])
    problem = TilingProblem(board, exactly(ALL_PENTOMINOS).with_reflections())
    solution = problem.solve()
    actual = solution.tiling
    assert len(actual) == 12
예제 #15
0
def test_tile_with_many_size_check():
    board = Rectangle(8, 8).remove((0, 0))
    with pytest.raises(Exception):
        board.tile_with_many([(0, 0), (1, 0)])
예제 #16
0
def test_wrong_gcd():
    board = Rectangle(3, 3)
    tile = TETROMINOS["T"]
    tileset = Tileset([], [], [tile])
    with pytest.raises(CoverWithWrongModulus):
        tileset.check(board)
예제 #17
0
def test_4_square():
    board = Rectangle(4, 4)
    problem = board.tile_with_many(TETROMINOS["T"])
    solution = problem.solve()
    assert solution is not None