-
Notifications
You must be signed in to change notification settings - Fork 1
/
astar_impl_test.go
66 lines (50 loc) · 1.46 KB
/
astar_impl_test.go
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
package astar
import (
"testing"
)
func Test__Works_For_Square_Map_With_Diagonal_Path_Without_Obstacles(t *testing.T) {
// * O O
// O * O
// O O *
// given
_, start, end := GraphFromBitmap("resources/3x3_empty_terrain")
// when
distance, actualPath := AStar(start, end)
// then
PersistGraphToBitmap(actualPath, "resources/3x3_empty_terrain")
PersistGraphToFile(distance, actualPath, "resources/3x3_empty_terrain")
// and
AssertDistanceEqual(t, distance, 3)
}
func Test__Works_For_Square_Map_With_Obstacles(t *testing.T) {
// * O O X *
// O * O X *
// O X O X O
// O O * X *
// O O O * O
// given
_, start, end := GraphFromBitmap("resources/5x5_terrain_with_obstacles")
// when
distance, actualPath := AStar(start, end)
// then
PersistGraphToBitmap(actualPath, "resources/5x5_terrain_with_obstacles")
PersistGraphToFile(distance, actualPath, "resources/5x5_terrain_with_obstacles")
// and:
AssertDistanceEqual(t, distance, 8)
}
func Test__Jumps_Over_Obstacles_When_Velocity_Is_Sufficient(t *testing.T) {
// * * O * X * * *
// O O O O X O O O
// O O X O X O O O
// O O O O X O O O
// O O O O O O O O
// given
_, start, end := GraphFromBitmap("resources/8x5_terrain_with_obstacles")
// when
distance, actualPath := AStar(start, end)
// then
PersistGraphToBitmap(actualPath, "resources/8x5_terrain_with_obstacles")
PersistGraphToFile(distance, actualPath, "resources/8x5_terrain_with_obstacles")
// and:
AssertDistanceEqual(t, distance, 6)
}