2021-02-01 18:37:19 +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.
|
|
|
|
|
2021-02-02 13:13:50 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-02-01 18:37:19 +08:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-02-02 13:13:50 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2021-02-01 18:37:19 +08:00
|
|
|
using osu.Game.Utils;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Mods
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class ModUtilsTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestModIsCompatibleByItself()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod = new Mock<CustomMod1>();
|
2021-02-01 18:37:19 +08:00
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestIncompatibleThroughTopLevel()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod1 = new Mock<CustomMod1>();
|
|
|
|
var mod2 = new Mock<CustomMod2>();
|
2021-02-01 18:37:19 +08:00
|
|
|
|
|
|
|
mod1.Setup(m => m.IncompatibleMods).Returns(new[] { mod2.Object.GetType() });
|
|
|
|
|
|
|
|
// Test both orderings.
|
2021-02-02 17:33:12 +08:00
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
|
2021-02-01 18:37:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-02-02 17:31:08 +08:00
|
|
|
public void TestMultiModIncompatibleWithTopLevel()
|
2021-02-01 18:37:19 +08:00
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod1 = new Mock<CustomMod1>();
|
2021-02-01 18:37:19 +08:00
|
|
|
|
|
|
|
// The nested mod.
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod2 = new Mock<CustomMod2>();
|
2021-02-01 18:37:19 +08:00
|
|
|
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { mod1.Object.GetType() });
|
|
|
|
|
|
|
|
var multiMod = new MultiMod(new MultiMod(mod2.Object));
|
|
|
|
|
|
|
|
// Test both orderings.
|
2021-02-02 17:33:12 +08:00
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { multiMod, mod1.Object }), Is.False);
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, multiMod }), Is.False);
|
2021-02-01 18:37:19 +08:00
|
|
|
}
|
|
|
|
|
2021-02-02 17:31:08 +08:00
|
|
|
[Test]
|
|
|
|
public void TestTopLevelIncompatibleWithMultiMod()
|
|
|
|
{
|
|
|
|
// The nested mod.
|
|
|
|
var mod1 = new Mock<CustomMod1>();
|
|
|
|
var multiMod = new MultiMod(new MultiMod(mod1.Object));
|
|
|
|
|
|
|
|
var mod2 = new Mock<CustomMod2>();
|
|
|
|
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(CustomMod1) });
|
|
|
|
|
|
|
|
// Test both orderings.
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { multiMod, mod2.Object }), Is.False);
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, multiMod }), Is.False);
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:01:33 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCompatibleMods()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod1 = new Mock<CustomMod1>();
|
|
|
|
var mod2 = new Mock<CustomMod2>();
|
2021-02-02 17:01:33 +08:00
|
|
|
|
|
|
|
// Test both orderings.
|
2021-02-02 17:33:12 +08:00
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.True);
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.True);
|
2021-02-02 17:01:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestIncompatibleThroughBaseType()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod1 = new Mock<CustomMod1>();
|
|
|
|
var mod2 = new Mock<CustomMod2>();
|
|
|
|
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(Mod) });
|
2021-02-02 17:01:33 +08:00
|
|
|
|
|
|
|
// Test both orderings.
|
2021-02-02 17:33:12 +08:00
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
|
|
|
|
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
|
2021-02-01 18:37:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAllowedThroughMostDerivedType()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod = new Mock<CustomMod1>();
|
2021-02-01 18:37:19 +08:00
|
|
|
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { mod.Object.GetType() }));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNotAllowedThroughBaseType()
|
|
|
|
{
|
2021-02-02 17:33:12 +08:00
|
|
|
var mod = new Mock<CustomMod1>();
|
2021-02-01 18:37:19 +08:00
|
|
|
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { typeof(Mod) }), Is.False);
|
|
|
|
}
|
2021-02-02 13:13:50 +08:00
|
|
|
|
|
|
|
// test incompatible pair.
|
|
|
|
[TestCase(new[] { typeof(OsuModDoubleTime), typeof(OsuModHalfTime) }, new[] { typeof(OsuModDoubleTime), typeof(OsuModHalfTime) })]
|
|
|
|
// test incompatible pair with derived class.
|
|
|
|
[TestCase(new[] { typeof(OsuModNightcore), typeof(OsuModHalfTime) }, new[] { typeof(OsuModNightcore), typeof(OsuModHalfTime) })]
|
|
|
|
// test system mod.
|
|
|
|
[TestCase(new[] { typeof(OsuModDoubleTime), typeof(OsuModTouchDevice) }, new[] { typeof(OsuModTouchDevice) })]
|
|
|
|
// test valid.
|
|
|
|
[TestCase(new[] { typeof(OsuModDoubleTime), typeof(OsuModHardRock) }, null)]
|
|
|
|
public void TestInvalidModScenarios(Type[] input, Type[] expectedInvalid)
|
|
|
|
{
|
|
|
|
List<Mod> inputMods = new List<Mod>();
|
|
|
|
foreach (var t in input)
|
|
|
|
inputMods.Add((Mod)Activator.CreateInstance(t));
|
|
|
|
|
|
|
|
bool isValid = ModUtils.CheckValidForGameplay(inputMods, out var invalid);
|
|
|
|
|
|
|
|
Assert.That(isValid, Is.EqualTo(expectedInvalid == null));
|
|
|
|
|
|
|
|
if (isValid)
|
|
|
|
Assert.IsNull(invalid);
|
|
|
|
else
|
|
|
|
Assert.That(invalid?.Select(t => t.GetType()), Is.EquivalentTo(expectedInvalid));
|
|
|
|
}
|
2021-02-02 17:41:35 +08:00
|
|
|
|
2021-02-02 17:31:08 +08:00
|
|
|
public abstract class CustomMod1 : Mod
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract class CustomMod2 : Mod
|
|
|
|
{
|
|
|
|
}
|
2021-02-01 18:37:19 +08:00
|
|
|
}
|
|
|
|
}
|