def check_unifier(full_shapes, unique_shapes): full_keys = [repr(shape) for shape in full_shapes] all_orientations = [] for base_shape in unique_shapes: all_orientations.extend(get_all_orientations(base_shape)) for key in all_orientations: if key not in full_keys: print('Shape was not in original list!') print(Shape(key)) for key in full_keys: if key not in all_orientations: print('Shape not a rotation of unified list!') print(Shape(key))
def get_all_orientations(shape): all_orientations = [] for _ in range(0, 4): key = shape.rotate() all_orientations.append(key) shape = Shape(key) shape = Shape(shape.flip()) for _ in range(0, 4): key = shape.rotate() all_orientations.append(key) shape = Shape(key) return all_orientations
def test_long_drop(self): shape = Shape('#...:...#:.#..:..#.') left, right = shape.cut() assert left == '...#:..#.:....:....' assert right == '#...:.#..:....:....'
def test_scaffolding_prevents_drop(self): shape = Shape('#.#.:...#:....:....') left, right = shape.cut() assert left == '..#.:...#:....:....' assert right == '#...:....:....:....'
def test_repr(self): key = '##.#:..#.:....:....' shape = Shape(key) assert repr(shape) == key
def test_stack_angle(self): bottom = Shape('##..:....:....:....') top = Shape('.##.:....:....:....') merged = bottom.stack(top) assert merged == '##..:.##.:....:....'
def test_stack_tall(self): bottom = Shape('#...:#...:....:....') top = Shape('#...:#...:....:....') merged = bottom.stack(top) assert merged == '#...:#...:#...:#...'
def test_diagonal(self): bottom = Shape('...#:....:....:....') top = Shape('.#..:....:....:....') merged = bottom.stack(top) assert merged == '.#.#:....:....:....'
def test_logo(self): left_half = Shape('...#:..#.:....:....') right_half = Shape('##..:....:....:....') logo = left_half.stack(right_half) assert logo == '##.#:..#.:....:....'
def test_tetris(self): bottom = Shape('.##.:..#.:..#.:....') top = Shape('.#..:.##.:....:....') merged = bottom.stack(top) assert merged == '.##.:..#.:.##.:.##.'
def test_trim_to_four_layers(self): bottom = Shape('#...:#...:...#:....') top = Shape('####:...#:....:....') merged = bottom.stack(top) assert merged == '#...:#...:...#:####'
def test_long_drop(self): bottom = Shape('#...:#...:#...:#...') top = Shape('.#..:....:....:....') merged = bottom.stack(top) assert merged == '##..:#...:#...:#...'
def test_staircase(self): bottom = Shape('#..#:##..:....:....') top = Shape('.##.:..##:....:....') merged = bottom.stack(top) assert merged == '#..#:##..:.##.:..##'
def test_stack_merge_on_second_layer(self): bottom = Shape('##..:#...:....:....') top = Shape('.##.:....:....:....') merged = bottom.stack(top) assert merged == '##..:###.:....:....'
def test_no_empty_shape(self): empty = Shape('....:....:....:....') with pytest.raises(ValueError): empty.stack(empty)
def test_simple_merge(self): bottom = Shape('##..:....:....:....') top = Shape('..##:....:....:....') merged = bottom.stack(top) assert merged == '####:....:....:....'
def test_spiral(self): shape = Shape('#...:.#..:..#.:...#') rotated = shape.rotate() assert rotated == '.#..:..#.:...#:#...'
def test_stack_full_layers(self): bottom = Shape('####:....:....:....') top = Shape('####:....:....:....') merged = bottom.stack(top) assert merged == '####:####:....:....'
def test_vertical(self): shape = Shape('..##:....:....:....') left, right = shape.cut() assert left == '..##:....:....:....' assert right == '....:....:....:....'
impossible = [] rest = buildable_shapes[:] n = 0 while len(rest) > 0: try_shape = all_shapes.pop(0) if rest[0] == try_shape: _ = rest.pop(0) else: impossible.append(try_shape) short_keys = [ ':'.join(shape[i:i + 4] for i in range(0, 16, 4)) for shape in impossible ] impossible_shapes = [Shape(k) for k in short_keys] # No floating layers impossible_shapes = [ shape for shape in impossible_shapes if not ((not any(shape.layers[1]) and (any(shape.layers[2]) or any(shape.layers[3]))) or (not any(shape.layers[2]) and any(shape.layers[3]))) ] layers_2 = [ s for s in impossible_shapes if not any(s.layers[3]) and not any(s.layers[2]) ] layers_3 = [
def test_horizontal(self): shape = Shape('#..#:....:....:....') left, right = shape.cut() assert left == '...#:....:....:....' assert right == '#...:....:....:....'
def test_two_layers(self): shape = Shape('####:####:....:....') left, right = shape.cut() assert left == '..##:..##:....:....' assert right == '##..:##..:....:....'
def test_str(self): key = '##.#:..#.:.##.:##..' pretty = str(Shape(key)) assert pretty == """