-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lambdaman.py
45 lines (32 loc) · 1.15 KB
/
test_lambdaman.py
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
44
45
import pytest
from pathlib import Path
from lambdaman import Grid, find_path
def get_lambdaman_content(num: int) -> str:
content = Path(f"lambdaman/lambdaman{num}").read_text(encoding="utf-8")
content = content.strip()
return content
def get_lambdaman_solution(num: int) -> str:
solution_file = Path(f"lambdaman/lambdaman{num}_solution")
if not solution_file.exists():
return ""
return solution_file.read_text(encoding="utf-8")
def test_repr():
grid_str = "#####\n#L..#\n#...#\n#####\n"
grid = Grid(grid_str)
assert str(grid) == grid_str
def test_example_walk():
grid = Grid("###.#...\n...L..##\n.#######")
end_grid = grid.walk_path("LLLDURRRUDRRURR")
assert end_grid.is_solved()
@pytest.mark.parametrize("i", range(9, 22))
@pytest.mark.timeout(60)
def test_lambdaman(i: int):
cont = get_lambdaman_content(i)
grid = Grid(cont)
sol = get_lambdaman_solution(i)
if not sol:
sol = find_path(grid, shortest=False)
solution_file = Path(f"lambdaman/lambdaman{i}_solution")
solution_file.write_text(sol, encoding="utf-8")
else:
assert grid.walk_path(sol).is_solved()