File size: 1,214 Bytes
ed2ad9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest

import torch

from rubik.cube import Cube
from rubik.display import stringify, pad_colors


@pytest.mark.parametrize(
    "colors, size",
    [
        [["U", "L", "C", "R", "B", "D"], 3],
        [["Up", "Left", "Center", "Right", "Back", "Down"], 5],
        [["A", "BB", "CCC", "DDDD", "EEEEE", "FFFFFF"], 10],
    ],
)
def test_stringify(colors: list[str], size: int):
    """
    Test that stringify behaves as expected.
    """
    cube = Cube(colors=colors, size=size)
    state = cube.state.argmax(dim=-1).to(device="cpu", dtype=torch.int16)
    repr = stringify(state, colors, size)
    lens = {len(line) for line in repr.split("\n")}
    assert len(lens) == 1, f"'stringify' lines have variable length: {lens}"


@pytest.mark.parametrize(
    "colors",
    [
        ["U", "L", "C", "R", "B", "D"],
        ["Up", "Left", "Center", "Right", "Back", "Down"],
        ["A", "BB", "CCC", "DDDD", "EEEEE", "FFFFFF"],
    ],
)
def test_pad_colors(colors: list[str]):
    """
    Test that pad_colors behaves as expected.
    """
    padded = pad_colors(colors)
    lengths = {len(color) for color in padded}
    assert len(lengths) == 1, f"'pad_colors' generates non-unique lengths: {lengths}"