-
Notifications
You must be signed in to change notification settings - Fork 64
/
test_util.py
48 lines (42 loc) · 1.11 KB
/
test_util.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
from pathfinding.core.grid import Grid
from pathfinding.core.util import bresenham, raytrace, smoothen_path
def test_bresenham():
"""
test bresenham path interpolation
"""
assert bresenham([0, 0], [2, 5]) == [
[0, 0], [0, 1],
[1, 2], [1, 3],
[2, 4], [2, 5]
]
assert bresenham([0, 1], [0, 4]) == [
[0, 1], [0, 2], [0, 3], [0, 4]
]
def test_raytrace():
"""
test raytrace path interpolation
"""
assert raytrace([0, 0], [2, 5]) == [
[0, 0], [0, 1],
[1, 1], [1, 2], [1, 3], [1, 4],
[2, 4], [2, 5]
]
assert raytrace([0, 1], [0, 4]) == [
[0, 1], [0, 2], [0, 3], [0, 4]
]
def test_smoothen_path():
matrix = [
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]
]
grid = Grid(matrix=matrix)
path = [
[0, 0], [1, 0], [2, 0], [2, 1], [2, 2], [2, 3], [3, 3], [3, 4], [4, 4]
]
smooth_path = [
[0, 0], [1, 0], [2, 0], [2, 1], [2, 2], [2, 3], [3, 3], [4, 4]
]
assert smoothen_path(grid, path) == smooth_path