2019-09-16 04:55:25 +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-09-16 04:55:25 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Game.Beatmaps.Legacy;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Beatmaps
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base class for tests of converting <see cref="LegacyMods"/> enumeration flags to ruleset mod instances.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class LegacyModConversionTest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates the <see cref="Ruleset"/> whose legacy mod conversion is to be tested.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract Ruleset CreateRuleset();
|
|
|
|
|
|
2020-11-15 21:17:41 +08:00
|
|
|
|
protected void TestFromLegacy(LegacyMods legacyMods, Type[] expectedMods)
|
2019-09-16 04:55:25 +08:00
|
|
|
|
{
|
|
|
|
|
var ruleset = CreateRuleset();
|
2020-03-24 11:06:24 +08:00
|
|
|
|
var mods = ruleset.ConvertFromLegacyMods(legacyMods).ToList();
|
2019-09-16 04:55:25 +08:00
|
|
|
|
Assert.AreEqual(expectedMods.Length, mods.Count);
|
|
|
|
|
|
|
|
|
|
foreach (var modType in expectedMods)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull(mods.SingleOrDefault(mod => mod.GetType() == modType));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-15 21:25:22 +08:00
|
|
|
|
|
|
|
|
|
protected void TestToLegacy(LegacyMods expectedLegacyMods, Type[] providedModTypes)
|
|
|
|
|
{
|
|
|
|
|
var ruleset = CreateRuleset();
|
2021-09-10 10:09:13 +08:00
|
|
|
|
var modInstances = ruleset.CreateAllMods()
|
2020-11-15 21:25:22 +08:00
|
|
|
|
.Where(mod => providedModTypes.Contains(mod.GetType()))
|
|
|
|
|
.ToArray();
|
|
|
|
|
var actualLegacyMods = ruleset.ConvertToLegacyMods(modInstances);
|
|
|
|
|
Assert.AreEqual(expectedLegacyMods, actualLegacyMods);
|
|
|
|
|
}
|
2019-09-16 04:55:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|