mirror of
https://github.com/ppy/osu.git
synced 2025-02-12 20:23:06 +08:00
Move metadata randomisation local to usage
This commit is contained in:
parent
11de429621
commit
0257b8c2ff
@ -85,8 +85,7 @@ namespace osu.Game.Tests.Resources
|
||||
/// </summary>
|
||||
/// <param name="difficultyCount">Number of difficulties. If null, a random number between 1 and 20 will be used.</param>
|
||||
/// <param name="rulesets">Rulesets to cycle through when creating difficulties. If <c>null</c>, osu! ruleset will be used.</param>
|
||||
/// <param name="randomiseMetadata">Whether to randomise metadata to create a better distribution.</param>
|
||||
public static BeatmapSetInfo CreateTestBeatmapSetInfo(int? difficultyCount = null, RulesetInfo[] rulesets = null, bool randomiseMetadata = false)
|
||||
public static BeatmapSetInfo CreateTestBeatmapSetInfo(int? difficultyCount = null, RulesetInfo[] rulesets = null)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
@ -96,21 +95,7 @@ namespace osu.Game.Tests.Resources
|
||||
|
||||
int setId = GetNextTestID();
|
||||
|
||||
char getRandomCharacter()
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz*";
|
||||
return chars[RNG.Next(chars.Length)];
|
||||
}
|
||||
|
||||
var metadata = randomiseMetadata
|
||||
? new BeatmapMetadata
|
||||
{
|
||||
// Create random metadata, then we can check if sorting works based on these
|
||||
Artist = $"{getRandomCharacter()}ome Artist " + RNG.Next(0, 9),
|
||||
Title = $"{getRandomCharacter()}ome Song (set id {setId:000}) {Guid.NewGuid()}",
|
||||
Author = { Username = $"{getRandomCharacter()}ome Guy " + RNG.Next(0, 9) },
|
||||
}
|
||||
: new BeatmapMetadata
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
// Create random metadata, then we can check if sorting works based on these
|
||||
Artist = "Some Artist " + RNG.Next(0, 9),
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -190,12 +191,37 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
/// </summary>
|
||||
/// <param name="count">The count of beatmap sets to add.</param>
|
||||
/// <param name="fixedDifficultiesPerSet">If not null, the number of difficulties per set. If null, randomised difficulty count will be used.</param>
|
||||
protected void AddBeatmaps(int count, int? fixedDifficultiesPerSet = null) => AddStep($"add {count} beatmaps", () =>
|
||||
/// <param name="randomMetadata">Whether to randomise the metadata to make groupings more uniform.</param>
|
||||
protected void AddBeatmaps(int count, int? fixedDifficultiesPerSet = null, bool randomMetadata = false) => AddStep($"add {count} beatmaps{(randomMetadata ? " with random data" : "")}", () =>
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
BeatmapSets.Add(TestResources.CreateTestBeatmapSetInfo(fixedDifficultiesPerSet ?? RNG.Next(1, 4), randomiseMetadata: true));
|
||||
{
|
||||
var beatmapSetInfo = TestResources.CreateTestBeatmapSetInfo(fixedDifficultiesPerSet ?? RNG.Next(1, 4));
|
||||
|
||||
if (randomMetadata)
|
||||
{
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
// Create random metadata, then we can check if sorting works based on these
|
||||
Artist = $"{getRandomCharacter()}ome Artist " + RNG.Next(0, 9),
|
||||
Title = $"{getRandomCharacter()}ome Song (set id {beatmapSetInfo.OnlineID:000}) {Guid.NewGuid()}",
|
||||
Author = { Username = $"{getRandomCharacter()}ome Guy " + RNG.Next(0, 9) },
|
||||
};
|
||||
|
||||
foreach (var beatmap in beatmapSetInfo.Beatmaps)
|
||||
beatmap.Metadata = metadata.DeepClone();
|
||||
}
|
||||
|
||||
BeatmapSets.Add(beatmapSetInfo);
|
||||
}
|
||||
});
|
||||
|
||||
private static char getRandomCharacter()
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz*";
|
||||
return chars[RNG.Next(chars.Length)];
|
||||
}
|
||||
|
||||
protected void RemoveAllBeatmaps() => AddStep("clear all beatmaps", () => BeatmapSets.Clear());
|
||||
|
||||
protected void RemoveFirstBeatmap() =>
|
||||
|
@ -26,8 +26,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
[Test]
|
||||
public void TestBasics()
|
||||
{
|
||||
AddBeatmaps(1);
|
||||
AddBeatmaps(10);
|
||||
AddBeatmaps(10, randomMetadata: true);
|
||||
AddBeatmaps(1);
|
||||
RemoveFirstBeatmap();
|
||||
RemoveAllBeatmaps();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user