2022-04-07 20:38:00 +00: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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
|
|
|
using osu.Game.Utils;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Mods
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class MultiModIncompatibilityTest
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Ensures that all mods grouped into <see cref="MultiMod"/>s, as declared by the default rulesets, are pairwise incompatible with each other.
|
|
|
|
/// </summary>
|
|
|
|
[TestCase(typeof(OsuRuleset))]
|
|
|
|
[TestCase(typeof(TaikoRuleset))]
|
|
|
|
[TestCase(typeof(CatchRuleset))]
|
|
|
|
[TestCase(typeof(ManiaRuleset))]
|
|
|
|
public void TestAllMultiModsFromRulesetAreIncompatible(Type rulesetType)
|
|
|
|
{
|
2022-07-10 16:07:17 +00:00
|
|
|
var ruleset = Activator.CreateInstance(rulesetType) as Ruleset;
|
2022-04-07 20:38:00 +00:00
|
|
|
Assert.That(ruleset, Is.Not.Null);
|
|
|
|
|
2022-07-10 16:07:17 +00:00
|
|
|
var allMultiMods = getMultiMods(ruleset!);
|
2022-04-07 20:38:00 +00:00
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
foreach (var multiMod in allMultiMods)
|
|
|
|
{
|
|
|
|
int modCount = multiMod.Mods.Length;
|
|
|
|
|
|
|
|
for (int i = 0; i < modCount; ++i)
|
|
|
|
{
|
|
|
|
// indexing from i + 1 ensures that only pairs of different mods are checked, and are checked only once
|
|
|
|
// (indexing from 0 would check each pair twice, and also check each mod against itself).
|
|
|
|
for (int j = i + 1; j < modCount; ++j)
|
|
|
|
{
|
|
|
|
var firstMod = multiMod.Mods[i];
|
|
|
|
var secondMod = multiMod.Mods[j];
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
ModUtils.CheckCompatibleSet(new[] { firstMod, secondMod }), Is.False,
|
|
|
|
$"{firstMod.Name} ({firstMod.Acronym}) and {secondMod.Name} ({secondMod.Acronym}) should be incompatible.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
/// This local helper is used rather than <see cref="Ruleset.CreateAllMods"/>, because the aforementioned method flattens multi mods.
|
|
|
|
/// </remarks>>
|
|
|
|
private static IEnumerable<MultiMod> getMultiMods(Ruleset ruleset)
|
2022-12-26 19:36:39 +00:00
|
|
|
=> Enum.GetValues<ModType>().SelectMany(ruleset.GetModsFor).OfType<MultiMod>();
|
2022-04-07 20:38:00 +00:00
|
|
|
}
|
|
|
|
}
|