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
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
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
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
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)
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)
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])
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)])
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
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
def test_13_cylinder(): board = Irregular(make_13_cylinder()) problem = board.tile_with_many(TETROMINOS["T"]) solution = problem.solve() assert solution is not None
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
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)])
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
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
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()
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
def test_solve_impossible(): squares = [(0, 0), (0, 1), (1, 1)] with pytest.raises(PolyominoError): problem = Irregular(squares).tile_with_many(DOMINO)