def __init__(self, cube_face_input: List[CubieItem], cube_side_length: int): """Initialize one cube face. :param cube_face_input: The input needed to fill in the cube face. :param cube_side_length: The desired side length of the cube. """ # Error check. The input length should be cube face size times 4. assert len(cube_face_input) == cube_side_length ** 2 * CUBIE_LENGTH, \ WRONG_CUBE_FACE_INPUT # Save the cube side length. self._side_length = cube_side_length # Split the cube face input to chunks with length of 4. face_input_list = [ cube_face_input[index:index + 4] for index in range(0, len(cube_face_input), 4) ] # Create a list of cubies. face_input_cubie_list = [ Cubie(cubie_input=cubie_input) for cubie_input in face_input_list ] # Fill in the cube face matrix with the cubies. self._face_cubie_frame = pd.DataFrame( data=np.array_split(ary=face_input_cubie_list, indices_or_sections=cube_side_length), index=self.get_frame_index(cube_side_length=cube_side_length), columns=self.get_frame_column(cube_side_length=cube_side_length))
def test_cube_fill_col(self): # Create new testing cube face since the value get changed. cube_face = Face(cube_face_input=self.face_input, cube_side_length=3) cube_face.fill_col( col_name="R1", input_list=[ Cubie([CubieItem(content="1", marked=False) for _ in range(4)]), Cubie([CubieItem(content="1", marked=False) for _ in range(4)]), Cubie([CubieItem(content="1", marked=False) for _ in range(4)]) ]) # Get cols and check if they contain desired value. col_r1 = cube_face.get_col(col_name="R1") assert col_r1[0].get_content_string() == "1111" col_l1 = cube_face.get_col(col_name="L1") assert col_l1[0].get_content_string() == "0001"
def test_cube_fill_row(self): # Create new testing cube face since the value get changed. cube_face = Face(cube_face_input=self.face_input, cube_side_length=3) cube_face.fill_row( row_name="T1", input_list=[ Cubie([CubieItem(content="1", marked=False) for _ in range(4)]), Cubie([CubieItem(content="1", marked=False) for _ in range(4)]), Cubie([CubieItem(content="1", marked=False) for _ in range(4)]) ]) # Get rows and check if they contain desired value. row_t1 = cube_face.get_row(row_name="T1") assert row_t1[0].get_content_string() == "1111" row_d1 = self.cube_face.get_row(row_name="D1") assert row_d1[0].get_content_string() == "1010"
def test_rotate(self): try: Cubie(cubie_input=[ CubieItem(content=content, marked=False) for content in "1010" ]).rotate_by_angle(angle=123) raise AssertionError("Error message did not raise.") except AssertionError as error: assert str(error) == WRONG_ROTATION_ANGLE
def test_fill_col(self): try: self.cube_face.fill_col( col_name="R1", input_list=[Cubie(cubie_input=list("0000"))]) raise AssertionError("Error message did not raise.") except AssertionError as error: assert str(error) == WRONG_SIDE_LENGTH try: self.cube_face.fill_col(col_name="abracadabra", input_list=[ Cubie(cubie_input=list("0000")), Cubie(cubie_input=list("0000")), Cubie(cubie_input=list("0000")) ]) raise AssertionError("Error message did not raise.") except AssertionError as error: assert str(error) == WRONG_FRAME_COLUMN_NAME
class TestCubie: # Setup testing input. CubieItem(content="0", marked=False) cubie = Cubie(cubie_input=[ CubieItem(content=content, marked=False) for content in "1010" ]) def test_get_content(self): assert self.cubie.get_content() == [ CubieItem(content=content, marked=False) for content in "1010" ] def test_get_content_string(self): assert self.cubie.get_content_string() == "1010" def test_rotation(self): self.cubie.rotate_by_angle(angle=90) assert self.cubie.get_content_string() == "0101" def test_get_rotation(self): assert self.cubie == self.cubie.get_rotate_by_angle(angle=90)
def test_init(self): try: Cubie(cubie_input=list("abracadabra")) raise AssertionError("Error message did not raise.") except AssertionError as error: assert str(error) == WRONG_CUBIE_INPUT