def gen_orthogonal(n, i): sticker_matrix = [[ Sticker(FaceEnum.FRONT, OrientEnum.UP) for _ in range(n) ] for _ in range(i)] for _ in range(n - i): sticker_matrix.append( [Sticker(FaceEnum.BACK, OrientEnum.DOWN) for _ in range(n)]) return just(Face(n, flatten(sticker_matrix)))
def rotate_ccw_test(self): ccw_sticker_mat = [] s00 = Sticker(FaceEnum.FRONT, OrientEnum.UP) s01 = Sticker(FaceEnum.RIGHT, OrientEnum.RIGHT) s02 = Sticker(FaceEnum.BACK, OrientEnum.DOWN) ccw_sticker_mat.append([s00, s01, s02]) s10 = Sticker(FaceEnum.LEFT, OrientEnum.LEFT) s11 = Sticker(FaceEnum.UP, OrientEnum.UP) s12 = Sticker(FaceEnum.DOWN, OrientEnum.RIGHT) ccw_sticker_mat.append([s10, s11, s12]) s20 = Sticker(FaceEnum.FRONT, OrientEnum.DOWN) s21 = Sticker(FaceEnum.RIGHT, OrientEnum.LEFT) s22 = Sticker(FaceEnum.BACK, OrientEnum.UP) ccw_sticker_mat.append([s20, s21, s22]) ccw_comp_face = Face(*N_and_flatten(ccw_sticker_mat)) sticker_mat = [] sticker_row = [s20, s10, s00] sticker_mat.append([deepcopy(s).rotate_cw() for s in sticker_row]) sticker_row = [s21, s11, s01] sticker_mat.append([deepcopy(s).rotate_cw() for s in sticker_row]) sticker_row = [s22, s12, s02] sticker_mat.append([deepcopy(s).rotate_cw() for s in sticker_row]) comp_face = Face(*N_and_flatten(sticker_mat)) assert (comp_face.rotate_ccw() == ccw_comp_face ), f"failed for {str(comp_face)}\n{repr(comp_face)}"
def stickers_and_face(self): s1 = Sticker(FaceEnum.FRONT, OrientEnum.UP) s2 = Sticker(FaceEnum.BACK, OrientEnum.RIGHT) s3 = Sticker(FaceEnum.LEFT, OrientEnum.DOWN) stickers = [s1, s2, s3] cs = Sticker(FaceEnum.RIGHT, OrientEnum.LEFT) face_stickers = [] face_stickers.append([cs, s1, cs]) face_stickers.append([s1, s2, s3]) face_stickers.append([cs, s3, cs]) return stickers, Face(*N_and_flatten(face_stickers))
def rotate_ht_test(self): stickers = self.stickers() orig_slice = RowFaceSlice(stickers) face_slice = RowFaceSlice(deepcopy(stickers)).rotate_ht() assert isinstance(face_slice, RowFaceSlice) err_str = f"\n{repr(orig_slice)})\nto\n{repr(face_slice)}" sol_stickers = face_slice.stickers assert sol_stickers[0] == Sticker(FaceEnum.LEFT, OrientEnum.UP), err_str assert sol_stickers[1] == Sticker(FaceEnum.BACK, OrientEnum.LEFT), err_str assert sol_stickers[2] == Sticker(FaceEnum.FRONT, OrientEnum.DOWN), err_str
def face(self, stickers): s1, s2, s3 = stickers cs = Sticker(FaceEnum.RIGHT, OrientEnum.LEFT) face_stickers = [] face_stickers.append([cs, s1, cs]) face_stickers.append([s1, s2, s3]) face_stickers.append([cs, s3, cs]) return Face(face_stickers)
def front_face(self): sticker_matrix = [] for i in range(3): row = [Sticker(FaceEnum.FRONT, OrientEnum.UP) for _ in range(3)] sticker_matrix.append(row) return Face(*N_and_flatten(sticker_matrix))
def gen_c2_minus_c4_faces_4(): stickers = [ [ Sticker(FaceEnum.BACK, OrientEnum.DOWN), Sticker(FaceEnum.FRONT, OrientEnum.UP), Sticker(FaceEnum.FRONT, OrientEnum.UP), Sticker(FaceEnum.BACK, OrientEnum.DOWN), ], [ Sticker(FaceEnum.BACK, OrientEnum.DOWN), Sticker(FaceEnum.FRONT, OrientEnum.UP), Sticker(FaceEnum.FRONT, OrientEnum.UP), Sticker(FaceEnum.BACK, OrientEnum.DOWN), ], [ Sticker(FaceEnum.BACK, OrientEnum.UP), Sticker(FaceEnum.FRONT, OrientEnum.DOWN), Sticker(FaceEnum.FRONT, OrientEnum.DOWN), Sticker(FaceEnum.BACK, OrientEnum.UP), ], [ Sticker(FaceEnum.BACK, OrientEnum.UP), Sticker(FaceEnum.FRONT, OrientEnum.DOWN), Sticker(FaceEnum.FRONT, OrientEnum.DOWN), Sticker(FaceEnum.BACK, OrientEnum.UP), ], ] return just(Face(4, flatten(stickers)))
def test_repr(self, face_enum, orient_enum): sticker = Sticker(face_enum, orient_enum) sticker_repr = repr(sticker) orient_repr = repr(orient_enum) assert orient_repr in sticker_repr
def test_str(self, face_enum, orient_enum): sticker = Sticker(face_enum, orient_enum) gold = f"Sticker({face_enum}, {orient_enum})" assert str(sticker) == gold
def rotate_ht_test(self): sticker = Sticker(FaceEnum.FRONT, OrientEnum.UP) sticker.rotate_ht() assert sticker.init_face_enum == FaceEnum.FRONT assert sticker.orient_enum == OrientEnum.DOWN
def construction_test(self, face_enum, orient_enum): Sticker(face_enum, orient_enum)
def stickers(self): s1 = Sticker(FaceEnum.FRONT, OrientEnum.UP) s2 = Sticker(FaceEnum.BACK, OrientEnum.RIGHT) s3 = Sticker(FaceEnum.LEFT, OrientEnum.DOWN) return [s1, s2, s3]