forked from PoESkillTree/PoESkillTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsingTest.cs
More file actions
205 lines (181 loc) · 7.96 KB
/
ParsingTest.cs
File metadata and controls
205 lines (181 loc) · 7.96 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
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using PoESkillTree.Computation.Common;
using PoESkillTree.Computation.Common.Builders;
using PoESkillTree.Computation.Common.Builders.Conditions;
using PoESkillTree.Computation.Common.Builders.Damage;
using PoESkillTree.Computation.Common.Builders.Forms;
using PoESkillTree.Computation.Common.Builders.Stats;
using PoESkillTree.Computation.Common.Builders.Values;
using PoESkillTree.Computation.Data.GivenStats;
using PoESkillTree.Computation.Parsing;
using PoESkillTree.GameModel;
using PoESkillTree.Utils.Extensions;
using static PoESkillTree.Computation.IntegrationTests.ParsingTestUtils;
namespace PoESkillTree.Computation.IntegrationTests
{
[TestFixture]
public class ParsingTest : CompositionRootTestBase
{
private IParser _parser;
private IBuilderFactories _f;
[SetUp]
public async Task SetUpAsync()
{
_parser = await ParserTask.ConfigureAwait(false);
_f = await BuilderFactoriesTask.ConfigureAwait(false);
}
[Test, TestCaseSource(nameof(ReadParseableStatLines))]
public void Parses(string statLine)
{
var actual = Parse(statLine);
AssertIsParsedSuccessfully(actual);
}
[Test, TestCaseSource(nameof(ReadNotParseableStatLines))]
public void DoesNotParse(string statLine)
{
var actual = Parse(statLine);
AssertIsParsedUnsuccessfully(actual);
}
private static IEnumerable<string> ReadParseableStatLines()
{
var unparsedGivenStats = new GivenStatsCollection(null, null, null).SelectMany(s => s.GivenStatLines);
return ReadDataLines("SkillTreeStatLines")
.Concat(ReadDataLines("ParseableStatLines"))
.Concat(unparsedGivenStats)
.Where(s => !NotParseableStatLines.Value.Contains(s.ToLowerInvariant()));
}
private static IEnumerable<string> ReadNotParseableStatLines() => ParsingTestUtils.ReadNotParseableStatLines();
[Test]
public void Dexterity()
{
var expected = CreateModifier(
_f.StatBuilders.Attribute.Dexterity,
_f.FormBuilders.BaseAdd,
_f.ValueBuilders.Create(10));
var actual = Parse("+10 to Dexterity").Modifiers;
Assert.AreEqual(expected, actual);
}
[Test]
public void ManaPerGrandSpectrum()
{
var expected = new[]
{
CreateModifier(
_f.StatBuilders.GrandSpectrumJewelsSocketed,
_f.FormBuilders.BaseAdd,
_f.ValueBuilders.Create(1)),
CreateModifier(
_f.StatBuilders.Pool.From(Pool.Mana),
_f.FormBuilders.BaseAdd,
_f.ValueBuilders.Create(30).Multiply(_f.StatBuilders.GrandSpectrumJewelsSocketed.Value)),
}.Flatten();
var actual = Parse("Gain 30 Mana per Grand Spectrum").Modifiers;
Assert.AreEqual(expected, actual);
}
[Test]
public void CorruptedEnergy()
{
var expected = new[]
{
CreateModifier(
_f.DamageTypeBuilders.Chaos.DamageTakenFrom(_f.StatBuilders.Pool.From(Pool.EnergyShield))
.Before(_f.StatBuilders.Pool.From(Pool.Life)),
_f.FormBuilders.BaseAdd,
_f.ValueBuilders.Create(50),
_f.EquipmentBuilders.Equipment.Count(e => e.Corrupted.IsSet) >= 5),
CreateModifier(
_f.DamageTypeBuilders.Physical.DamageTakenFrom(_f.StatBuilders.Pool.From(Pool.EnergyShield))
.Before(_f.StatBuilders.Pool.From(Pool.Life)),
_f.FormBuilders.BaseSubtract,
_f.ValueBuilders.Create(50),
_f.EquipmentBuilders.Equipment.Count(e => e.Corrupted.IsSet) >= 5)
}.Flatten();
var actual = Parse(
"With 5 Corrupted Items Equipped: 50% of Chaos Damage does not bypass Energy Shield, and 50% of Physical Damage bypasses Energy Shield")
.Modifiers;
Assert.AreEqual(expected, actual);
}
[Test]
public void VaalPact()
{
var life = _f.StatBuilders.Pool.From(Pool.Life);
var expected = new[]
{
CreateModifier(
life.Leech.Rate,
_f.FormBuilders.PercentMore,
_f.ValueBuilders.Create(100)),
CreateModifier(
life.Leech.RateLimit,
_f.FormBuilders.PercentMore,
_f.ValueBuilders.Create(100)),
CreateModifier(
life.Regen,
_f.FormBuilders.PercentLess,
_f.ValueBuilders.Create(100))
}.Flatten();
var actual = Parse(
"Life Leeched per Second is doubled.\nMaximum Life Leech Rate is doubled.\nLife Regeneration has no effect.")
.Modifiers;
Assert.AreEqual(expected, actual);
}
[Test]
public void ParagonOfCalamity()
{
var expected = new[]
{
ParagonOfCalamityFor(_f.DamageTypeBuilders.Fire),
ParagonOfCalamityFor(_f.DamageTypeBuilders.Lightning),
ParagonOfCalamityFor(_f.DamageTypeBuilders.Cold),
}.Flatten();
var actual = Parse(
"For each Element you've been hit by Damage of Recently, 8% reduced Damage taken of that Element")
.Modifiers;
Assert.AreEqual(expected, actual);
IEnumerable<Modifier> ParagonOfCalamityFor(IDamageTypeBuilder damageType) =>
CreateModifier(
damageType.Damage.Taken,
_f.FormBuilders.PercentReduce,
_f.ValueBuilders.Create(8),
_f.ActionBuilders.HitWith(damageType).By(_f.EntityBuilders.Enemy).Recently);
}
[Test]
public void AurasGrantCastRate()
{
var expected = new[]
{
CreateModifier(
_f.BuffBuilders.Buffs(_f.EntityBuilders.Self, _f.EntityBuilders.Self, _f.EntityBuilders.Ally)
.With(_f.KeywordBuilders.Aura).Without(_f.KeywordBuilders.Curse)
.AddStat(_f.StatBuilders.CastRate),
_f.FormBuilders.PercentIncrease,
_f.ValueBuilders.Create(3))
}.Flatten();
var actual = Parse("Auras from your Skills grant 3% increased Attack and Cast Speed to you and Allies")
.Modifiers;
Assert.AreEqual(expected, actual);
}
private static IEnumerable<Modifier> CreateModifier(
IStatBuilder statBuilder, IFormBuilder formBuilder, IValueBuilder valueBuilder)
{
var statBuilderResults = statBuilder.Build(default(BuildParameters).With(new ModifierSource.Global()));
var (form, formValueConverter) = formBuilder.Build();
foreach (var (stats, source, statValueConverter) in statBuilderResults)
{
var value = formValueConverter(statValueConverter(valueBuilder)).Build(default);
yield return new Modifier(stats, form, value, source);
}
}
private static IEnumerable<Modifier> CreateModifier(
IStatBuilder statBuilder, IFormBuilder formBuilder, IValueBuilder valueBuilder,
IConditionBuilder conditionBuilder)
{
return CreateModifier(statBuilder.WithCondition(conditionBuilder), formBuilder, valueBuilder);
}
private ParseResult Parse(string stat)
=> _parser.ParseRawModifier(stat, new ModifierSource.Global(), Entity.Character);
}
}