forked from PoESkillTree/PoESkillTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkillParserTest.cs
More file actions
343 lines (321 loc) · 21.3 KB
/
SkillParserTest.cs
File metadata and controls
343 lines (321 loc) · 21.3 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using PoESkillTree.Computation.Builders.Stats;
using PoESkillTree.Computation.Common;
using PoESkillTree.Computation.Common.Builders.Damage;
using PoESkillTree.Computation.Parsing;
using PoESkillTree.GameModel;
using PoESkillTree.GameModel.Items;
using PoESkillTree.GameModel.Skills;
using PoESkillTree.Utils.Extensions;
using static PoESkillTree.Computation.IntegrationTests.ParsingTestUtils;
namespace PoESkillTree.Computation.IntegrationTests
{
[TestFixture]
public class SkillParserTest : CompositionRootTestBase
{
private SkillDefinitions _skillDefinitions;
private IParser _parser;
[SetUp]
public async Task SetUpAsync()
{
_skillDefinitions = await GameData.Skills.ConfigureAwait(false);
_parser = await ParserTask.ConfigureAwait(false);
}
[Test]
public void ParseFrenzyReturnsCorrectResult()
{
var frenzy = new Skill("Frenzy", 20, 20, ItemSlot.Boots, 0, 0);
var definition = _skillDefinitions.GetSkillById("Frenzy");
var levelDefinition = definition.Levels[20];
var local = new ModifierSource.Local.Skill("Frenzy", "Frenzy");
var global = new ModifierSource.Global(local);
var gemSource = new ModifierSource.Local.Gem(ItemSlot.Boots, 0, "Frenzy", "Frenzy");
var valueCalculationContextMock = new Mock<IValueCalculationContext>();
var isMainSkillStat = SetupIsActiveSkillInContext(valueCalculationContextMock, frenzy);
var offHandTagsStat = new Stat("OffHand.ItemTags");
valueCalculationContextMock.Setup(c => c.GetValue(offHandTagsStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue(Tags.Weapon.EncodeAsDouble()));
var mainHandTagsStat = new Stat("MainHand.ItemTags");
valueCalculationContextMock
.Setup(c => c.GetValue(mainHandTagsStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue(Tags.Ranged.EncodeAsDouble()));
var frenzyAmountStat = new Stat("Frenzy.Amount");
valueCalculationContextMock
.Setup(c => c.GetValue(frenzyAmountStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue(3));
var baseCostStat = new Stat("Boots.0.Cost");
valueCalculationContextMock
.Setup(c => c.GetValue(baseCostStat, NodeType.Total, PathDefinition.MainPath))
.Returns((NodeValue?) levelDefinition.ManaCost);
var expectedModifiers =
new (string stat, Form form, double? value, ModifierSource source, bool mainSkillOnly)[]
{
("SkillHitDamageSource", Form.TotalOverride, (int) DamageSource.Attack, global, true),
("SkillUses.MainHand", Form.TotalOverride, 1, global, true),
("SkillUses.OffHand", Form.TotalOverride, 1, global, true),
("MainSkill.Id", Form.TotalOverride, definition.NumericId, global, true),
("MainSkillPart.Maximum", Form.TotalOverride, definition.PartNames.Count - 1, global, true),
("BaseCastTime.Spell.Skill", Form.BaseSet, definition.ActiveSkill.CastTime / 1000D, global, true),
("BaseCastTime.Secondary.Skill", Form.BaseSet, definition.ActiveSkill.CastTime / 1000D, global,
true),
("Frenzy.ActiveSkillItemSlot", Form.BaseSet, (double) frenzy.ItemSlot, global, false),
("Frenzy.ActiveSkillSocketIndex", Form.BaseSet, frenzy.SocketIndex, global, false),
("Frenzy.Instances", Form.BaseAdd, 1, global, false),
("Skills[].Instances", Form.BaseAdd, 1, global, false),
("Skills[Attack].Instances", Form.BaseAdd, 1, global, false),
("Skills[Projectile].Instances", Form.BaseAdd, 1, global, false),
("Skills[Melee].Instances", Form.BaseAdd, 1, global, false),
("Skills[Bow].Instances", Form.BaseAdd, 1, global, false),
("MainSkill.Has.Attack", Form.TotalOverride, 1, global, true),
("MainSkill.Has.Projectile", Form.TotalOverride, 1, global, true),
("MainSkill.Has.Melee", Form.TotalOverride, 1, global, true),
("MainSkill.Has.Bow", Form.TotalOverride, 1, global, true),
("MainSkillPart.Has.Attack", Form.TotalOverride, 1, global, true),
("MainSkillPart.Has.Projectile", Form.TotalOverride, 1, global, true),
("MainSkillPart.Has.Melee", Form.TotalOverride, null, global, true),
("MainSkillPart.Has.Bow", Form.TotalOverride, 1, global, true),
("MainSkillPart.CastRate.Has.Attack", Form.TotalOverride, 1, global, true),
("MainSkillPart.CastRate.Has.Projectile", Form.TotalOverride, 1, global, true),
("MainSkillPart.CastRate.Has.Melee", Form.TotalOverride, null, global, true),
("MainSkillPart.CastRate.Has.Bow", Form.TotalOverride, 1, global, true),
("MainSkillPart.Damage.Attack.Has.Attack", Form.TotalOverride, 1, global, true),
("MainSkillPart.Damage.Attack.Has.Projectile", Form.TotalOverride, 1, global, true),
("MainSkillPart.Damage.Attack.Has.Melee", Form.TotalOverride, null, global, true),
("MainSkillPart.Damage.Attack.Has.Bow", Form.TotalOverride, 1, global, true),
("MainSkillPart.Damage.Spell.Has.Projectile", Form.TotalOverride, 1, global, true),
("MainSkillPart.Damage.Secondary.Has.Projectile", Form.TotalOverride, 1, global, true),
("Boots.0.Type.attack", Form.TotalOverride, 1, global, false),
("Boots.0.Type.projectile_attack", Form.TotalOverride, 1, global, false),
("Boots.0.Type.mirage_archer_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.projectile", Form.TotalOverride, 1, global, false),
("Boots.0.Type.volley_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.ranged_attack_totem_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.trap_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.remote_mine_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.melee_single_target_initial_hit", Form.TotalOverride, 1, global, false),
("Boots.0.Type.multistrike_supportable", Form.TotalOverride, 1, global, false),
("Boots.0.Type.melee", Form.TotalOverride, 1, global, false),
("Boots.0.Type.castable_by_maloneys_mechanism", Form.TotalOverride, 1, global, false),
("DamageBaseAddEffectiveness", Form.TotalOverride, levelDefinition.DamageEffectiveness, global,
true),
("DamageBaseSetEffectiveness", Form.TotalOverride, levelDefinition.DamageMultiplier, global, true),
("Boots.0.Cost", Form.BaseSet, levelDefinition.ManaCost, global, false),
("Mana.Cost", Form.BaseSet, levelDefinition.ManaCost, global, true),
("Frenzy.Reservation", Form.BaseSet, null, global, false),
("Life.Reservation", Form.BaseAdd, null, global, false),
("EnergyShield.Reservation", Form.BaseAdd, null, global, false),
("Mana.Reservation", Form.BaseAdd, null, global, false),
("Level.Required", Form.BaseSet, levelDefinition.Requirements.Level, gemSource, false),
("Dexterity.Required", Form.BaseSet, levelDefinition.Requirements.Dexterity, gemSource, false),
("CastRate.Attack.MainHand.Skill", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("CastRate.Attack.OffHand.Skill", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Physical.Damage.Attack.MainHand.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Attack.OffHand.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Spell.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Secondary.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.OverTime.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Attack.MainHand.Ignite", Form.Increase, levelDefinition.Stats[1].Value * 3,
global, true),
("Physical.Damage.Attack.MainHand.Bleed", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Attack.MainHand.Poison", Form.Increase, levelDefinition.Stats[1].Value * 3,
global, true),
("Physical.Damage.Attack.OffHand.Ignite", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Attack.OffHand.Bleed", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Attack.OffHand.Poison", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Spell.Ignite", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Spell.Bleed", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Spell.Poison", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Secondary.Ignite", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Secondary.Bleed", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("Physical.Damage.Secondary.Poison", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("CastRate.Attack.MainHand.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global,
true),
("CastRate.Attack.OffHand.Skill", Form.Increase, levelDefinition.Stats[1].Value * 3, global, true),
("Range.Attack.MainHand.Skill", Form.BaseAdd, null, global, true),
("Range.Attack.OffHand.Skill", Form.BaseAdd, null, global, true),
}.Select(t => (t.stat, t.form, (NodeValue?) t.value, t.source, t.mainSkillOnly)).ToArray();
var actual = _parser.ParseActiveSkill(frenzy);
AssertCorrectModifiers(valueCalculationContextMock, isMainSkillStat, expectedModifiers, actual);
}
[Test]
public void ParseAddedColdDamageSupportReturnsCorrectResult()
{
var frenzy = new Skill("Frenzy", 20, 20, ItemSlot.Boots, 0, 0);
var support = new Skill("SupportAddedColdDamage", 20, 20, ItemSlot.Boots, 1, 0);
var definition = _skillDefinitions.GetSkillById(support.Id);
var levelDefinition = definition.Levels[20];
var local = new ModifierSource.Local.Skill("Frenzy", "Added Cold Damage Support");
var global = new ModifierSource.Global(local);
var gemSource = new ModifierSource.Local.Gem(support.ItemSlot, support.SocketIndex,
"Frenzy", "Added Cold Damage Support");
var valueCalculationContextMock = new Mock<IValueCalculationContext>();
var isMainSkillStat = SetupIsActiveSkillInContext(valueCalculationContextMock, frenzy);
var addedDamageValue = new NodeValue(levelDefinition.Stats[0].Value, levelDefinition.Stats[1].Value);
var expectedModifiers =
new (string stat, Form form, double? value, ModifierSource source, bool mainSkillOnly)[]
{
("SupportAddedColdDamage.ActiveSkillItemSlot",
Form.BaseSet, (double) support.ItemSlot, global, false),
("SupportAddedColdDamage.ActiveSkillSocketIndex",
Form.BaseSet, support.SocketIndex, global, false),
("Mana.Cost", Form.More, levelDefinition.ManaMultiplier * 100 - 100, global, true),
("Frenzy.Reservation", Form.More, levelDefinition.ManaMultiplier * 100 - 100, global, false),
("Level.Required", Form.BaseSet, levelDefinition.Requirements.Level, gemSource, false),
("Dexterity.Required", Form.BaseSet, levelDefinition.Requirements.Dexterity, gemSource, false),
("Cold.Damage.Attack.MainHand.Skill", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.OffHand.Skill", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Spell.Skill", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Secondary.Skill", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.OverTime.Skill", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Attack.MainHand.Ignite", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.MainHand.Bleed", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.MainHand.Poison", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.OffHand.Ignite", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.OffHand.Bleed", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Attack.OffHand.Poison", Form.Increase,
levelDefinition.QualityStats[0].Value * 20 / 1000, global, true),
("Cold.Damage.Spell.Ignite", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Spell.Bleed", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Spell.Poison", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Secondary.Ignite", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Secondary.Bleed", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
("Cold.Damage.Secondary.Poison", Form.Increase, levelDefinition.QualityStats[0].Value * 20 / 1000,
global, true),
}.Select(t => (t.stat, t.form, (NodeValue?) t.value, t.source, t.mainSkillOnly)).ToArray();
expectedModifiers = expectedModifiers.Append(
("Cold.Damage.Attack.MainHand.Skill", Form.BaseAdd, addedDamageValue, global, true),
("Cold.Damage.Attack.OffHand.Skill", Form.BaseAdd, addedDamageValue, global, true),
("Cold.Damage.Spell.Skill", Form.BaseAdd, addedDamageValue, global, true),
("Cold.Damage.Secondary.Skill", Form.BaseAdd, addedDamageValue, global, true))
.ToArray();
var actual = _parser.ParseSupportSkill(frenzy, support);
AssertCorrectModifiers(valueCalculationContextMock, isMainSkillStat, expectedModifiers, actual);
}
private static Stat SetupIsActiveSkillInContext(
Mock<IValueCalculationContext> contextMock, Skill frenzy)
{
var activeSkillItemSlotStat = new Stat("Frenzy.ActiveSkillItemSlot");
contextMock
.Setup(c => c.GetValue(activeSkillItemSlotStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue((double) frenzy.ItemSlot));
var activeSkillSocketIndexStat = new Stat("Frenzy.ActiveSkillSocketIndex");
contextMock
.Setup(c => c.GetValue(activeSkillSocketIndexStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue(frenzy.SocketIndex));
var mainSkillItemSlotStat = new Stat("MainSkillItemSlot");
contextMock
.Setup(c => c.GetValue(mainSkillItemSlotStat, NodeType.Total, PathDefinition.MainPath))
.Returns(new NodeValue((double) frenzy.ItemSlot));
var isMainSkillStat = new Stat("IsMainSkill");
var mainSkillSocketIndexStat = new Stat("MainSkillSocketIndex");
contextMock
.Setup(c => c.GetValue(mainSkillSocketIndexStat, NodeType.Total, PathDefinition.MainPath))
.Returns(() => new NodeValue(contextMock.Object.GetValue(isMainSkillStat).IsTrue()
? frenzy.SocketIndex
: -1));
return isMainSkillStat;
}
private static void AssertCorrectModifiers(
Mock<IValueCalculationContext> contextMock,
Stat isMainSkillStat,
(string stat, Form form, NodeValue? value, ModifierSource source, bool mainSkillOnly)[] expectedModifiers,
ParseResult result)
{
var (failedLines, remainingSubstrings, modifiers) = result;
Assert.IsEmpty(failedLines);
Assert.IsEmpty(remainingSubstrings);
for (var i = 0; i < modifiers.Count && i < expectedModifiers.Length; i++)
{
var expected = expectedModifiers[i];
var actual = modifiers[i];
Assert.That(actual.Stats, Has.One.Items);
Assert.AreEqual(expected.stat, actual.Stats[0].Identity);
Assert.AreEqual(Entity.Character, actual.Stats[0].Entity);
Assert.AreEqual(expected.form, actual.Form);
Assert.AreEqual(expected.source, actual.Source);
contextMock
.Setup(c => c.GetValue(isMainSkillStat, NodeType.Total, PathDefinition.MainPath))
.Returns((NodeValue?) true);
var expectedValue = expected.value;
var actualValue = actual.Value.Calculate(contextMock.Object);
Assert.AreEqual(expectedValue, actualValue);
contextMock
.Setup(c => c.GetValue(isMainSkillStat, NodeType.Total, PathDefinition.MainPath))
.Returns((NodeValue?) false);
expectedValue = expected.mainSkillOnly ? null : expected.value;
actualValue = actual.Value.Calculate(contextMock.Object);
Assert.AreEqual(expectedValue, actualValue);
}
Assert.AreEqual(expectedModifiers.Length, modifiers.Count);
}
[TestCaseSource(nameof(ReadParseableSkills))]
public void SkillIsParsedSuccessfully(string skillId)
{
var actual = Parse(skillId);
AssertIsParsedSuccessfully(actual, NotParseableStatLines.Value);
}
[TestCaseSource(nameof(ReadNotParseableSkills))]
public void SkillIsParsedUnsuccessfully(string skillId)
{
var actual = Parse(skillId);
AssertIsParsedUnsuccessfully(actual);
}
private ParseResult Parse(string skillId)
{
var definition = _skillDefinitions.GetSkillById(skillId);
var level = Math.Min(definition.Levels.Keys.Max(), 20);
if (definition.IsSupport)
{
var activeSkill = new Skill("BloodRage", 20, 20, default, 0, 0);
var supportSkill = new Skill(skillId, level, 20, default, 1, 0);
return _parser.ParseSupportSkill(activeSkill, supportSkill);
}
else
{
var skill = new Skill(skillId, level, 20, default, 0, 0);
return _parser.ParseActiveSkill(skill);
}
}
private static IEnumerable<string> ReadParseableSkills()
=> ReadDataLines("ParseableSkills");
private static IEnumerable<string> ReadNotParseableSkills()
=> ReadDataLines("NotParseableSkills");
}
}