Datasets:
Download tests/test_maze.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/tests/test_maze.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/tests/test_maze.py
-
curl -L -o test_maze.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/tests/test_maze.py
1.91 kB
| import numpy as np | |
| from robotics.bench import trackD | |
| from robotics.benchmarks import maze_text as mt | |
| def test_text_maze_validator_accepts_all_shortest_paths(): | |
| suite = mt.suite() | |
| assert len(suite) == 40 | |
| for inst in suite: | |
| wall = np.array([[ch == "#" for ch in row] for row in inst["grid"]]) | |
| d = trackD.bfs(~wall, tuple(inst["goal"])) | |
| r, c = inst["start"] | |
| path = "" | |
| while (r, c) != tuple(inst["goal"]): | |
| mv = next(m for m, (dr, dc) in mt.MOVES.items() if d[r + dr, c + dc] == d[r, c] - 1) | |
| path += mv | |
| r, c = r + mt.MOVES[mv][0], c + mt.MOVES[mv][1] | |
| v = mt.validate(inst, path) | |
| assert v["solved"] and v["n_moves"] == inst["optimal"] | |
| def test_text_maze_validator_rejects_and_explains(): | |
| inst = mt.suite(n_per_size=1)[0] | |
| assert "no 'PATH" in mt.validate(inst, None)["error"] | |
| bad = mt.validate(inst, "UUUUUUUUUUUU") | |
| assert not bad["solved"] and ("hits a wall" in bad["error"] or "not at the goal" in bad["error"]) | |
| assert mt.parse("thinking...\nPATH: R, R -> D d\n") == "RRDD" | |
| def test_mazes_are_connected_and_deterministic(): | |
| G1, G2 = trackD.make_maze(8, 8, seed=3), trackD.make_maze(8, 8, seed=3) | |
| assert (G1 == G2).all() | |
| d = trackD.bfs(G1 == 0, (1, 1)) | |
| assert (d[G1 == 0] >= 0).all() # every free cell reachable | |
| def test_clean_swarm_shares_maps_and_race_map_matches_oracle_without_liars(): | |
| solo = trackD.episode(7, "none", 0, "solo") | |
| race = trackD.episode(7, "none", 0, "race_map") | |
| oracle = trackD.episode(7, "none", 0, "REF oracle") | |
| assert race["spl"] >= solo["spl"] and abs(race["spl"] - oracle["spl"]) < 0.05 | |
| def test_race_map_inverts_liars_better_than_majority(): | |
| gaps = [trackD.episode(s, "invert", 4, "race_map")["spl"] - trackD.episode(s, "invert", 4, "majority")["spl"] for s in (0, 1, 2)] | |
| assert np.mean(gaps) > 0.1 | |