1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-31 01:42:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

324 lines
12 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
2019-03-25 00:02:36 +08:00
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
2020-02-04 19:52:26 +08:00
using osu.Framework.Allocation;
2017-11-12 14:01:13 +08:00
using osu.Framework.Graphics;
2019-03-25 00:02:36 +08:00
using osu.Framework.Graphics.Containers;
2017-11-12 14:01:13 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
using osu.Game.Online.API;
2019-07-08 17:02:10 +08:00
using osu.Game.Online.API.Requests.Responses;
2020-02-04 19:52:26 +08:00
using osu.Game.Overlays;
2017-11-12 14:01:13 +08:00
using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Rulesets.Osu.Mods;
2018-11-28 15:12:57 +08:00
using osu.Game.Scoring;
2019-03-25 00:02:36 +08:00
using osu.Game.Users;
2019-07-09 17:16:58 +08:00
using osuTK.Graphics;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Tests.Visual.Online
2017-11-12 14:01:13 +08:00
{
public class TestSceneScoresContainer : OsuTestScene
2017-11-12 14:01:13 +08:00
{
2020-02-04 19:52:26 +08:00
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private TestScoresContainer scoresContainer;
2018-04-13 17:19:50 +08:00
[SetUpSteps]
public void SetUp() => Schedule(() =>
{
Child = new Container
2017-11-12 14:01:13 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Width = 0.8f,
Children = new Drawable[]
2017-11-12 14:01:13 +08:00
{
new Box
2019-07-09 17:16:58 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
scoresContainer = new TestScoresContainer
{
Beatmap = { Value = CreateAPIBeatmap() }
}
}
};
});
[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]
public void TestUserBest()
{
AddStep("Load scores with personal best", () =>
{
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)", () =>
{
var allScores = createScores();
var userBest = createUserBest();
userBest.Position = null;
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;
});
2018-04-13 17:19:50 +08:00
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;
scoresContainer.Scores = allScores;
});
AddUntilStep("best score not displayed", () => scoresContainer.ChildrenOfType<DrawableTopScore>().Count() == 1);
}
private int onlineID = 1;
private APIScoresCollection createScores()
{
var scores = new APIScoresCollection
2017-11-12 14:01:13 +08:00
{
Scores = new List<APIScore>
2017-11-12 14:01:13 +08:00
{
new APIScore
2017-11-12 14:01:13 +08:00
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
2017-11-12 14:01:13 +08:00
{
Id = 6602580,
Username = @"waaiiru",
Country = new Country
{
FullName = @"Spain",
FlagName = @"ES",
},
2017-11-12 14:01:13 +08:00
},
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,
2017-11-12 14:01:13 +08:00
},
new APIScore
2017-11-12 14:01:13 +08:00
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
2017-11-12 14:01:13 +08:00
{
Id = 4608074,
Username = @"Skycries",
Country = new Country
{
FullName = @"Brazil",
FlagName = @"BR",
},
2017-11-12 14:01:13 +08:00
},
Mods = new[]
{
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new APIMod { Acronym = new OsuModHidden().Acronym },
new APIMod { Acronym = new OsuModFlashlight().Acronym },
},
Rank = ScoreRank.S,
PP = 190,
MaxCombo = 1234,
TotalScore = 1234789,
Accuracy = 0.9997,
2017-11-12 14:01:13 +08:00
},
new APIScore
2019-07-08 17:02:10 +08:00
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 1014222,
Username = @"eLy",
Country = new Country
{
FullName = @"Japan",
FlagName = @"JP",
},
},
Mods = new[]
2019-07-08 17:02:10 +08:00
{
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
new APIMod { Acronym = new OsuModHidden().Acronym },
2019-07-08 17:02:10 +08:00
},
Rank = ScoreRank.B,
PP = 180,
MaxCombo = 1234,
TotalScore = 12345678,
Accuracy = 0.9854,
2019-07-08 17:02:10 +08:00
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
{
Id = 1541390,
Username = @"Toukai",
Country = new Country
{
FullName = @"Canada",
FlagName = @"CA",
},
},
Mods = new[]
{
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
},
Rank = ScoreRank.C,
PP = 170,
MaxCombo = 1234,
TotalScore = 1234567,
Accuracy = 0.8765,
},
new APIScore
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
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,
},
}
};
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
2017-11-12 14:01:13 +08:00
{
Date = DateTimeOffset.Now,
OnlineID = onlineID++,
User = new APIUser
2019-12-03 15:18:36 +08:00
{
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 = 1337,
};
private class TestScoresContainer : ScoresContainer
{
2021-10-28 16:48:56 +08:00
public new APIScoresCollection Scores
{
set => base.Scores = value;
}
}
2017-11-12 14:01:13 +08:00
}
}