Repository navigation
Expand file tree
/
Copy pathastar_test.go
More file actions
69 lines (53 loc) · 1.4 KB
/
Copy pathastar_test.go
File metadata and controls
69 lines (53 loc) · 1.4 KB
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
package tinyrogue
import (
"testing"
"github.com/firefly-zero/firefly-go/firefly"
)
func TestAStar(t *testing.T) {
game := NewGame()
game.Images["floor"] = firefly.Image{}
game.Images["wall"] = firefly.Image{}
game.SetData(NewGameData(16, 10, 16, 16))
game.SetMap(NewSingleLevelGameMap())
level := game.CurrentLevel()
level.Dump()
room1 := level.Rooms[0]
room2 := level.Rooms[len(level.Rooms)-1]
// Set the start and end points
x1, y1 := room1.Center()
start := Position{x1, y1}
x2, y2 := room2.Center()
end := Position{x2, y2}
// Create the AStar object
as := AStar{}
// Get the path
path := as.GetPath(level, start, end)
// Check the path
if len(path) == 0 {
t.Errorf("Expected path length of > 0, got %d", len(path))
}
}
func TestAStar2(t *testing.T) {
game := NewGame()
game.Images["floor"] = firefly.Image{}
game.Images["wall"] = firefly.Image{}
game.SetData(NewGameData(32, 32, 16, 16))
game.SetMap(NewSingleLevelGameMap())
level := game.CurrentLevel()
level.Dump()
room1 := level.Rooms[0]
room2 := level.Rooms[len(level.Rooms)-1]
// Set the start and end points
x1, y1 := room1.Center()
start := Position{x1, y1}
x2, y2 := room2.Center()
end := Position{x2, y2}
// Create the AStar object
as := AStar{}
// Get the path
path := as.GetPath(level, start, end)
// Check the path
if len(path) == 0 {
t.Errorf("Expected path length of > 0, got %d", len(path))
}
}