-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathequipment_test.go
More file actions
209 lines (173 loc) · 7.97 KB
/
equipment_test.go
File metadata and controls
209 lines (173 loc) · 7.97 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package common
import (
"testing"
"github.com/stretchr/testify/assert"
st "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/sendtables"
)
func TestEquipmentElement_Class(t *testing.T) {
assert.Equal(t, EqClassUnknown, EqUnknown.Class(), "EqUnknown should have the class EqClassUnknown")
assert.Equal(t, EqClassPistols, EqP2000.Class(), "EqP2000 should have the class EqClassPistols")
assert.Equal(t, EqClassPistols, EqRevolver.Class(), "EqRevolver should have the class EqClassPistols")
assert.Equal(t, EqClassRifle, EqG3SG1.Class(), "EqG3SG1 should have the class EqClassRifle")
}
func TestEquipmentElement_Name(t *testing.T) {
assert.Equal(t, "Dual Berettas", EqDualBerettas.String(), "EqDualBerettas should be named correctly")
}
func TestMapEquipment(t *testing.T) {
assert.Equal(t, EqKnife, MapEquipment("weapon_bayonet"), "'weapon_bayonet' should be mapped to EqKnifeBayonet")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_butterfly"), "'weapon_knife_butterfly' should be mapped to EqKnifeButterfly")
assert.Equal(t, EqM4A4, MapEquipment("weapon_m4a1"), "'weapon_m4a1' should be mapped to EqM4A4") // This is correct, weapon_m4a1 == M4A4
assert.Equal(t, EqM4A1, MapEquipment("weapon_m4a1_silencer"), "'weapon_m4a1_silencer' should be mapped to EqM4A1")
assert.Equal(t, EqUnknown, MapEquipment("asdf"), "'asdf' should be mapped to EqUnknown")
}
func TestMapEquipmentKnives(t *testing.T) {
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_bayonet"), "'weapon_knife_bayonet' should be mapped to EqKnifeBayonet")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_css"), "'weapon_knife_css' should be mapped to EqKnifeCSS")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_flip"), "'weapon_knife_flip' should be mapped to EqKnifeFlip")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_gut"), "'weapon_knife_gut' should be mapped to EqKnifeGut")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_karambit"), "'weapon_knife_karambit' should be mapped to EqKnifeKarambit")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_m9_bayonet"), "'weapon_knife_m9_bayonet' should be mapped to EqKnifeM9Bayonet")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_tactical"), "'weapon_knife_tactical' should be mapped to EqKnifeTactical")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_falchion"), "'weapon_knife_falchion' should be mapped to EqKnifeFalchion")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_survival_bowie"), "'weapon_knife_survival_bowie' should be mapped to EqKnifeSurvivalBowie")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_butterfly"), "'weapon_knife_butterfly' should be mapped to EqKnifeButterfly")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_push"), "'weapon_knife_push' should be mapped to EqKnifePush")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_cord"), "'weapon_knife_cord' should be mapped to EqKnifeCord")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_canis"), "'weapon_knife_canis' should be mapped to EqKnifeCanis")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_ursus"), "'weapon_knife_ursus' should be mapped to EqKnifeUrsus")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_gypsy_jackknife"), "'weapon_knife_gypsy_jackknife' should be mapped to EqKnifeGypsyJackknife")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_outdoor"), "'weapon_knife_outdoor' should be mapped to EqKnifeOutdoor")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_stiletto"), "'weapon_knife_stiletto' should be mapped to EqKnifeStiletto")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_widowmaker"), "'weapon_knife_widowmaker' should be mapped to EqKnifeWidowmaker")
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_skeleton"), "'weapon_knife_skeleton' should be mapped to EqKnifeSkeleton")
}
func TestEquipment_Class(t *testing.T) {
assert.Equal(t, EqClassUnknown, NewEquipment(EqUnknown).Class(), "EqUnknown should have the class EqClassUnknown")
assert.Equal(t, EqClassPistols, NewEquipment(EqP2000).Class(), "EqP2000 should have the class EqClassPistols")
assert.Equal(t, EqClassPistols, NewEquipment(EqRevolver).Class(), "EqRevolver should have the class EqClassPistols")
assert.Equal(t, EqClassRifle, NewEquipment(EqG3SG1).Class(), "EqG3SG1 should have the class EqClassRifle")
}
func TestEquipment_UniqueID(t *testing.T) {
assert.NotEqual(t, NewEquipment(EqAK47).UniqueID(), NewEquipment(EqAK47).UniqueID(), "UniqueIDs of different equipment instances should be different")
}
func TestEquipment_AmmoInMagazine(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
Entity: entityWithProperty("m_iClip1", st.PropertyValue{IntVal: 31, Any: uint32(30)}),
}
// returned value should be minus 1, m_iClip1 is always 1 more than the actual number of bullets
assert.Equal(t, 30, wep.AmmoInMagazine())
}
func TestEquipment_AmmoInMagazine_NotFound(t *testing.T) {
entity := entityWithID(1)
entity.On("PropertyValue", "m_iClip1").Return(st.PropertyValue{}, false)
wep := &Equipment{
Type: EqAK47,
Entity: entity,
}
// returned value should be minus 1, m_iClip1 is always 1 more than the actual number of bullets
assert.Equal(t, -1, wep.AmmoInMagazine())
}
func TestEquipment_AmmoInMagazine_Grenade(t *testing.T) {
wep := &Equipment{
Type: EqFlash,
}
assert.Equal(t, 1, wep.AmmoInMagazine())
}
func TestEquipment_AmmoInMagazine_EntityNil(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
}
assert.Equal(t, 0, wep.AmmoInMagazine())
}
func TestEquipment_AmmoReserve(t *testing.T) {
entity := entityWithProperties([]fakeProp{
{
propName: "m_pReserveAmmo.0000",
value: st.PropertyValue{},
isNil: true,
},
{
propName: "m_iPrimaryReserveAmmoCount",
value: st.PropertyValue{IntVal: 60},
isNil: false,
},
})
wep := &Equipment{
Type: EqAK47,
Entity: entity,
}
assert.Equal(t, 60, wep.AmmoReserve())
}
func TestEquipment_AmmoReserve_Grenade(t *testing.T) {
owner := new(Player)
owner.AmmoLeft[1] = 2
entity := entityWithProperties([]fakeProp{
{
propName: "m_pReserveAmmo.0001",
value: st.PropertyValue{},
isNil: true,
},
{
propName: "LocalWeaponData.m_iPrimaryAmmoType",
value: st.PropertyValue{IntVal: 1},
isNil: false,
},
})
wep := &Equipment{
Type: EqFlash,
Owner: owner,
Entity: entity,
}
assert.Equal(t, 1, wep.AmmoReserve())
}
func TestEquipment_AmmoReserve_Grenade_OwnerNil(t *testing.T) {
wep := &Equipment{
Type: EqFlash,
}
assert.Equal(t, 0, wep.AmmoReserve())
}
func TestEquipment_AmmoReserve_EntityNil(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
}
assert.Equal(t, 0, wep.AmmoReserve())
}
func TestEquipment_ZoomLevel(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
Entity: entityWithProperty("m_zoomLevel", st.PropertyValue{IntVal: 2}),
}
assert.Equal(t, ZoomFull, wep.ZoomLevel())
}
func TestEquipment_ZoomLevel_EntityNil(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
}
assert.Equal(t, ZoomLevel(0), wep.ZoomLevel())
}
func TestEquipment_Not_Silenced(t *testing.T) {
wep := &Equipment{
Type: EqAK47,
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0}),
}
assert.Equal(t, false, wep.Silenced())
}
func TestEquipment_Silenced_On_Off(t *testing.T) {
wep := &Equipment{
Type: EqUSP,
Entity: entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 1}),
}
assert.Equal(t, true, wep.Silenced(), "Weapon should be silenced after the property value has been set to 1.")
wep.Entity = entityWithProperty("m_bSilencerOn", st.PropertyValue{IntVal: 0})
assert.Equal(t, false, wep.Silenced(), "Weapon should not be silenced after the property value has been set to 0.")
}
func TestEquipmentAlternative(t *testing.T) {
assert.Equal(t, EqUSP, EquipmentAlternative(EqP2000))
assert.Equal(t, EqCZ, EquipmentAlternative(EqP250))
assert.Equal(t, EqCZ, EquipmentAlternative(EqFiveSeven))
assert.Equal(t, EqCZ, EquipmentAlternative(EqTec9))
assert.Equal(t, EqRevolver, EquipmentAlternative(EqDeagle))
assert.Equal(t, EqMP5, EquipmentAlternative(EqMP7))
assert.Equal(t, EqM4A1, EquipmentAlternative(EqM4A4))
}