1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 17:37:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlaySuccessRate.cs

113 lines
3.7 KiB
C#
Raw Normal View History

2019-06-13 17:44:00 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2019-06-13 17:44:00 +08:00
using System.Linq;
using NUnit.Framework;
2020-02-05 05:39:51 +08:00
using osu.Framework.Allocation;
2019-06-13 17:44:00 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2020-08-25 02:19:33 +08:00
using osu.Framework.Testing;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2019-06-13 17:44:00 +08:00
using osu.Game.Beatmaps;
2020-08-25 02:19:33 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
2020-02-05 05:39:51 +08:00
using osu.Game.Overlays;
2019-06-13 17:44:00 +08:00
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Screens.Select.Details;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Online
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneBeatmapSetOverlaySuccessRate : OsuTestScene
2019-06-13 17:44:00 +08:00
{
private GraphExposingSuccessRate successRate;
2020-02-05 05:39:51 +08:00
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
2019-06-13 17:44:00 +08:00
[SetUp]
public void Setup() => Schedule(() =>
{
Child = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(275, 220),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray,
},
successRate = new GraphExposingSuccessRate
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(275, 220),
Padding = new MarginPadding(20)
}
}
};
});
[Test]
public void TestMetrics()
{
var firstBeatmap = createBeatmap();
var secondBeatmap = createBeatmap();
AddStep("set first set", () => successRate.Beatmap = firstBeatmap);
AddAssert("ratings set", () => successRate.Graph.FailTimes == firstBeatmap.FailTimes);
2019-06-13 17:44:00 +08:00
AddStep("set second set", () => successRate.Beatmap = secondBeatmap);
AddAssert("ratings set", () => successRate.Graph.FailTimes == secondBeatmap.FailTimes);
2019-06-13 17:44:00 +08:00
static APIBeatmap createBeatmap() => new APIBeatmap
2019-06-13 17:44:00 +08:00
{
FailTimes = new APIFailTimes
2019-06-13 17:44:00 +08:00
{
Fails = Enumerable.Range(1, 100).Select(_ => RNG.Next(10)).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(_ => RNG.Next(10)).ToArray(),
},
PassCount = RNG.Next(0, 999),
PlayCount = RNG.Next(1000, 1999),
2019-06-13 17:44:00 +08:00
};
}
2020-08-25 02:19:33 +08:00
[Test]
public void TestOnlyFailMetrics()
{
AddStep("set beatmap", () => successRate.Beatmap = new APIBeatmap
2020-08-25 02:19:33 +08:00
{
FailTimes = new APIFailTimes
2020-08-25 02:19:33 +08:00
{
Fails = Enumerable.Range(1, 100).ToArray(),
2020-08-25 02:19:33 +08:00
}
});
AddAssert("graph max values correct", () => successRate.ChildrenOfType<BarGraph>().All(graph => graph.MaxValue == 100));
2020-08-25 02:19:33 +08:00
}
2020-08-25 02:47:29 +08:00
[Test]
public void TestEmptyMetrics()
{
AddStep("set beatmap", () => successRate.Beatmap = new APIBeatmap
2020-08-25 02:47:29 +08:00
{
FailTimes = new APIFailTimes()
2020-08-25 02:47:29 +08:00
});
AddAssert("graph max values correct", () => successRate.ChildrenOfType<BarGraph>().All(graph => graph.MaxValue == 0));
2020-08-25 02:47:29 +08:00
}
2022-11-24 13:32:20 +08:00
private partial class GraphExposingSuccessRate : SuccessRate
2019-06-13 17:44:00 +08:00
{
public new FailRetryGraph Graph => base.Graph;
}
}
}