Skip to content

Commit a7eb524

Browse files
committed
Add test for batch calculation return order
1 parent 56e0bcc commit a7eb524

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

Difficalcy.Tests/DummyCalculatorServiceTest.cs

+69-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,68 @@ public class DummyCalculatorServiceTest : CalculatorServiceTest<DummyScore, Dumm
1111
[InlineData(15, 1500, "test 1", 150)]
1212
[InlineData(10, 1000, "test 2", 100)]
1313
public void Test(double expectedDifficultyTotal, double expectedPerformanceTotal, string beatmapId, int mods)
14-
=> TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new DummyScore { BeatmapId = beatmapId, Mods = mods });
14+
=> TestGetCalculationReturnsCorrectValues(expectedDifficultyTotal, expectedPerformanceTotal, new DummyScore { BeatmapId = beatmapId, Mods = mods, Points = 100 });
15+
16+
[Fact]
17+
public async Task TestGetCalculationBatchReturnsCorrectValuesInOrder()
18+
{
19+
// values are intentionally in a random order to ensure unique beatmap grouping doesnt break return ordering
20+
var scores = new[]
21+
{
22+
new DummyScore { BeatmapId = "test 1", Mods = 200, Points = 200 }, // 3
23+
new DummyScore { BeatmapId = "test 2", Mods = 300, Points = 100 }, // 4
24+
new DummyScore { BeatmapId = "test 2", Mods = 300, Points = 200 }, // 5
25+
new DummyScore { BeatmapId = "test 3", Mods = 500, Points = 200 }, // 9
26+
new DummyScore { BeatmapId = "test 2", Mods = 400, Points = 200 }, // 7
27+
new DummyScore { BeatmapId = "test 1", Mods = 200, Points = 100 }, // 2
28+
new DummyScore { BeatmapId = "test 3", Mods = 600, Points = 100 }, // 10
29+
new DummyScore { BeatmapId = "test 2", Mods = 400, Points = 100 }, // 6
30+
new DummyScore { BeatmapId = "test 3", Mods = 500, Points = 100 }, // 8
31+
new DummyScore { BeatmapId = "test 1", Mods = 100, Points = 200 }, // 1
32+
new DummyScore { BeatmapId = "test 3", Mods = 600, Points = 200 }, // 11
33+
new DummyScore { BeatmapId = "test 1", Mods = 100, Points = 100 }, // 0
34+
};
35+
36+
var calculations = (await CalculatorService.GetCalculationBatch(scores)).ToArray();
37+
38+
Assert.Equal(12, calculations.Length);
39+
40+
Assert.Equal(20, calculations[0].Difficulty.Total); // 3
41+
Assert.Equal(4000, calculations[0].Performance.Total);
42+
43+
Assert.Equal(30, calculations[1].Difficulty.Total); // 4
44+
Assert.Equal(3000, calculations[1].Performance.Total);
45+
46+
Assert.Equal(30, calculations[2].Difficulty.Total); // 5
47+
Assert.Equal(6000, calculations[2].Performance.Total);
48+
49+
Assert.Equal(50, calculations[3].Difficulty.Total); // 9
50+
Assert.Equal(10000, calculations[3].Performance.Total);
51+
52+
Assert.Equal(40, calculations[4].Difficulty.Total); // 7
53+
Assert.Equal(8000, calculations[4].Performance.Total);
54+
55+
Assert.Equal(20, calculations[5].Difficulty.Total); // 2
56+
Assert.Equal(2000, calculations[5].Performance.Total);
57+
58+
Assert.Equal(60, calculations[6].Difficulty.Total); // 10
59+
Assert.Equal(6000, calculations[6].Performance.Total);
60+
61+
Assert.Equal(40, calculations[7].Difficulty.Total); // 6
62+
Assert.Equal(4000, calculations[7].Performance.Total);
63+
64+
Assert.Equal(50, calculations[8].Difficulty.Total); // 8
65+
Assert.Equal(5000, calculations[8].Performance.Total);
66+
67+
Assert.Equal(10, calculations[9].Difficulty.Total); // 1
68+
Assert.Equal(2000, calculations[9].Performance.Total);
69+
70+
Assert.Equal(60, calculations[10].Difficulty.Total); // 11
71+
Assert.Equal(12000, calculations[10].Performance.Total);
72+
73+
Assert.Equal(10, calculations[11].Difficulty.Total); // 0
74+
Assert.Equal(1000, calculations[11].Performance.Total);
75+
}
1576
}
1677

1778
/// <summary>
@@ -29,17 +90,17 @@ public class DummyCalculatorService(ICache cache) : CalculatorService<DummyScore
2990
CalculatorUrl = $"not.a.real.url"
3091
};
3192

32-
protected override (object, string) CalculateDifficultyAttributes(DummyScore score)
93+
protected override (object, string) CalculateDifficultyAttributes(string beatmapId, int mods)
3394
{
34-
var difficulty = score.Mods / 10.0;
95+
var difficulty = mods / 10.0;
3596
return (difficulty, difficulty.ToString());
3697
}
3798

3899
protected override DummyCalculation CalculatePerformance(DummyScore score, object difficultyAttributes) =>
39100
new()
40101
{
41102
Difficulty = new DummyDifficulty() { Total = (double)difficultyAttributes },
42-
Performance = new DummyPerformance() { Total = (double)difficultyAttributes * 100 }
103+
Performance = new DummyPerformance() { Total = (double)difficultyAttributes * score.Points }
43104
};
44105

45106
protected override object DeserialiseDifficultyAttributes(string difficultyAttributesJson) =>
@@ -49,7 +110,10 @@ protected override Task EnsureBeatmap(string beatmapId) =>
49110
Task.FromResult(true);
50111
}
51112

52-
public record DummyScore : Score { }
113+
public record DummyScore : Score
114+
{
115+
public int Points { get; init; }
116+
}
53117
public record DummyDifficulty : Difficulty { }
54118
public record DummyPerformance : Performance { }
55119
public record DummyCalculation : Calculation<DummyDifficulty, DummyPerformance> { }

0 commit comments

Comments
 (0)