1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 12:43:16 +08:00

Rewrite rank graph test to use more modern style

This commit is contained in:
Bartłomiej Dach 2022-11-21 20:56:38 +01:00
parent 4490504104
commit 735cac3104
No known key found for this signature in database

View File

@ -1,13 +1,12 @@
// 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.
#nullable disable
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
@ -23,33 +22,14 @@ namespace osu.Game.Tests.Visual.Online
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
public TestSceneRankGraph()
private RankGraph graph = null!;
private const int history_length = 89;
[SetUpSteps]
public void SetUpSteps()
{
RankGraph graph;
int[] data = new int[89];
int[] dataWithZeros = new int[89];
int[] smallData = new int[89];
int[] edgyData = new int[89];
for (int i = 0; i < 89; i++)
data[i] = dataWithZeros[i] = (i + 1) * 1000;
for (int i = 20; i < 60; i++)
dataWithZeros[i] = 0;
for (int i = 79; i < 89; i++)
smallData[i] = 100000 - i * 1000;
bool edge = true;
for (int i = 0; i < 20; i++)
{
edgyData[i] = 100000 + (edge ? 1000 : -1000) * (i + 1);
edge = !edge;
}
Add(new Container
AddStep("create graph", () => Child = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -67,8 +47,14 @@ namespace osu.Game.Tests.Visual.Online
}
}
});
}
[Test]
public void TestNullUser() =>
AddStep("null user", () => graph.Statistics.Value = null);
[Test]
public void TestRankOnly() =>
AddStep("rank only", () =>
{
graph.Statistics.Value = new UserStatistics
@ -78,6 +64,14 @@ namespace osu.Game.Tests.Visual.Online
};
});
[Test]
public void TestWithRankHistory()
{
int[] data = new int[history_length];
for (int i = 0; i < history_length; i++)
data[i] = (i + 1) * 1000;
AddStep("with rank history", () =>
{
graph.Statistics.Value = new UserStatistics
@ -86,10 +80,22 @@ namespace osu.Game.Tests.Visual.Online
PP = 12345,
RankHistory = new APIRankHistory
{
Data = data,
Data = data
}
};
});
}
[Test]
public void TestRanksWithZeroValues()
{
int[] dataWithZeros = new int[history_length];
for (int i = 0; i < history_length; i++)
{
if (i < 20 || i >= 60)
dataWithZeros[i] = (i + 1) * 1000;
}
AddStep("with zero values", () =>
{
@ -103,6 +109,15 @@ namespace osu.Game.Tests.Visual.Online
}
};
});
}
[Test]
public void TestSmallAmountOfData()
{
int[] smallData = new int[history_length];
for (int i = history_length - 10; i < history_length; i++)
smallData[i] = 100000 - i * 1000;
AddStep("small amount of data", () =>
{
@ -116,6 +131,20 @@ namespace osu.Game.Tests.Visual.Online
}
};
});
}
[Test]
public void TestHistoryWithEdges()
{
int[] edgyData = new int[89];
bool edge = true;
for (int i = 0; i < 20; i++)
{
edgyData[i] = 100000 + (edge ? 1000 : -1000) * (i + 1);
edge = !edge;
}
AddStep("graph with edges", () =>
{