Repository navigation
Expand file tree
/
Copy pathcharacter_test.go
More file actions
89 lines (77 loc) · 2.05 KB
/
Copy pathcharacter_test.go
File metadata and controls
89 lines (77 loc) · 2.05 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tinyrogue
import (
"testing"
"github.com/firefly-zero/firefly-go/firefly"
)
func TestCharacterName(t *testing.T) {
c := &character{name: "Hero"}
if c.Name() != "Hero" {
t.Errorf("expected name 'Hero', got '%s'", c.Name())
}
}
func TestCharacterKind(t *testing.T) {
c := &character{kind: "warrior"}
if c.Kind() != "warrior" {
t.Errorf("expected kind 'warrior', got '%s'", c.Kind())
}
}
func TestCharacterSetImage(t *testing.T) {
c := &character{}
img := &firefly.Image{}
c.SetImage(img)
if c.Image != img {
t.Error("SetImage did not set the image correctly")
}
}
func TestCharacterGetSpeed(t *testing.T) {
c := &character{speed: 5}
if c.GetSpeed() != 5 {
t.Errorf("expected speed 5, got %d", c.GetSpeed())
}
}
func TestCharacterSetSpeed(t *testing.T) {
c := &character{}
c.SetSpeed(10)
if c.GetSpeed() != 10 {
t.Errorf("expected speed 10, got %d", c.GetSpeed())
}
}
func TestCharacterGetPosition(t *testing.T) {
c := &character{pos: Position{X: 3, Y: 7}}
pos := c.GetPosition()
if pos.X != 3 || pos.Y != 7 {
t.Errorf("expected position (3, 7), got (%d, %d)", pos.X, pos.Y)
}
}
func TestCharacterMove(t *testing.T) {
c := &character{pos: Position{X: 5, Y: 5}}
c.Move(2, -3)
pos := c.GetPosition()
if pos.X != 7 || pos.Y != 2 {
t.Errorf("expected position (7, 2), got (%d, %d)", pos.X, pos.Y)
}
}
func TestCharacterMoveNegative(t *testing.T) {
c := &character{pos: Position{X: 10, Y: 10}}
c.Move(-5, -5)
pos := c.GetPosition()
if pos.X != 5 || pos.Y != 5 {
t.Errorf("expected position (5, 5), got (%d, %d)", pos.X, pos.Y)
}
}
func TestCharacterMoveTo(t *testing.T) {
c := &character{pos: Position{X: 0, Y: 0}}
c.MoveTo(Position{X: 10, Y: 20})
pos := c.GetPosition()
if pos.X != 10 || pos.Y != 20 {
t.Errorf("expected position (10, 20), got (%d, %d)", pos.X, pos.Y)
}
}
func TestCharacterMoveToOverwrite(t *testing.T) {
c := &character{pos: Position{X: 100, Y: 200}}
c.MoveTo(Position{X: 5, Y: 5})
pos := c.GetPosition()
if pos.X != 5 || pos.Y != 5 {
t.Errorf("expected position (5, 5), got (%d, %d)", pos.X, pos.Y)
}
}