1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

Add function to assert multiplier value instead of hardcoded string

This commit is contained in:
Ganendra Afrasya 2019-12-15 22:42:44 +07:00
parent af5c5a3000
commit 0e658790c1

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Mods;
@ -28,33 +29,46 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test]
public void TestIncrementMultiplier()
{
AddStep(@"Add Hidden", () => changeMods(new Mod[] { new OsuModHidden() }));
AddAssert(@"Check Hidden multiplier", () => footerButtonMods.MultiplierText.Text == @"1.06x");
AddStep(@"Add HardRock", () => changeMods(new Mod[] { new OsuModHidden() }));
AddAssert(@"Check HardRock multiplier", () => footerButtonMods.MultiplierText.Text == @"1.06x");
AddStep(@"Add DoubleTime", () => changeMods(new Mod[] { new OsuModDoubleTime() }));
AddAssert(@"Check DoubleTime multiplier", () => footerButtonMods.MultiplierText.Text == @"1.12x");
AddStep(@"Add multiple Mods", () => changeMods(new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModHidden() }));
AddAssert(@"Check multiple mod multiplier", () => footerButtonMods.MultiplierText.Text == @"1.26x");
var hiddenMod = new Mod[] { new OsuModHidden() };
AddStep(@"Add Hidden", () => changeMods(hiddenMod));
AddAssert(@"Check Hidden multiplier", () => assertModsMultiplier(hiddenMod));
var hardRockMod = new Mod[] { new OsuModHardRock() };
AddStep(@"Add HardRock", () => changeMods(hardRockMod));
AddAssert(@"Check HardRock multiplier", () => assertModsMultiplier(hardRockMod));
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]
public void TestDecrementMultiplier()
{
AddStep(@"Add Easy", () => changeMods(new Mod[] { new OsuModEasy() }));
AddAssert(@"Check Easy multiplier", () => footerButtonMods.MultiplierText.Text == @"0.50x");
AddStep(@"Add NoFail", () => changeMods(new Mod[] { new OsuModNoFail() }));
AddAssert(@"Check NoFail multiplier", () => footerButtonMods.MultiplierText.Text == @"0.50x");
AddStep(@"Add Multiple Mods", () => changeMods(new Mod[] { new OsuModEasy(), new OsuModNoFail() }));
AddAssert(@"Check multiple mod multiplier", () => footerButtonMods.MultiplierText.Text == @"0.25x");
var easyMod = new Mod[] { new OsuModEasy() };
AddStep(@"Add Easy", () => changeMods(easyMod));
AddAssert(@"Check Easy multiplier", () => assertModsMultiplier(easyMod));
var noFailMod = new Mod[] { new OsuModNoFail() };
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]
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>()));
AddAssert(@"Check empty multiplier", () => string.IsNullOrEmpty(footerButtonMods.MultiplierText.Text));
AddAssert(@"Check empty multiplier", () => assertModsMultiplier(Array.Empty<Mod>()));
}
private void changeMods(IReadOnlyList<Mod> mods)
@ -62,6 +76,14 @@ namespace osu.Game.Tests.Visual.UserInterface
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
{
public new OsuSpriteText MultiplierText => base.MultiplierText;