Spaces:
Sleeping
Sleeping
import pytest | |
import torch | |
from rubik.cube import Cube | |
from rubik.display import stringify, pad_colors | |
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}" | |
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}" | |