Add better test coverage of user top scores

This commit is contained in:
Dean Herbert
2022-01-17 16:23:58 +09:00
parent 6436b6186f
commit a80e461000

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -30,9 +31,7 @@ namespace osu.Game.Tests.Visual.Online
private TestScoresContainer scoresContainer; private TestScoresContainer scoresContainer;
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public void SetUp() => Schedule(() =>
{
AddStep("Create container", () =>
{ {
Child = new Container Child = new Container
{ {
@ -54,49 +53,103 @@ namespace osu.Game.Tests.Visual.Online
} }
}; };
}); });
[Test]
public void TestNoUserBest()
{
AddStep("Scores with no user best", () =>
{
var allScores = createScores();
allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("no user best displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
AddStep("Load null scores", () => scoresContainer.Scores = null);
AddUntilStep("wait for scores not displayed", () => !scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("no best score displayed", () => !scoresContainer.ChildrenOfType<DrawableTopScore>().Any());
AddStep("Load only one score", () =>
{
var allScores = createScores();
allScores.Scores.RemoveRange(1, allScores.Scores.Count - 1);
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores not displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Count() == 1);
AddAssert("no best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
} }
[Test] [Test]
public void TestDisplay() public void TestUserBest()
{ {
foreach (var s in allScores.Scores) AddStep("Load scores with personal best", () =>
{ {
s.Statistics = new Dictionary<string, int> var allScores = createScores();
allScores.UserScore = createUserBest();
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
AddStep("Load scores with personal best (null position)", () =>
{ {
{ "count_300", RNG.Next(2000) }, var allScores = createScores();
{ "count_100", RNG.Next(2000) }, var userBest = createUserBest();
{ "count_50", RNG.Next(2000) }, userBest.Position = null;
{ "count_miss", RNG.Next(2000) } allScores.UserScore = userBest;
scoresContainer.Scores = allScores;
});
AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 2);
AddStep("Load scores with personal best (first place)", () =>
{
var allScores = createScores();
allScores.UserScore = new APIScoreWithPosition
{
Score = allScores.Scores.First(),
Position = 1,
}; };
} scoresContainer.Scores = allScores;
});
AddStep("Load all scores", () => AddUntilStep("wait for scores displayed", () => scoresContainer.ChildrenOfType<ScoreTableRowBackground>().Any());
AddAssert("best score displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
AddStep("Scores with no user best", () =>
{ {
var allScores = createScores();
allScores.UserScore = null; allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddStep("Load null scores", () => scoresContainer.Scores = null);
AddStep("Load only one score", () => scoresContainer.Scores = oneScore);
AddStep("Load scores with my best", () =>
{
allScores.UserScore = myBestScore;
scoresContainer.Scores = allScores; scoresContainer.Scores = allScores;
}); });
AddStep("Load scores with null my best position", () => AddAssert("best score not displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
{
allScores.UserScore = myBestScoreWithNullPosition;
scoresContainer.Scores = allScores;
});
} }
private readonly APIScoresCollection allScores = new APIScoresCollection private int onlineID = 1;
private APIScoresCollection createScores()
{
var scores = new APIScoresCollection
{ {
Scores = new List<APIScore> Scores = new List<APIScore>
{ {
new APIScore new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 6602580, Id = 6602580,
@ -123,6 +176,7 @@ namespace osu.Game.Tests.Visual.Online
new APIScore new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 4608074, Id = 4608074,
@ -148,6 +202,7 @@ namespace osu.Game.Tests.Visual.Online
new APIScore new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 1014222, Id = 1014222,
@ -172,6 +227,7 @@ namespace osu.Game.Tests.Visual.Online
new APIScore new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 1541390, Id = 1541390,
@ -195,6 +251,7 @@ namespace osu.Game.Tests.Visual.Online
new APIScore new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 7151382, Id = 7151382,
@ -214,11 +271,26 @@ namespace osu.Game.Tests.Visual.Online
} }
}; };
private readonly APIScoreWithPosition myBestScore = new APIScoreWithPosition foreach (var s in scores.Scores)
{
s.Statistics = new Dictionary<string, int>
{
{ "count_300", RNG.Next(2000) },
{ "count_100", RNG.Next(2000) },
{ "count_50", RNG.Next(2000) },
{ "count_miss", RNG.Next(2000) }
};
}
return scores;
}
private APIScoreWithPosition createUserBest() => new APIScoreWithPosition
{ {
Score = new APIScore Score = new APIScore
{ {
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser User = new APIUser
{ {
Id = 7151382, Id = 7151382,
@ -238,63 +310,6 @@ namespace osu.Game.Tests.Visual.Online
Position = 1337, Position = 1337,
}; };
private readonly APIScoreWithPosition myBestScoreWithNullPosition = new APIScoreWithPosition
{
Score = new APIScore
{
Date = DateTimeOffset.Now,
User = new APIUser
{
Id = 7151382,
Username = @"Mayuri Hana",
Country = new Country
{
FullName = @"Thailand",
FlagName = @"TH",
},
},
Rank = ScoreRank.D,
PP = 160,
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
},
Position = null,
};
private readonly APIScoresCollection oneScore = new APIScoresCollection
{
Scores = new List<APIScore>
{
new APIScore
{
Date = DateTimeOffset.Now,
User = new APIUser
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
{
FullName = @"Spain",
FlagName = @"ES",
},
},
Mods = new[]
{
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new APIMod { Acronym = new OsuModHidden().Acronym },
new APIMod { Acronym = new OsuModFlashlight().Acronym },
new APIMod { Acronym = new OsuModHardRock().Acronym },
},
Rank = ScoreRank.XH,
PP = 200,
MaxCombo = 1234,
TotalScore = 1234567890,
Accuracy = 1,
}
}
};
private class TestScoresContainer : ScoresContainer private class TestScoresContainer : ScoresContainer
{ {
public new APIScoresCollection Scores public new APIScoresCollection Scores