forked from dotabuff/manta
/
manta_test.go
162 lines (143 loc) · 4.6 KB
/
manta_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
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
package manta
import (
"testing"
"github.com/dotabuff/manta/dota"
"github.com/stretchr/testify/assert"
)
func init() {
debugMode = true
}
func TestParseOneMatch(t *testing.T) {
assert := assert.New(t)
buf := mustGetReplayData("1560315800", "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1560315800.dem")
parser, err := NewParser(buf)
assert.Nil(err)
err = parser.Start()
assert.Nil(err)
}
// Simply tests that we can read the outer structure of a real match
func TestParseRealMatches(t *testing.T) {
assert := assert.New(t)
scenarios := []struct {
matchId string
replayUrl string
expectCombatLogDamage int
expectCombatLogHealing int
expectCombatLogDeaths int
expectCombatLogEvents int
expectUnitOrderEvents int
}{
{
matchId: "1560289528",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1560289528.dem",
expectCombatLogDamage: 1180993,
expectCombatLogHealing: 57511,
expectCombatLogDeaths: 1449,
expectCombatLogEvents: 49146,
expectUnitOrderEvents: 63387,
},
{
matchId: "1560294294",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1560294294.dem",
expectCombatLogDamage: 768154,
expectCombatLogHealing: 11565,
expectCombatLogDeaths: 954,
expectCombatLogEvents: 24535,
expectUnitOrderEvents: 30657,
},
{
matchId: "1560315800",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1560315800.dem",
expectCombatLogDamage: 1332418,
expectCombatLogHealing: 57874,
expectCombatLogDeaths: 1645,
expectCombatLogEvents: 51288,
expectUnitOrderEvents: 63992,
},
{
matchId: "1582611189",
replayUrl: "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1582611189.dem",
expectCombatLogDamage: 599388,
expectCombatLogHealing: 28576,
expectCombatLogDeaths: 930,
expectCombatLogEvents: 23800,
expectUnitOrderEvents: 40237,
},
}
for _, s := range scenarios {
buf := mustGetReplayData(s.matchId, s.replayUrl)
parser, err := NewParser(buf)
if err != nil {
t.Errorf("unable to instantiate parser: %s", err)
continue
}
gotCombatLogDamage := 0
gotCombatLogHealing := 0
gotCombatLogDeaths := 0
gotCombatLogEvents := 0
gotUnitOrderEvents := 0
parser.Callbacks.OnCDOTAUserMsg_SpectatorPlayerUnitOrders(func(m *dota.CDOTAUserMsg_SpectatorPlayerUnitOrders) error {
gotUnitOrderEvents += 1
return nil
})
parser.GameEvents.OnDotaCombatlog(func(m *GameEventDotaCombatlog) error {
gotCombatLogEvents += 1
switch dota.DOTA_COMBATLOG_TYPES(m.Type) {
case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_DAMAGE:
gotCombatLogDamage += int(m.Value)
case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_DEATH:
gotCombatLogDeaths += 1
case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_HEAL:
gotCombatLogHealing += int(m.Value)
}
return nil
})
err = parser.Start()
assert.Nil(err, s.matchId)
/*
Use this to write out instancebaseline fixtures
t, _ := parser.stringTables.getTableByName("instancebaseline")
for _, i := range t.items {
classId, _ := atoi32(i.key)
className := parser.classInfo[classId]
_dump_fixture(_sprintf("instancebaseline/%s_%s.rawbuf", className), s.matchId, i.value)
}
*/
/*
Use this to dump layout of sendtables
out := _sprintf("")
classIds := make([]int, 0)
for classId, _ := range parser.classInfo {
classIds = append(classIds, int(classId))
}
sort.Ints(classIds)
for _, classId := range classIds {
className := parser.classInfo[int32(classId)]
st := parser.sendTables.tables[className]
out += _sprintf("class id=%d name=%s\n", classId, className)
out += _sprintf("table id=%d name=%s version=%d\n", st.index, st.name, st.version)
for i, p := range st.props {
out += _sprintf(" -> prop %d: %s\n", i, p.Describe())
}
out += "\n"
}
*/
assert.Equal(s.expectCombatLogDamage, gotCombatLogDamage, s.matchId)
assert.Equal(s.expectCombatLogHealing, gotCombatLogHealing, s.matchId)
assert.Equal(s.expectCombatLogDeaths, gotCombatLogDeaths, s.matchId)
assert.Equal(s.expectCombatLogEvents, gotCombatLogEvents, s.matchId)
assert.Equal(s.expectUnitOrderEvents, gotUnitOrderEvents, s.matchId)
}
}
func BenchmarkParseMatch(b *testing.B) {
assert := assert.New(b)
buf := mustGetReplayData("1560315800", "https://s3-us-west-2.amazonaws.com/manta.dotabuff/1560315800.dem")
b.ResetTimer()
for n := 0; n < b.N; n++ {
parser, err := NewParser(buf)
assert.Nil(err)
err = parser.Start()
assert.Nil(err)
}
b.ReportAllocs()
}