1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:52:54 +08:00

Rewrite tests for KPS

This commit is contained in:
Ryuki 2022-08-05 15:53:06 +02:00
parent 24c29b7e2f
commit b4e0fa7c53
No known key found for this signature in database
GPG Key ID: A353889EAEACBF49
2 changed files with 66 additions and 139 deletions

View File

@ -1,91 +0,0 @@
// 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.
#nullable disable
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD.KPSCounter;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneKeyPerSecondCounter : PlayerTestScene
{
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
protected override bool HasCustomSteps => false;
protected override bool Autoplay => true;
private GameplayClock gameplayClock;
private DrawableRuleset drawableRuleset;
// private DependencyProvidingContainer dependencyContainer;
private KeysPerSecondCounter counter;
[SetUpSteps]
public new void SetUpSteps()
{
/*
CreateTest(() => AddStep("Create components", () =>
{
Logger.Log($"{(Player != null ? Player.ToString() : "null")}", level: LogLevel.Debug);
dependencyContainer = new DependencyProvidingContainer
{
RelativePositionAxes = Axes.Both,
};
}));
*/
}
private void createCounter()
{
AddStep("Create counter", () =>
{
/*
if (!Contains(dependencyContainer))
{
Add(dependencyContainer);
}
if (dependencyContainer.CachedDependencies.Length == 0)
{
dependencyContainer.CachedDependencies = new (Type, object)[]
{
(typeof(GameplayClock), ,
(typeof(DrawableRuleset),)
};
}
Dependencies.Cache(gameplayClock = Player.GameplayClockContainer.GameplayClock));
*/
Dependencies.Cache(gameplayClock = Player.GameplayClockContainer.GameplayClock);
Dependencies.Cache(drawableRuleset = Player.DrawableRuleset);
Add(counter = new KeysPerSecondCounter
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Scale = new Vector2(5),
Position = new Vector2(10, 100)
}
);
});
AddAssert("ensure counter added", () => Contains(counter));
}
[Test]
public void TestInGameTimeConsistency()
{
createCounter();
AddUntilStep("Wait until first note", () => counter.Current.Value != 0);
AddStep("Pause gameplay", () => gameplayClock.IsPaused.Value = true);
AddAssert("KPS = 1", () => counter.Current.Value == 1);
}
}
}

View File

@ -3,9 +3,15 @@
#nullable disable
using System.Linq;
using AutoMapper.Internal;
using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD.KPSCounter;
using osuTK;
@ -13,63 +19,75 @@ using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneKeysPerSecondCounter : OsuManualInputManagerTestScene
public class TestSceneKeysPerSecondCounter : PlayerTestScene
{
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
protected override bool HasCustomSteps => false;
protected override bool Autoplay => false;
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, false);
private GameplayClock gameplayClock;
private DrawableRuleset drawableRuleset;
private KeysPerSecondCounter counter;
[SetUpSteps]
public void Setup()
private void createCounter()
{
AddStep("Create counter", () =>
{
gameplayClock = Player.GameplayClockContainer.GameplayClock;
drawableRuleset = Player.DrawableRuleset;
Player.HUDOverlay.Add(counter = new KeysPerSecondCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
});
counter.SmoothingTime.Value = 0;
});
AddUntilStep("Counter created", () => Player.HUDOverlay.Contains(counter));
}
[Test]
public void TestBasic()
{
createCounter();
}
private void createCounter() => AddStep("Create counter", () =>
{
Child = counter = new KeysPerSecondCounter
AddStep("press 1 key", () => InputManager.Key(Key.D));
AddAssert("KPS = 1", () => counter.Current.Value == 1);
AddUntilStep("Wait for KPS cooldown", () => counter.Current.Value <= 0);
AddStep("press 4 keys", () =>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5)
};
});
[Test]
public void TestManualTrigger()
{
AddAssert("Counter = 0", () => counter.Current.Value == 0);
AddRepeatStep("manual trigger", KeysPerSecondCalculator.AddInput, 20);
AddAssert("Counter is not 0", () => counter.Current.Value > 0);
}
[Test]
public void TestKpsAsideKeyCounter()
{
AddStep("Create key counter display", () =>
Add(new KeyCounterDisplay
InputManager.Key(Key.D);
InputManager.Key(Key.F);
InputManager.Key(Key.J);
InputManager.Key(Key.K);
});
AddAssert("KPS = 4", () => counter.Current.Value == 4);
AddStep("Pause player", () => Player.Pause());
AddAssert("KPS = 4", () => counter.Current.Value == 4);
AddStep("Resume player", () => Player.Resume());
AddStep("press 4 keys", () =>
{
InputManager.Key(Key.D);
InputManager.Key(Key.F);
InputManager.Key(Key.J);
InputManager.Key(Key.K);
});
AddAssert("KPS = 8", () => counter.Current.Value == 8);
AddUntilStep("Wait for KPS cooldown", () => counter.Current.Value <= 0);
AddStep("Add DT", () =>
{
var dt = new ManiaModDoubleTime
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Y = 100,
Children = new KeyCounter[]
SpeedChange =
{
new KeyCounterKeyboard(Key.W),
new KeyCounterKeyboard(Key.X),
new KeyCounterKeyboard(Key.C),
new KeyCounterKeyboard(Key.V)
Value = 2
}
})
);
AddAssert("Counter = 0", () => counter.Current.Value == 0);
addPressKeyStep(Key.W);
addPressKeyStep(Key.X);
addPressKeyStep(Key.C);
addPressKeyStep(Key.V);
AddAssert("Counter = 4", () => counter.Current.Value == 4);
}
private void addPressKeyStep(Key key)
{
AddStep($"Press {key} key", () => InputManager.Key(key));
};
Player.Mods.Value.Concat((dt.Yield()).ToArray());
});
}
}
}