Skip to content

Commit

Permalink
Merge pull request #24203 from peppy/results-screen-testability
Browse files Browse the repository at this point in the history
Make results / statistics visual testing easier with better data population
  • Loading branch information
bdach authored Jul 13, 2023
2 parents 1ed15dc + 56409fa commit 601e3fe
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 34 deletions.
58 changes: 34 additions & 24 deletions osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,35 @@ public void TestScaling()
}));
}

private int onlineScoreID = 1;

[TestCase(1, ScoreRank.X)]
[TestCase(0.9999, ScoreRank.S)]
[TestCase(0.975, ScoreRank.S)]
[TestCase(0.925, ScoreRank.A)]
[TestCase(0.85, ScoreRank.B)]
[TestCase(0.75, ScoreRank.C)]
[TestCase(0.5, ScoreRank.D)]
[TestCase(0.2, ScoreRank.D)]
public void TestResultsWithPlayer(double accuracy, ScoreRank rank)
{
TestResultsScreen screen = null;

loadResultsScreen(() =>
{
var score = TestResources.CreateTestScoreInfo();
score.OnlineID = onlineScoreID++;
score.HitEvents = TestSceneStatisticsPanel.CreatePositionDistributedHitEvents();
score.Accuracy = accuracy;
score.Rank = rank;
return screen = createResultsScreen(score);
});
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay present", () => screen.RetryOverlay != null);
}

[Test]
public void TestResultsWithoutPlayer()
{
Expand All @@ -82,34 +111,14 @@ public void TestResultsWithoutPlayer()
RelativeSizeAxes = Axes.Both
};
stack.Push(screen = createResultsScreen());
var score = TestResources.CreateTestScoreInfo();
stack.Push(screen = createResultsScreen(score));
});
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay not present", () => screen.RetryOverlay == null);
}

[TestCase(0.2, ScoreRank.D)]
[TestCase(0.5, ScoreRank.D)]
[TestCase(0.75, ScoreRank.C)]
[TestCase(0.85, ScoreRank.B)]
[TestCase(0.925, ScoreRank.A)]
[TestCase(0.975, ScoreRank.S)]
[TestCase(0.9999, ScoreRank.S)]
[TestCase(1, ScoreRank.X)]
public void TestResultsWithPlayer(double accuracy, ScoreRank rank)
{
TestResultsScreen screen = null;

var score = TestResources.CreateTestScoreInfo();

score.Accuracy = accuracy;
score.Rank = rank;

loadResultsScreen(() => screen = createResultsScreen(score));
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddAssert("retry overlay present", () => screen.RetryOverlay != null);
}

[Test]
public void TestResultsForUnranked()
{
Expand Down Expand Up @@ -328,13 +337,14 @@ public TestResultsContainer(IScreen screen)
}
}

private partial class TestResultsScreen : ResultsScreen
private partial class TestResultsScreen : SoloResultsScreen
{
public HotkeyRetryOverlay RetryOverlay;

public TestResultsScreen(ScoreInfo score)
: base(score, true)
{
ShowUserStatistics = true;
}

protected override void LoadComplete()
Expand Down
62 changes: 52 additions & 10 deletions osu.Game.Tests/Visual/Ranking/TestSceneStatisticsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Solo;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;
Expand All @@ -23,26 +24,28 @@
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Tests.Resources;
using osu.Game.Users;
using osuTK;

namespace osu.Game.Tests.Visual.Ranking
{
public partial class TestSceneStatisticsPanel : OsuTestScene
{
[Test]
public void TestScoreWithTimeStatistics()
public void TestScoreWithPositionStatistics()
{
var score = TestResources.CreateTestScoreInfo();
score.HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents();
score.OnlineID = 1234;
score.HitEvents = CreatePositionDistributedHitEvents();

loadPanel(score);
}

[Test]
public void TestScoreWithPositionStatistics()
public void TestScoreWithTimeStatistics()
{
var score = TestResources.CreateTestScoreInfo();
score.HitEvents = createPositionDistributedHitEvents();
score.HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents();

loadPanel(score);
}
Expand Down Expand Up @@ -79,28 +82,67 @@ public void TestNullScore()

private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
{
Child = new StatisticsPanel
Child = new SoloStatisticsPanel(score)
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible },
Score = { Value = score }
Score = { Value = score },
StatisticsUpdate =
{
Value = new SoloStatisticsUpdate(score, new UserStatistics
{
Level = new UserStatistics.LevelInfo
{
Current = 5,
Progress = 20,
},
GlobalRank = 38000,
CountryRank = 12006,
PP = 2134,
RankedScore = 21123849,
Accuracy = 0.985,
PlayCount = 13375,
PlayTime = 354490,
TotalScore = 128749597,
TotalHits = 0,
MaxCombo = 1233,
}, new UserStatistics
{
Level = new UserStatistics.LevelInfo
{
Current = 5,
Progress = 30,
},
GlobalRank = 36000,
CountryRank = 12000,
PP = (decimal)2134.5,
RankedScore = 23897015,
Accuracy = 0.984,
PlayCount = 13376,
PlayTime = 35789,
TotalScore = 132218497,
TotalHits = 0,
MaxCombo = 1233,
})
}
};
});

private static List<HitEvent> createPositionDistributedHitEvents()
public static List<HitEvent> CreatePositionDistributedHitEvents()
{
var hitEvents = new List<HitEvent>();
var hitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents();

// Use constant seed for reproducibility
var random = new Random(0);

for (int i = 0; i < 500; i++)
for (int i = 0; i < hitEvents.Count; i++)
{
double angle = random.NextDouble() * 2 * Math.PI;
double radius = random.NextDouble() * 0.5f * OsuHitObject.OBJECT_RADIUS;

var position = new Vector2((float)(radius * Math.Cos(angle)), (float)(radius * Math.Sin(angle)));

hitEvents.Add(new HitEvent(0, HitResult.Perfect, new HitCircle(), new HitCircle(), position));
hitEvents[i] = hitEvents[i].With(position);
}

return hitEvents;
Expand Down

0 comments on commit 601e3fe

Please sign in to comment.