def test_got_nothing(self, basic_patch): other_patch = Patch(12345) for i in range(len(basic_patch.characters)): other_patch.add_line("." * len(basic_patch.characters[0])) for base_side in Patch.SIDES: encoding = basic_patch.match(base_side=base_side, other=other_patch) assert encoding is None
def test_construction(self): patch = Patch(12345) patch.add_line(".###..\n") patch.add_line(".#.#..\n") patch.add_line("....##\n") patch.add_line("....#.\n") patch.add_line("....##\n") patch.add_line("#...#.\n") assert patch.tile == 12345 assert patch.characters == [ ".###..", ".#.#..", "....##", "....#.", "....##", "#...#." ] assert patch.position is None assert patch.sides_covered == [] assert patch.sides_ruled_out == []
def test_find_orientation(self, encoding, inverse): characters = [ "..OO.##...", ".##O#...#.", "...#..OO..", "OO...OO.##", ".OOO##O#..", "...O..#..O", "..........", ] patch = Patch.from_chars(characters) patch.apply(**encoding) if inverse is None: encoding["rotations"] = -encoding["rotations"] % 4 inverse = encoding # Only check for the more complex pattern to avoid multiple matches pattern = ["....##", "##.#..", "..#..."] assert PatchMap.find_orientation(patch, pattern) == inverse
def test_complex_case(self, basic_patch): other_patch = Patch(12345) characters = [ "#....#", "......", "......", "......", "#.....", "..#.#." ] for line in characters: other_patch.add_line(line) assert basic_patch.match(base_side=0, other=other_patch) == \ {"base_side": 0, "rotations": 3, "flip": False} assert other_patch.match(base_side=3, other=basic_patch) == \ {"base_side": 3, "rotations": 1, "flip": False} assert basic_patch.match(base_side=2, other=other_patch) == \ {"base_side": 2, "rotations": 0, "flip": True} assert other_patch.match(base_side=0, other=basic_patch) == \ {"base_side": 0, "rotations": 0, "flip": True} assert basic_patch.match(base_side=3, other=other_patch) == \ {"base_side": 3, "rotations": 3, "flip": True} assert other_patch.match(base_side=2, other=basic_patch) == \ {"base_side": 2, "rotations": 1, "flip": True}
def basic_patch(): basic = Patch(2605) characters = [".###..", ".#.#..", "....##", "....#.", "....##", "#...#."] for line in characters: basic.add_line(line) return basic
def test_from_chars(self, basic_patch): patch = Patch.from_chars(basic_patch.characters, basic_patch.tile) assert patch is not basic_patch assert patch.tile == basic_patch.tile assert patch.characters == basic_patch.characters
def make_patch(tile, lines, position): patch = Patch(tile) for line in lines: patch.add_line(line) patch.position = numpy.array(position) patchmap.add(patch)
def test_set_relative_position(self, basic_patch, basic_position, side, expected): basic_patch.position = basic_position other_patch = Patch(12345) other_patch.set_relative_position(basic_patch, side) assert numpy.allclose(other_patch.position, expected)