Addressed changes

This commit is contained in:
Terochi
2023-03-09 20:14:58 +01:00
parent 8bf84869a5
commit b51c41a804
2 changed files with 109 additions and 52 deletions

View File

@ -14,7 +14,7 @@ namespace osu.Game.Tests.Mods
public class ModSettingsTest
{
[Test]
public void TestModSettingsUnboundWhenCopied()
public void TestModSettingsUnboundWhenCloned()
{
var original = new OsuModDoubleTime();
var copy = (OsuModDoubleTime)original.DeepClone();
@ -26,7 +26,7 @@ namespace osu.Game.Tests.Mods
}
[Test]
public void TestMultiModSettingsUnboundWhenCopied()
public void TestMultiModSettingsUnboundWhenCloned()
{
var original = new MultiMod(new OsuModDoubleTime());
var copy = (MultiMod)original.DeepClone();
@ -54,6 +54,42 @@ namespace osu.Game.Tests.Mods
Assert.That(modBool.TestSetting.Value, Is.EqualTo(!modBool.TestSetting.Default));
}
[Test]
public void TestDefaultValueKeptWhenCopied()
{
var modBoolTrue = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = true, Value = false } };
var modBoolFalse = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = false, Value = true } };
modBoolFalse.CopySharedSettings(modBoolTrue);
Assert.That(modBoolFalse.TestSetting.Default, Is.EqualTo(false));
Assert.That(modBoolFalse.TestSetting.Value, Is.EqualTo(modBoolTrue.TestSetting.Value));
}
[Test]
public void TestValueResetsToDefaultWhenCopied()
{
var modDouble = new TestNonMatchingSettingTypeModDouble();
var modInt = new TestNonMatchingSettingTypeModInt { TestSetting = { Value = 1 } };
modInt.CopySharedSettings(modDouble);
Assert.That(modInt.TestSetting.Value, Is.EqualTo(modInt.TestSetting.Default));
}
[Test]
public void TestRelativelyScaleWithClampedRangeWhenCopied()
{
const double setting_change = 50.4;
var modDouble100 = new TestNonMatchingSettingTypeModDouble { TestSetting = { MaxValue = 100, MinValue = 0, Value = setting_change } };
var modDouble200 = new TestNonMatchingSettingTypeModDouble { TestSetting = { MaxValue = 200, MinValue = 0 } };
modDouble200.CopySharedSettings(modDouble100);
Assert.That(modDouble200.TestSetting.Value, Is.EqualTo(setting_change * 2));
}
[Test]
public void TestCopyDoubleToIntWithDefaultRange()
{
@ -64,7 +100,32 @@ namespace osu.Game.Tests.Mods
modInt.CopySharedSettings(modDouble);
Assert.That(modInt.TestSetting.Value, Is.EqualTo((int)setting_change));
Assert.That(modInt.TestSetting.Value, Is.EqualTo(Convert.ToInt32(setting_change)));
}
[Test]
public void TestCopyDoubleToIntWithOutOfBoundsRange()
{
const double setting_change = 50.4;
var modDouble = new TestNonMatchingSettingTypeModDouble { TestSetting = { MinValue = int.MinValue - 1d, Value = setting_change } };
// make RangeConstrainedBindable.HasDefinedRange return true
var modInt = new TestNonMatchingSettingTypeModInt { TestSetting = { MinValue = int.MinValue + 1 } };
modInt.CopySharedSettings(modDouble);
Assert.That(modInt.TestSetting.Value, Is.EqualTo(Convert.ToInt32(setting_change)));
}
[Test]
public void TestCopyDoubleToIntWithOutOfBoundsValue()
{
var modDouble = new TestNonMatchingSettingTypeModDouble { TestSetting = { MinValue = int.MinValue + 1, Value = int.MaxValue + 1d } };
var modInt = new TestNonMatchingSettingTypeModInt { TestSetting = { MinValue = int.MinValue + 1 } };
modInt.CopySharedSettings(modDouble);
Assert.That(modInt.TestSetting.Value, Is.EqualTo(int.MaxValue));
}
[Test]
@ -80,31 +141,6 @@ namespace osu.Game.Tests.Mods
Assert.That(modDouble.TestSetting.Value, Is.EqualTo(setting_change));
}
[Test]
public void TestCopyDoubleToIntWithClampedRange()
{
const double setting_change = 50.4;
var modDouble = new TestNonMatchingSettingTypeModDouble { TestSetting = { MaxValue = 100, MinValue = 0, Value = setting_change } };
var modInt = new TestNonMatchingSettingTypeModInt { TestSetting = { MaxValue = 200, MinValue = 0 } };
modInt.CopySharedSettings(modDouble);
Assert.That(modInt.TestSetting.Value, Is.EqualTo(Convert.ToInt32(setting_change * 2)));
}
[Test]
public void TestDefaultValueKeptWhenCopied()
{
var modBoolTrue = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = true, Value = false } };
var modBoolFalse = new TestNonMatchingSettingTypeModBool { TestSetting = { Default = false, Value = true } };
modBoolFalse.CopySharedSettings(modBoolTrue);
Assert.That(modBoolFalse.TestSetting.Default, Is.EqualTo(false));
Assert.That(modBoolFalse.TestSetting.Value, Is.EqualTo(modBoolTrue.TestSetting.Value));
}
private class TestNonMatchingSettingTypeModDouble : TestNonMatchingSettingTypeMod
{
public override string Acronym => "NMD";