1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 16:27:43 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneFooterButtonMods.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
4.1 KiB
C#
Raw Normal View History

2019-11-28 13:03:11 +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.
using System;
using System.Collections.Generic;
using System.Linq;
2019-11-28 13:03:11 +08:00
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
2019-11-28 13:03:11 +08:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Select;
2023-12-31 21:47:10 +08:00
using osu.Game.Utils;
2019-11-28 13:03:11 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneFooterButtonMods : OsuTestScene
2019-11-28 13:03:11 +08:00
{
private readonly TestFooterButtonMods footerButtonMods;
2019-11-28 13:03:11 +08:00
public TestSceneFooterButtonMods()
2019-11-28 13:03:11 +08:00
{
Add(footerButtonMods = new TestFooterButtonMods());
2019-11-28 13:03:11 +08:00
}
[Test]
public void TestIncrementMultiplier()
{
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 multipleIncrementMods = new Mod[] { new OsuModDoubleTime(), new OsuModHidden(), new OsuModHardRock() };
AddStep(@"Add multiple Mods", () => changeMods(multipleIncrementMods));
AddAssert(@"Check multiple mod multiplier", () => assertModsMultiplier(multipleIncrementMods));
2019-11-28 13:03:11 +08:00
}
[Test]
public void TestDecrementMultiplier()
{
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));
2019-11-28 13:03:11 +08:00
}
[Test]
public void TestClearMultiplier()
{
var multipleMods = new Mod[] { new OsuModDoubleTime(), new OsuModFlashlight() };
AddStep(@"Add mods", () => changeMods(multipleMods));
2019-11-28 13:03:11 +08:00
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
AddAssert(@"Check empty multiplier", () => assertModsMultiplier(Array.Empty<Mod>()));
2019-11-28 13:03:11 +08:00
}
[Test]
public void TestUnrankedBadge()
{
AddStep(@"Add unranked mod", () => changeMods(new[] { new OsuModDeflate() }));
AddAssert("Unranked badge shown", () => footerButtonMods.UnrankedBadge.Alpha == 1);
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
AddAssert("Unranked badge not shown", () => footerButtonMods.UnrankedBadge.Alpha == 0);
}
2019-11-28 13:03:11 +08:00
private void changeMods(IReadOnlyList<Mod> mods)
{
footerButtonMods.Current.Value = mods;
}
private bool assertModsMultiplier(IEnumerable<Mod> mods)
{
double multiplier = mods.Aggregate(1.0, (current, mod) => current * mod.ScoreMultiplier);
2023-12-31 21:47:10 +08:00
string expectedValue = multiplier == 1 ? string.Empty : ModUtils.FormatScoreMultiplier(multiplier).ToString();
return expectedValue == footerButtonMods.MultiplierText.Current.Value;
}
private partial class TestFooterButtonMods : FooterButtonMods
{
public new OsuSpriteText MultiplierText => base.MultiplierText;
public new Drawable UnrankedBadge => base.UnrankedBadge;
}
2019-11-28 13:03:11 +08:00
}
}