示例#1
0
class TestCube(unittest.TestCase):
    def setUp(self):
        self.cube = Cube()

    def test_is_completed(self):
        self.assertTrue(self.cube.is_completed)

        self.cube.faces[0].stickers[0] = 'Y'
        self.assertFalse(self.cube.is_completed)
        self.cube.faces[0].stickers[0] = 'W'

    def test_layer_is_completed(self):
        # TODO -> Finish
        with self.assertRaises(InvalidLayerIndexException):
            self.cube.layer_is_completed(-1)
            self.cube.layer_is_completed(3)

        for idx in range(3):
            self.assertTrue(self.cube.layer_is_completed(idx))

    def test___eq__(self):
        new_cube = Cube()
        self.assertTrue(new_cube == self.cube)

        new_cube.faces[0].stickers[0] = 'Y'
        self.assertFalse(new_cube == self.cube)
示例#2
0
    def test_turn_up(self):
        # TODO -> improve
        def swap_faces(cube):
            faces = cube.faces
            new_faces = [
                faces[1], faces[5], faces[2], faces[0], faces[4], faces[3]
            ]
            cube.faces = new_faces

        # Simple test
        new_cube = Cube()
        swap_faces(new_cube)

        test_cube = Cube()
        test_cube.moves.turn_up()

        self.assertTrue(test_cube == new_cube)

        # Complexe test
        new_cube = Cube()
        self._prepare_cube(new_cube)

        swap_faces(new_cube)
        new_cube.faces[4].rotate_anti_clockwise()
        new_cube.faces[2].rotate_clockwise()

        test_cube = Cube()
        self._prepare_cube(test_cube)
        test_cube.moves.turn_up()

        self.assertTrue(test_cube == new_cube)
示例#3
0
    def test_turn_right(self):
        # TODO -> improve
        new_cube = Cube()
        faces = new_cube.faces
        new_faces = [
            faces[4], faces[1], faces[0], faces[3], faces[5], faces[2]
        ]
        new_cube.faces = new_faces

        test_cube = Cube()
        test_cube.moves.turn_right()

        self.assertTrue(test_cube == new_cube)
示例#4
0
    def test__turn(self):
        # TODO -> improve
        new_cube = Cube()
        faces = new_cube.faces
        new_faces = [
            faces[2], faces[1], faces[5], faces[3], faces[0], faces[4]
        ]
        new_cube.faces = new_faces

        test_cube = Cube()
        test_cube.moves._turn(0, 2, 5, 4)

        self.assertTrue(test_cube == new_cube)
示例#5
0
    def test__swap_right(self):
        faces = [0, 3, 5, 1]
        new_cube = Cube()
        new_cube.moves._swap_right(*faces)

        test_cube = Cube()
        test_cube.faces[0].stickers[2:9:3] = ['O'] * 3
        test_cube.faces[3].stickers[2:9:3] = ['Y'] * 3
        test_cube.faces[5].stickers[2:9:3] = ['R'] * 3
        test_cube.faces[1].stickers[2:9:3] = ['W'] * 3
        self.assertTrue(test_cube == new_cube)

        faces = [0, 1, 5, 3]
        new_cube.moves._swap_right(*faces)
        self.assertTrue(new_cube == self.cube)
示例#6
0
    def test__swap_bot(self):
        faces = [4, 0, 2, 5]
        new_cube = Cube()
        new_cube.moves._swap_bot(*faces)

        test_cube = Cube()
        test_cube.faces[4].stickers[-3:] = ['W'] * 3
        test_cube.faces[0].stickers[-3:] = ['B'] * 3
        test_cube.faces[2].stickers[-3:] = ['Y'] * 3
        test_cube.faces[5].stickers[-3:] = ['G'] * 3
        self.assertTrue(test_cube == new_cube)

        faces = [4, 5, 2, 0]
        new_cube.moves._swap_bot(*faces)
        self.assertTrue(new_cube == self.cube)
示例#7
0
    def _init_front_cube(self):
        cube = Cube()
        cube.faces[1].stickers[:3] = ['B'] * 3
        cube.faces[2].stickers[0:7:3] = ['O'] * 3
        cube.faces[3].stickers[-3:] = ['G'] * 3
        cube.faces[4].stickers[2:9:3] = ['R'] * 3

        return cube
示例#8
0
    def _init_cube(self):
        cube = Cube()
        stickers = [['W', 'Y', 'W', 'Y', 'W', 'Y', 'W', 'Y', 'W'],
                    ['R', 'O', 'R', 'O', 'R', 'O', 'R', 'O', 'R'],
                    ['B', 'G', 'B', 'G', 'B', 'G', 'B', 'G', 'B'],
                    ['O', 'R', 'O', 'R', 'O', 'R', 'O', 'R', 'O'],
                    ['G', 'B', 'G', 'B', 'G', 'B', 'G', 'B', 'G'],
                    ['Y', 'W', 'Y', 'W', 'Y', 'W', 'Y', 'W', 'Y']]

        for idx in range(6):
            cube.faces[idx].stickers = stickers[idx]

        return cube
示例#9
0
    def test___eq__(self):
        new_cube = Cube()
        self.assertTrue(new_cube == self.cube)

        new_cube.faces[0].stickers[0] = 'Y'
        self.assertFalse(new_cube == self.cube)
示例#10
0
 def setUp(self):
     self.cube = Cube()
示例#11
0
 def test__face_inverter(self):
     cube = Cube()
     cube.faces[0].stickers = ['W', 'R', 'B', 'O', 'G', 'Y', 'G', 'O', 'B']
     _face_invertion(cube, 0)
     self.assertTrue(cube.faces[0].stickers ==
                     ['B', 'O', 'G', 'Y', 'G', 'O', 'B', 'R', 'W'])
示例#12
0
 def setUp(self):
     self.cube = Cube()
     self.moves = Moves(self.cube)
示例#13
0
    def test_mv_front_anti_clockwise(self):
        cube = Cube()
        test_cube = self._init_front_cube()
        test_cube.moves.mv_front_anti_clockwise()

        self.assertEqual(test_cube, cube)
示例#14
0
def test_rotate():
    cube = Cube()
    rot = CubicRotation.ry
    cube.rotate(rot)
    assert np.array_equal(cube.rotation.apply(X), -Z)
    assert np.array_equal(cube.rotation.apply(Y), Y)
示例#15
0
def test_get_color_on_face():
    cube = Cube()
    for face in FACE_ORDER:
        assert cube.get_color_on_face(face) == face
    cube.rotate(CubicRotation.ry)
    assert cube.get_color_on_face("F") == "L"
    assert cube.get_color_on_face("B") == "R"
    assert cube.get_color_on_face("U") == "U"
    assert cube.get_color_on_face("D") == "D"
    assert cube.get_color_on_face("L") == "B"
    assert cube.get_color_on_face("R") == "F"
    cube.rotate(CubicRotation.rx)
    assert cube.get_color_on_face("F") == "U"
    assert cube.get_color_on_face("R") == "F"
    assert cube.get_color_on_face("B") == "D"
示例#16
0
from rubiks_cube.display.cube_2d_display import Cube2DDisplay
from rubiks_cube.display.sequence_2d_display import Sequence2DDisplay
from rubiks_cube.cube import Cube
from rubiks_cube.moves import Moves

import random

if __name__ == '__main__':
    cube = Cube()

    move_sequence = [random.choice(Moves.LETTERS) for _ in range(20)]
    cube_display = Sequence2DDisplay(cube)
    cube_display.display(move_sequence)