-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_test.go
74 lines (68 loc) · 1.91 KB
/
entity_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
67
68
69
70
71
72
73
74
package main
import "testing"
func TestAttackInfo_Attack(t *testing.T) {
type fields struct {
AttackPower int
attackAsset Asset
attackFrame int
}
type args struct {
d EntityInfo
}
tests := []struct {
name string
fields fields
args args
}{
{"case 1", fields{1, &AssetInfo{FrameCount: 5}, 0}, args{EntityInfo{CurrentHealth: 10, Defense: 0}}},
{"case 2", fields{2, &AssetInfo{FrameCount: 5}, 0}, args{EntityInfo{CurrentHealth: 10, Defense: 0}}},
{"case 3", fields{5, &AssetInfo{FrameCount: 5}, 0}, args{EntityInfo{CurrentHealth: 10, Defense: 0}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &AttackInfo{
AttackPower: tt.fields.AttackPower,
attackAsset: tt.fields.attackAsset,
attackFrame: tt.fields.attackFrame,
}
maxHealth := tt.args.d.CurrentHealth
a.Attack(&tt.args.d)
if tt.args.d.CurrentHealth == maxHealth {
t.Errorf("after attack health didn't go down: %v max: %v", tt.args.d.CurrentHealth, maxHealth)
}
})
}
}
func TestAttackInfo_AttackHighDefense(t *testing.T) {
type fields struct {
AttackPower int
attackAsset Asset
attackFrame int
}
type args struct {
d EntityInfo
}
tests := []struct {
name string
fields fields
args args
wantHealth int
}{
{"case 1", fields{5, &AssetInfo{FrameCount: 5}, 0}, args{EntityInfo{CurrentHealth: 10, Defense: 5}}, 9},
{"case 2", fields{5, &AssetInfo{FrameCount: 5}, 0}, args{EntityInfo{CurrentHealth: 100, Defense: 10}}, 8},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &AttackInfo{
AttackPower: tt.fields.AttackPower,
attackAsset: tt.fields.attackAsset,
attackFrame: tt.fields.attackFrame,
}
maxHealth := tt.args.d.CurrentHealth
a.Attack(&tt.args.d)
if tt.args.d.CurrentHealth < maxHealth {
t.Errorf("after attack health went down in spite of defense: %v max: %v", tt.args.d.CurrentHealth, maxHealth)
}
})
}
}