Spaces:
Runtime error
Runtime error
| """Fast dependency-free checks for cube transition and solver correctness.""" | |
| # The Space supplies Gradio; load only the dependency-free cube core for local checks. | |
| namespace = {} | |
| source = open("app.py", encoding="utf-8").read().split("\nwith gr.Blocks", 1)[0] | |
| # The cube mechanics live before tensor/model definitions and need no Space packages. | |
| source = source.split("\ndef state_tensor", 1)[0] | |
| for statement in ("import spaces # Must precede torch: ZeroGPU patches CUDA placement at import time.\n", "import torch\n", "from torch import nn\n", "import torch.nn.functional as F\n", "import gradio as gr\n"): | |
| source = source.replace(statement, "") | |
| exec(source, namespace) | |
| INVERSE = namespace["INVERSE"] | |
| MOVES = namespace["MOVES"] | |
| SOLVED = namespace["SOLVED"] | |
| apply_moves = namespace["apply_moves"] | |
| random_scramble = namespace["random_scramble"] | |
| def test_turn_order_and_inverse() -> None: | |
| for move in MOVES: | |
| assert apply_moves(SOLVED, [move] * 4) == SOLVED | |
| assert apply_moves(SOLVED, [move, INVERSE[move]]) == SOLVED | |
| def test_reverse_scramble_returns_to_solved() -> None: | |
| scramble = random_scramble(6, __import__("random").Random(31)) | |
| state = apply_moves(SOLVED, scramble) | |
| solution = [INVERSE[move] for move in reversed(scramble)] | |
| assert apply_moves(state, solution) == SOLVED | |
| if __name__ == "__main__": | |
| test_turn_order_and_inverse() | |
| test_reverse_scramble_returns_to_solved() | |
| print("cube checks passed") | |