1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Fix TestFriendScore intermittently failing due to randomness

If `createRandomScore()` happened to randomly pick the highest total
score when called with `friend` as the sole argument, that particular
score would not be pink.

`GetScoreByUsername()` would arbitrarily pick the first score for the
user, so in this particular case where a friend had the number 1 score,
the test would wrongly fail.

Fix by checking whether any of the 3 added friend scores have received
the pink colour. Because there is more than 1 friend score in the test,
doing so ensures that at least one of those should eventually become
pink (because, obviously, you can't have two scores at number 1).
This commit is contained in:
Bartłomiej Dach 2023-09-21 21:09:24 +02:00
parent 9301a1907a
commit e45d456324
No known key found for this signature in database

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -165,8 +166,10 @@ namespace osu.Game.Tests.Visual.Gameplay
() => Does.Not.Contain("#FF549A")); () => Does.Not.Contain("#FF549A"));
AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3); AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3);
AddUntilStep("friend score is pink", AddUntilStep("at least one friend score is pink",
() => leaderboard.GetScoreByUsername("my friend").ChildrenOfType<Box>().Select(b => ((Colour4)b.Colour).ToHex()), () => leaderboard.GetAllScoresForUsername("my friend")
.SelectMany(score => score.ChildrenOfType<Box>())
.Select(b => ((Colour4)b.Colour).ToHex()),
() => Does.Contain("#FF549A")); () => Does.Contain("#FF549A"));
} }
@ -211,10 +214,8 @@ namespace osu.Game.Tests.Visual.Gameplay
return scoreItem != null && scoreItem.ScorePosition == expectedPosition; return scoreItem != null && scoreItem.ScorePosition == expectedPosition;
} }
public GameplayLeaderboardScore GetScoreByUsername(string username) public IEnumerable<GameplayLeaderboardScore> GetAllScoresForUsername(string username)
{ => Flow.Where(i => i.User?.Username == username);
return Flow.FirstOrDefault(i => i.User?.Username == username);
}
} }
} }
} }