def test_multiple(actions, expected):
    a = parse_actions(actions)
    b = parse_actions(expected)
    actual = []

    pp = OptimizingPostprocessor()
    pp.callback = actual.append
    for x in a:
        pp.process(x)
    pp.done()

    assert all(repr(x) == repr(y) for x, y in zip_longest(actual, b))
Exemple #2
0
def test_cube_flip_flop():
    cube = Cube((3, 3, 3))
    assert_cube(cube, "RRR/RRR/RRR", "GGG/GGG/GGG", "OOO/OOO/OOO",
                "BBB/BBB/BBB", "YYY/YYY/YYY", "WWW/WWW/WWW")

    for action in parse_actions("RUR'U'"):
        action.perform(cube, Orientation())
    assert_cube(cube, "RRW/RRY/RRR", "GGY/OGG/YGG", "OGG/OOO/OOO",
                "OBB/BBB/BBB", "YYB/YYR/YYR", "WWG/WWW/WWW")

    for _ in range(5):
        for action in parse_actions("RUR'U'"):
            action.perform(cube, Orientation())
    assert_cube(cube, "RRR/RRR/RRR", "GGG/GGG/GGG", "OOO/OOO/OOO",
                "BBB/BBB/BBB", "YYY/YYY/YYY", "WWW/WWW/WWW")
Exemple #3
0
def test_orient_not_matching_side():
    cube = Cube((3, 3, 3))
    for action in parse_actions("RUR'U'"):
        action.perform(cube, Orientation())
    match = cube.orient(Orientation(),
                        front=Pattern([[Color.WHITE, Color.GREEN, None],
                                       [None, None, None], [None, None,
                                                            None]]))
    assert match is None
Exemple #4
0
def test_rotation():
    actions = list(parse_actions("X X' Y' Z2"))
    expected_sides = [Side.RIGHT, Side.LEFT, Side.BOTTOM, Side.FRONT]
    expected_twice = [False, False, False, True]

    assert len(actions) == len(expected_sides)
    for action, side, twice in zip(actions, expected_sides, expected_twice):
        assert isinstance(action, Rotate)
        assert action.twice == twice
        assert action.axis_side == side
Exemple #5
0
def test_turn_single(text: str, type: TurningType, indices: int, turns: int):
    actions = list(parse_actions(text))
    assert len(actions) == 1
    action = actions[0]
    assert isinstance(action, Turn)
    assert action.indices == indices
    assert action.turns == turns
    assert action.type == type

    assert text == str(action)
def run_test(seed, filename, dimension):
    scramble = subprocess.check_output(
        ["python", "-m", "cubelang.scrambler", "-d", str(dimension),
         "-s", str(seed)])

    scramble = scramble.decode(stdout.encoding).strip()

    cube = Cube((dimension, dimension, dimension))
    orientation = Orientation()
    for action in parse_actions(scramble):
        orientation = action.perform(cube, orientation)

    arguments = ["python", "-m", "cubelang", "-d", str(dimension), "-s", scramble,
                 str(Path(__file__).parents[1] / "examples" / filename)]
    solution = subprocess.check_output(arguments).decode("utf-8")

    for action in parse_actions(solution):
        orientation = action.perform(cube, orientation)
    assert_solved(cube)
Exemple #7
0
def test_orient_not_matching_groups():
    cube = Cube((3, 3, 3))
    for action in parse_actions("RUR'U'"):
        action.perform(cube, Orientation())

    match = cube.orient(Orientation(),
                        front=Pattern([["a", "a", "b"], [None, None, None],
                                       [None, None, None]]),
                        right=Pattern([["a", None, None], [None, None, None],
                                       ["a", None, "b"]]))
    assert match is None
Exemple #8
0
def test_orient_keep():
    cube = Cube((3, 3, 3))
    for action in parse_actions("RUR'U'"):
        action.perform(cube, Orientation())

    match = cube.orient(Orientation(),
                        keeping=Side.LEFT,
                        bottom=Pattern([[Color.WHITE, None, None],
                                        [None, None, None], [None, None,
                                                             None]]))
    assert Orientation(Side.FRONT, Side.TOP) == match
Exemple #9
0
def test_valid_parsing():
    actions = list(parse_actions("R  L2  U' RU L"))
    expected_sides = [
        TurningType.VERTICAL, TurningType.VERTICAL, TurningType.HORIZONTAL,
        TurningType.VERTICAL, TurningType.HORIZONTAL, TurningType.VERTICAL
    ]
    expected_turns = [1, 2, 1, 1, 3, 3]

    assert len(actions) == len(expected_sides)
    for action, type, turns in zip(actions, expected_sides, expected_turns):
        assert isinstance(action, Turn)
        assert action.type == type
        assert action.turns == turns
Exemple #10
0
def test_orient_full():
    cube = Cube((3, 3, 3))
    for action in parse_actions("RUR'U'"):
        action.perform(cube, Orientation())

    match = cube.orient(Orientation(),
                        top=Pattern([[Color.WHITE, None, None],
                                     [None, "a", None], ["a", None, None]]),
                        front=Pattern([[None, None, None],
                                       [None, None, Color.ORANGE],
                                       [None, None, None]]),
                        right=Pattern([[None, None, None],
                                       [Color.YELLOW, None, None],
                                       ["a", None, None]]),
                        back=Pattern([[None, None, None], [None, None, None],
                                      [Color.BLUE, None, None]]),
                        left=Pattern([[None, Color.ORANGE, None],
                                      [None, None, None],
                                      [None, Color.GREEN, None]]),
                        bottom=Pattern([[Color.BLUE, None, Color.RED],
                                        [None, None, None], [None, None,
                                                             None]]))
    assert Orientation(Side.RIGHT, Side.BOTTOM) == match
Exemple #11
0
def test_illegal_parsing(text: str, column: int):
    with pytest.raises(ParsingError) as e:
        parse_actions(text)
    assert e.value.column == column