mirror of
https://github.com/ppy/osu
synced 2025-01-09 15:49:32 +00:00
Add function to assert multiplier value instead of hardcoded string
This commit is contained in:
parent
af5c5a3000
commit
0e658790c1
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
@ -28,33 +29,46 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestIncrementMultiplier()
|
public void TestIncrementMultiplier()
|
||||||
{
|
{
|
||||||
AddStep(@"Add Hidden", () => changeMods(new Mod[] { new OsuModHidden() }));
|
var hiddenMod = new Mod[] { new OsuModHidden() };
|
||||||
AddAssert(@"Check Hidden multiplier", () => footerButtonMods.MultiplierText.Text == @"1.06x");
|
AddStep(@"Add Hidden", () => changeMods(hiddenMod));
|
||||||
AddStep(@"Add HardRock", () => changeMods(new Mod[] { new OsuModHidden() }));
|
AddAssert(@"Check Hidden multiplier", () => assertModsMultiplier(hiddenMod));
|
||||||
AddAssert(@"Check HardRock multiplier", () => footerButtonMods.MultiplierText.Text == @"1.06x");
|
|
||||||
AddStep(@"Add DoubleTime", () => changeMods(new Mod[] { new OsuModDoubleTime() }));
|
var hardRockMod = new Mod[] { new OsuModHardRock() };
|
||||||
AddAssert(@"Check DoubleTime multiplier", () => footerButtonMods.MultiplierText.Text == @"1.12x");
|
AddStep(@"Add HardRock", () => changeMods(hardRockMod));
|
||||||
AddStep(@"Add multiple Mods", () => changeMods(new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModHidden() }));
|
AddAssert(@"Check HardRock multiplier", () => assertModsMultiplier(hardRockMod));
|
||||||
AddAssert(@"Check multiple mod multiplier", () => footerButtonMods.MultiplierText.Text == @"1.26x");
|
|
||||||
|
var doubleTimeMod = new Mod[] { new OsuModDoubleTime() };
|
||||||
|
AddStep(@"Add DoubleTime", () => changeMods(doubleTimeMod));
|
||||||
|
AddAssert(@"Check DoubleTime multiplier", () => assertModsMultiplier(doubleTimeMod));
|
||||||
|
|
||||||
|
var mutlipleIncrementMods = new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModHardRock() };
|
||||||
|
AddStep(@"Add multiple Mods", () => changeMods(mutlipleIncrementMods));
|
||||||
|
AddAssert(@"Check multiple mod multiplier", () => assertModsMultiplier(mutlipleIncrementMods));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDecrementMultiplier()
|
public void TestDecrementMultiplier()
|
||||||
{
|
{
|
||||||
AddStep(@"Add Easy", () => changeMods(new Mod[] { new OsuModEasy() }));
|
var easyMod = new Mod[] { new OsuModEasy() };
|
||||||
AddAssert(@"Check Easy multiplier", () => footerButtonMods.MultiplierText.Text == @"0.50x");
|
AddStep(@"Add Easy", () => changeMods(easyMod));
|
||||||
AddStep(@"Add NoFail", () => changeMods(new Mod[] { new OsuModNoFail() }));
|
AddAssert(@"Check Easy multiplier", () => assertModsMultiplier(easyMod));
|
||||||
AddAssert(@"Check NoFail multiplier", () => footerButtonMods.MultiplierText.Text == @"0.50x");
|
|
||||||
AddStep(@"Add Multiple Mods", () => changeMods(new Mod[] { new OsuModEasy(), new OsuModNoFail() }));
|
var noFailMod = new Mod[] { new OsuModNoFail() };
|
||||||
AddAssert(@"Check multiple mod multiplier", () => footerButtonMods.MultiplierText.Text == @"0.25x");
|
AddStep(@"Add NoFail", () => changeMods(noFailMod));
|
||||||
|
AddAssert(@"Check NoFail multiplier", () => assertModsMultiplier(noFailMod));
|
||||||
|
|
||||||
|
var multipleDecrementMods = new Mod[] { new OsuModEasy(), new OsuModNoFail() };
|
||||||
|
AddStep(@"Add Multiple Mods", () => changeMods(multipleDecrementMods));
|
||||||
|
AddAssert(@"Check multiple mod multiplier", () => assertModsMultiplier(multipleDecrementMods));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestClearMultiplier()
|
public void TestClearMultiplier()
|
||||||
{
|
{
|
||||||
AddStep(@"Add mods", () => changeMods(new Mod[] { new OsuModDoubleTime(), new OsuModFlashlight() }));
|
var multipleMods = new Mod[] { new OsuModDoubleTime(), new OsuModFlashlight() };
|
||||||
|
AddStep(@"Add mods", () => changeMods(multipleMods));
|
||||||
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
|
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
|
||||||
AddAssert(@"Check empty multiplier", () => string.IsNullOrEmpty(footerButtonMods.MultiplierText.Text));
|
AddAssert(@"Check empty multiplier", () => assertModsMultiplier(Array.Empty<Mod>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeMods(IReadOnlyList<Mod> mods)
|
private void changeMods(IReadOnlyList<Mod> mods)
|
||||||
@ -62,6 +76,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
footerButtonMods.Current.Value = mods;
|
footerButtonMods.Current.Value = mods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool assertModsMultiplier(IEnumerable<Mod> mods)
|
||||||
|
{
|
||||||
|
var multiplier = mods.Aggregate(1.0, (current, mod) => current * mod.ScoreMultiplier);
|
||||||
|
var expectedValue = multiplier.Equals(1.0) ? string.Empty : $"{multiplier:N2}x";
|
||||||
|
|
||||||
|
return expectedValue == footerButtonMods.MultiplierText.Text;
|
||||||
|
}
|
||||||
|
|
||||||
private class TestFooterButtonMods : FooterButtonMods
|
private class TestFooterButtonMods : FooterButtonMods
|
||||||
{
|
{
|
||||||
public new OsuSpriteText MultiplierText => base.MultiplierText;
|
public new OsuSpriteText MultiplierText => base.MultiplierText;
|
||||||
|
Loading…
Reference in New Issue
Block a user