-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_spaceship.py
58 lines (43 loc) · 1.46 KB
/
test_spaceship.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
46
47
48
49
50
51
52
53
54
55
56
57
58
from pathlib import Path
import pytest
from spaceship import Spaceship, is_subseq
def get_spaceship_content(num: int) -> list[tuple[int, int]]:
content = Path(f"spaceship/spaceship{num}").read_text(encoding="utf-8")
content = content.strip()
lines = [line.split() for line in content.splitlines()]
points = [(int(p[0]), int(p[1])) for p in lines]
return points
def get_spaceship_solution(num: int) -> str:
solution_file = Path(f"spaceship/spaceship{num}_solution")
if not solution_file.exists():
return ""
return solution_file.read_text(encoding="utf-8")
def test_example():
path = [(0, 0), (0, -1), (1, -3), (3, -5), (6, -7), (9, -9), (13, -10)]
dirs = "236659"
end_ship = Spaceship().walk_path(dirs)
assert end_ship.path == path
def test_subpath():
path: list[tuple[int, int]] = [
(0, 0),
(0, -1),
(1, -3),
(3, -5),
(6, -7),
(9, -9),
(13, -10),
]
subpath: list[tuple[int, int]] = [(0, 0), (6, -7)]
assert is_subseq(path, subpath)
@pytest.mark.parametrize("i", range(1, 11))
def test_spaceship(i: int):
cont = get_spaceship_content(i)
sol = get_spaceship_solution(i)
if not sol:
pass
# # record
# sol = find_path(cont)
# solution_file = Path(f"spaceship/spaceship{i}_solution")
# solution_file.write_text(sol, encoding="utf-8")
else:
assert is_subseq(Spaceship().walk_path(sol).path, cont)