maze-solving-qwen35 / tests /test_experiments.py
peeache's picture
Initial upload of Qwen3.5 maze-solving experiments
4f2951b verified
Raw History Blame Contribute Delete
2.96 kB
"""Pure-Python tests for follow-up experiment prompts and scoring."""
from maze_lab.difficulty import build
from maze_lab.experiments import (cell_queries, extract_unstructured_moves,
normalized_cell_center, parse_cell_answers,
parse_dimensions, parse_grounding_points,
point_to_cell, score_cell_answers, score_point,
score_point_path)
def test_extract_unstructured_moves():
assert extract_unstructured_moves("The path is R, R, D, D.") == "RRDD"
assert extract_unstructured_moves("Try LL. Final route: RRUULL") == "RRUULL"
assert extract_unstructured_moves("['S', 'R', 'R', 'D', 'E']") == "RRD"
assert extract_unstructured_moves("Right, right, down") == "RRD"
assert extract_unstructured_moves("Path: (1,1) → (1,3) → (3,3)") == "RRDD"
assert extract_unstructured_moves("I cannot solve it") is None
def test_cell_queries_are_balanced_and_deterministic():
maze = build(2, 3)
a = cell_queries(maze, seed=203)
b = cell_queries(maze, seed=203)
assert a == b and len(a) == 8 and len(set(a)) == 8
chars = [maze.grid[r][c] for r, c in a]
assert chars.count("S") == 1 and chars.count("E") == 1
assert chars.count("#") == 3 and chars.count(".") == 3
def test_cell_answer_scoring():
maze = build(1, 0)
queries = [maze.start, maze.goal, (0, 0), (1, 2)]
result = score_cell_answers(maze, queries, "START GOAL WALL FLOOR")
assert result["correct"] == result["total"] == 4
assert parse_cell_answers("1. wall, 2. floor", 2) == ["WALL", "FLOOR"]
def test_dimension_parser():
assert parse_dimensions("13 x 13") == (13, 13)
assert parse_dimensions("There are 11 rows and 9 columns.") == (11, 9)
assert parse_dimensions("not sure") is None
def test_grounding_point_parser_and_cell_mapping():
maze = build(1, 0)
target = (3, 5)
center = normalized_cell_center(maze, target, labels=True)
reply = f'[{{"point_2d": [{center[0]}, {center[1]}], "label": "cell"}}]'
assert parse_grounding_points(reply) == [center]
assert point_to_cell(maze, center, labels=True) == target
assert score_point(maze, target, reply, labels=True)["correct"]
def test_point_path_scoring():
maze = build(1, 0)
cells = [maze.start]
pos = maze.start
for move in maze.bfs_path_to_goal(maze.start):
pos, _ = maze.step(pos, move)
cells.append(pos)
reply = "[" + ",".join(
f'{{"point_2d":[{x},{y}]}}'
for x, y in (normalized_cell_center(maze, p, labels=False) for p in cells)
) + "]"
result = score_point_path(maze, reply, labels=False)
assert result["exact_path"] and result["ends_at_e"]
if __name__ == "__main__":
tests = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for test in tests:
test()
print(f" ok {test.__name__}")
print(f"\n{len(tests)} tests passed")