FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-pathfinding/test/grid_test.py at python2 · brean/python-pathfinding · GitHub
brean
/
python-pathfinding
Public
Notifications
You must be signed in to change notification settings
Fork
73
Star
383
Code
Issues
24
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-pathfinding
/
test
/
grid_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (68 loc) · 1.51 KB
Breadcrumbs
python-pathfinding
/
test
/
grid_test.py
Copy path
File metadata and controls
86 lines (68 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
import
numpy
as
np
from
pathfinding
.
core
.
diagonal_movement
import
DiagonalMovement
from
pathfinding
.
core
.
grid
import
Grid
from
pathfinding
.
finder
.
a_star
import
AStarFinder
BORDERLESS_GRID
=
"""
xxx
xxx
"""
BORDER_GRID
=
"""
+---+
| |
| |
+---+
"""
WALKED_GRID
=
"""
+---+
|s# |
|xe |
+---+
"""
SIMPLE_MATRIX
=
[
[
1
,
1
,
1
],
[
1
,
0
,
1
],
[
1
,
1
,
1
]
]
SIMPLE_WALKED
=
"""
+---+
|sx |
| #x|
| e|
+---+
"""
def
test_str
():
"""
test printing the grid
"""
grid
=
Grid
(
height
=
2
,
width
=
3
)
assert
grid
.
grid_str
(
border
=
False
,
empty_chr
=
'x'
)
==
BORDERLESS_GRID
[
1
:
-
1
]
assert
grid
.
grid_str
(
border
=
True
)
==
BORDER_GRID
[
1
:
-
1
]
grid
.
nodes
[
0
][
1
].
walkable
=
False
start
=
grid
.
nodes
[
0
][
0
]
end
=
grid
.
nodes
[
1
][
1
]
path
=
[(
0
,
1
)]
assert
grid
.
grid_str
(
path
,
start
,
end
)
==
WALKED_GRID
[
1
:
-
1
]
def
test_empty
():
"""
special test for empty values
"""
matrix
=
()
grid
=
Grid
(
matrix
=
matrix
)
assert
grid
.
grid_str
()
==
'++
\n
||
\n
++'
matrix
=
np
.
array
(
matrix
)
grid
=
Grid
(
matrix
=
matrix
)
assert
grid
.
grid_str
()
==
'++
\n
||
\n
++'
def
test_numpy
():
"""
test grid from numpy array
"""
matrix
=
np
.
array
(
SIMPLE_MATRIX
)
grid
=
Grid
(
matrix
=
matrix
)
start
=
grid
.
node
(
0
,
0
)
end
=
grid
.
node
(
2
,
2
)
finder
=
AStarFinder
(
diagonal_movement
=
DiagonalMovement
.
always
)
path
,
runs
=
finder
.
find_path
(
start
,
end
,
grid
)
assert
grid
.
grid_str
(
path
,
start
,
end
)
==
SIMPLE_WALKED
[
1
:
-
1
]
if
__name__
==
'__main__'
:
test_str
()
Back
|
FazBrowse Home
|
New Git URL