-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from PoESkillTree/calculation-items-skills
Calculation Rewriting Part 2.3: Skill and Item parsing
- Loading branch information
Showing
416 changed files
with
18,769 additions
and
4,650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
PoESkillTree.Computation.Builders.Tests/Behaviors/AffectedByModifiersToOtherStatValueTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Linq; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PoESkillTree.Computation.Builders.Behaviors; | ||
using PoESkillTree.Computation.Builders.Stats; | ||
using PoESkillTree.Computation.Common; | ||
using PoESkillTree.Utils.Extensions; | ||
|
||
namespace PoESkillTree.Computation.Builders.Tests.Behaviors | ||
{ | ||
[TestFixture] | ||
public class AffectedByModifiersToOtherStatValueTest | ||
{ | ||
[TestCase(true, true)] | ||
[TestCase(true, false)] | ||
[TestCase(false, false)] | ||
public void CalculateReturnsCorrectResult(bool formIsAffected, bool conditionStatValue) | ||
{ | ||
var expected = (NodeValue?) 42; | ||
var affectedForm = Form.Increase; | ||
var retrievedForm = formIsAffected ? affectedForm : Form.BaseAdd; | ||
|
||
var transformedStat = new Stat("transformed"); | ||
var otherStat = new Stat("other"); | ||
var conditionStat = new Stat("condition"); | ||
var expectedPaths = new (IStat, PathDefinition)[] { (transformedStat, PathDefinition.MainPath) } | ||
.AsEnumerable(); | ||
if (formIsAffected && conditionStatValue) | ||
expectedPaths = expectedPaths.Append((otherStat, PathDefinition.MainPath)); | ||
|
||
var context = Mock.Of<IValueCalculationContext>(c => | ||
c.GetValues(retrievedForm, expectedPaths) == new[] { expected } && | ||
c.GetValue(conditionStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?) conditionStatValue); | ||
var transformedValue = new FunctionalValue(c => c.GetValues(retrievedForm, transformedStat).Sum(), ""); | ||
var sut = new AffectedByModifiersToOtherStatValue(transformedStat, otherStat, conditionStat, affectedForm, | ||
transformedValue); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
PoESkillTree.Computation.Builders.Tests/Behaviors/DamageEffectivenessBaseValueTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PoESkillTree.Computation.Builders.Behaviors; | ||
using PoESkillTree.Computation.Builders.Stats; | ||
using PoESkillTree.Computation.Common; | ||
|
||
namespace PoESkillTree.Computation.Builders.Tests.Behaviors | ||
{ | ||
[TestFixture] | ||
public class DamageEffectivenessBaseValueTest | ||
{ | ||
[TestCase(null, null)] | ||
[TestCase(1.5, 2)] | ||
public void CalculateReturnsCorrectResult(double? baseSetEffectiveness, double? baseAddEffectiveness) | ||
{ | ||
var baseSet = (NodeValue?) 2; | ||
var baseAdd = (NodeValue?) 3; | ||
var expected = baseSet * (baseSetEffectiveness ?? 1) + baseAdd * (baseAddEffectiveness ?? 1); | ||
|
||
var context = Mock.Of<IValueCalculationContext>(c => | ||
c.GetValue(TransformedStat, NodeType.BaseSet, PathDefinition.MainPath) == baseSet && | ||
c.GetValue(TransformedStat, NodeType.BaseAdd, PathDefinition.MainPath) == baseAdd && | ||
c.GetValue(SetEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == | ||
(NodeValue?) baseSetEffectiveness && | ||
c.GetValue(AddEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == | ||
(NodeValue?) baseAddEffectiveness); | ||
var sut = CreateSut( | ||
c => c.GetValue(TransformedStat, NodeType.BaseSet) + c.GetValue(TransformedStat, NodeType.BaseAdd)); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void CalculateDoesNotTransformOtherForms() | ||
{ | ||
var expected = (NodeValue?) 42; | ||
var context = Mock.Of<IValueCalculationContext>(c => | ||
c.GetValue(TransformedStat, NodeType.Increase, PathDefinition.MainPath) == expected && | ||
c.GetValue(SetEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?) 2 && | ||
c.GetValue(AddEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?) 2); | ||
var sut = CreateSut(c => c.GetValue(TransformedStat, NodeType.Increase)); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
public void CalculateDoesNotTransformOtherStats() | ||
{ | ||
var expected = (NodeValue?) 42; | ||
var otherStat = new Stat("other"); | ||
var context = Mock.Of<IValueCalculationContext>(c => | ||
c.GetValue(otherStat, NodeType.BaseSet, PathDefinition.MainPath) == expected && | ||
c.GetValue(SetEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?) 2 && | ||
c.GetValue(AddEffectivenessStat, NodeType.Total, PathDefinition.MainPath) == (NodeValue?) 2); | ||
var sut = CreateSut(c => c.GetValue(otherStat, NodeType.BaseSet)); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
private static DamageEffectivenessBaseValue CreateSut(Func<IValueCalculationContext, NodeValue?> baseCalculate) | ||
=> new DamageEffectivenessBaseValue(TransformedStat, SetEffectivenessStat, AddEffectivenessStat, | ||
new FunctionalValue(baseCalculate, "")); | ||
|
||
private static readonly IStat TransformedStat = new Stat("transformed"); | ||
private static readonly IStat SetEffectivenessStat = new Stat("setEffectiveness"); | ||
private static readonly IStat AddEffectivenessStat = new Stat("addEffectiveness"); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
PoESkillTree.Computation.Builders.Tests/Behaviors/MaximumFormAggregatingValueTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Linq; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PoESkillTree.Computation.Builders.Behaviors; | ||
using PoESkillTree.Computation.Builders.Stats; | ||
using PoESkillTree.Computation.Common; | ||
|
||
namespace PoESkillTree.Computation.Builders.Tests.Behaviors | ||
{ | ||
[TestFixture] | ||
public class MaximumFormAggregatingValueTest | ||
{ | ||
[Test] | ||
public void CalculateReturnsNullWithOnlyNullValues() | ||
{ | ||
var sut = CreateSut(); | ||
var context = MockContext(null, null); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.IsNull(actual); | ||
} | ||
|
||
[TestCase(0, ExpectedResult = 0)] | ||
[TestCase(0, null, 1, 3, 4, 2, ExpectedResult = 4)] | ||
public double CalculateReturnsCorrectResult(params int?[] values) | ||
{ | ||
var sut = CreateSut(); | ||
var context = MockContext(values); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
return actual.Single(); | ||
} | ||
|
||
[Test] | ||
public void CalculateChecksForSameForm() | ||
{ | ||
var transformedValue = new FunctionalValue(c => c.GetValues(Form.BaseSet, Paths).First(), ""); | ||
var sut = CreateSut(Stat, Form.More, transformedValue); | ||
var context = MockContext(2, 4); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(2, actual.Single()); | ||
} | ||
|
||
[Test] | ||
public void CalculateChecksForSameSta() | ||
{ | ||
var transformedValue = new FunctionalValue(c => c.GetValues(Form.BaseSet, Paths).First(), ""); | ||
var sut = CreateSut(new Stat("a"), Form.BaseSet, transformedValue); | ||
var context = MockContext(2, 4); | ||
|
||
var actual = sut.Calculate(context); | ||
|
||
Assert.AreEqual(2, actual.Single()); | ||
} | ||
|
||
[Test] | ||
public void CalculateThrowsIfPathsContainsSameAndDifferentStats() | ||
{ | ||
var paths = new[] { (Stat, PathDefinition.MainPath), (new Stat("a"), PathDefinition.MainPath) }; | ||
var transformedValue = new FunctionalValue(c => c.GetValues(Form.BaseSet, paths).Single(), ""); | ||
var sut = CreateSut(Stat, Form.BaseSet, transformedValue); | ||
var nodeValues = new NodeValue?[0]; | ||
var context = Mock.Of<IValueCalculationContext>(c => c.GetValues(Form.BaseSet, paths) == nodeValues); | ||
|
||
Assert.Throws<InvalidOperationException>(() => sut.Calculate(context)); | ||
} | ||
|
||
private static readonly IStat Stat = new Stat("s"); | ||
|
||
private static readonly (IStat, PathDefinition)[] Paths = | ||
{ | ||
(Stat, PathDefinition.MainPath), (Stat, new PathDefinition(new ModifierSource.Local.Given())) | ||
}; | ||
|
||
private static MaximumFormAggregatingValue CreateSut() | ||
{ | ||
var transformedValue = new FunctionalValue(c => c.GetValues(Form.BaseSet, Paths).Single(), ""); | ||
return CreateSut(Stat, Form.BaseSet, transformedValue); | ||
} | ||
|
||
private static MaximumFormAggregatingValue CreateSut(IStat stat, Form form, IValue transformedValue) | ||
=> new MaximumFormAggregatingValue(stat, form, transformedValue); | ||
|
||
private static IValueCalculationContext MockContext(params int?[] values) | ||
{ | ||
var nodeValues = values.Select(v => (NodeValue?) v); | ||
return Mock.Of<IValueCalculationContext>(c => c.GetValues(Form.BaseSet, Paths) == nodeValues); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
PoESkillTree.Computation.Builders.Tests/Behaviors/RequirementUncappedSubtotalValueTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Linq; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PoESkillTree.Computation.Builders.Behaviors; | ||
using PoESkillTree.Computation.Builders.Stats; | ||
using PoESkillTree.Computation.Common; | ||
using PoESkillTree.GameModel.Items; | ||
|
||
namespace PoESkillTree.Computation.Builders.Tests.Behaviors | ||
{ | ||
[TestFixture] | ||
public class RequirementUncappedSubtotalValueTest | ||
{ | ||
[TestCase(-1.0, null, 1.0)] | ||
[TestCase(42.0, 43.0, 41.0, 43.0, 40.0)] | ||
public void CalculateReturnsCorrectResult(params double?[] values) | ||
{ | ||
var expected = (NodeValue?) values.Max(); | ||
var transformedStat = new Stat("transformed"); | ||
var paths = values | ||
.Select((_, i) => new PathDefinition(new ModifierSource.Local.Gem(ItemSlot.Helm, i))) | ||
.ToList(); | ||
var contextMock = new Mock<IValueCalculationContext>(); | ||
contextMock.Setup(c => c.GetPaths(transformedStat)).Returns(paths); | ||
for (var i = 0; i < paths.Count; i++) | ||
{ | ||
var path = paths[i]; | ||
contextMock.Setup(c => c.GetValue(transformedStat, NodeType.PathTotal, path)) | ||
.Returns((NodeValue?) values[i]); | ||
} | ||
var transformedValue = new FunctionalValue(c => c.GetValues(transformedStat, NodeType.PathTotal).Sum(), ""); | ||
var sut = new RequirementUncappedSubtotalValue(transformedStat, transformedValue); | ||
|
||
var actual = sut.Calculate(contextMock.Object); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.