diff --git a/src/Modules/RoundRankingModule/Models/PointsRepartition.cs b/src/Modules/RoundRankingModule/Models/PointsRepartition.cs index ff9e823a..d86df818 100644 --- a/src/Modules/RoundRankingModule/Models/PointsRepartition.cs +++ b/src/Modules/RoundRankingModule/Models/PointsRepartition.cs @@ -7,18 +7,13 @@ public class PointsRepartition : List { public const string ModeScriptSetting = "S_PointsRepartition"; - private const string DefaultValue = "10,6,4,3,2,1"; + public const string DefaultValue = "10,6,4,3,2,1"; public PointsRepartition() { Update(DefaultValue); } - private PointsRepartition(PointsRepartition pointsRepartition) - { - this.AddRange(pointsRepartition); - } - /// /// Consumes new a points repartition. /// Values are comma separated. @@ -39,13 +34,4 @@ public int GetGainedPoints(int rank) { return rank <= Count ? this[rank - 1] : this.LastOrDefault(0); } - - /// - /// Creates a copy of the object. - /// - /// - public PointsRepartition Clone() - { - return new PointsRepartition(this); - } } diff --git a/tests/Modules/RoundRankingModule.Tests/Models/PointsRepartitionTests.cs b/tests/Modules/RoundRankingModule.Tests/Models/PointsRepartitionTests.cs index 4719b0dc..9379a5a7 100644 --- a/tests/Modules/RoundRankingModule.Tests/Models/PointsRepartitionTests.cs +++ b/tests/Modules/RoundRankingModule.Tests/Models/PointsRepartitionTests.cs @@ -1,6 +1,48 @@ -namespace EvoSC.Modules.Official.RoundRankingModule.Tests.Models; +using EvoSC.Modules.Official.RoundRankingModule.Models; + +namespace EvoSC.Modules.Official.RoundRankingModule.Tests.Models; public class PointsRepartitionTests { - + [Theory] + [InlineData("1,2,3,4,5,6,7", new[] { 1, 2, 3, 4, 5, 6, 7 })] + [InlineData("10,6,4,3,2,1", new[] { 10, 6, 4, 3, 2, 1 })] + [InlineData("0, 0, 1, 2, -4, -5", new[] { 0, 0, 1, 2, -4, -5 })] + public void Sets_Points_From_String(string pointsRepartition, int[] expectedPoints) + { + var pr = new PointsRepartition(); + pr.Update(pointsRepartition); + + Assert.Equal(expectedPoints, pr.ToArray()); + } + + [Fact] + public void Initializes_PointsRepartition_With_Default() + { + var expected = PointsRepartition.DefaultValue.Split(',').Select(int.Parse).ToList(); + + Assert.Equal(expected, new PointsRepartition()); + } + + [Theory] + [InlineData("10,6,4,3,2,1", 1, 10)] + [InlineData("10,6,4,3,2,1", 2, 6)] + [InlineData("10,6,4,3,2,1", 3, 4)] + [InlineData("10,6,4,3,2,1", 4, 3)] + [InlineData("10,6,4,3,2,1", 5, 2)] + [InlineData("10,6,4,3,2,1", 6, 1)] + [InlineData("10,6,4,3,2,1", 7, 1)] + [InlineData("-1,-2,0,7,3", 1, -1)] + [InlineData("-1,-2,0,7,3", 2, -2)] + [InlineData("-1,-2,0,7,3", 3, 0)] + [InlineData("-1,-2,0,7,3", 4, 7)] + [InlineData("-1,-2,0,7,3", 5, 3)] + [InlineData("-1,-2,0,7,3", 6, 3)] + public void Gets_Gained_Points_Correctly(string pointsRepartition, int rank, int expectedGainedPoints) + { + var pr = new PointsRepartition(); + pr.Update(pointsRepartition); + + Assert.Equal(expectedGainedPoints, pr.GetGainedPoints(rank)); + } }