Skip to content

Commit

Permalink
Add points repartition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
araszka committed Nov 17, 2024
1 parent b67347a commit d3f7de8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
16 changes: 1 addition & 15 deletions src/Modules/RoundRankingModule/Models/PointsRepartition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
public class PointsRepartition : List<int>
{
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);
}

/// <summary>
/// Consumes new a points repartition.
/// Values are comma separated.
Expand All @@ -39,13 +34,4 @@ public int GetGainedPoints(int rank)
{
return rank <= Count ? this[rank - 1] : this.LastOrDefault(0);
}

/// <summary>
/// Creates a copy of the object.
/// </summary>
/// <returns></returns>
public PointsRepartition Clone()
{
return new PointsRepartition(this);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit d3f7de8

Please sign in to comment.