mirror of
https://github.com/osukey/osukey.git
synced 2025-05-07 22:57:31 +09:00
Rewrite tests for KPS
This commit is contained in:
parent
24c29b7e2f
commit
b4e0fa7c53
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,9 +3,15 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using AutoMapper.Internal;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
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;
|
||||||
using osu.Game.Screens.Play.HUD.KPSCounter;
|
using osu.Game.Screens.Play.HUD.KPSCounter;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -13,63 +19,75 @@ using osuTK.Input;
|
|||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Gameplay
|
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;
|
private KeysPerSecondCounter counter;
|
||||||
|
|
||||||
[SetUpSteps]
|
private void createCounter()
|
||||||
public void Setup()
|
{
|
||||||
|
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();
|
createCounter();
|
||||||
}
|
|
||||||
|
|
||||||
private void createCounter() => AddStep("Create counter", () =>
|
AddStep("press 1 key", () => InputManager.Key(Key.D));
|
||||||
{
|
AddAssert("KPS = 1", () => counter.Current.Value == 1);
|
||||||
Child = counter = new KeysPerSecondCounter
|
AddUntilStep("Wait for KPS cooldown", () => counter.Current.Value <= 0);
|
||||||
|
AddStep("press 4 keys", () =>
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
InputManager.Key(Key.D);
|
||||||
Origin = Anchor.Centre,
|
InputManager.Key(Key.F);
|
||||||
Scale = new Vector2(5)
|
InputManager.Key(Key.J);
|
||||||
};
|
InputManager.Key(Key.K);
|
||||||
});
|
});
|
||||||
|
AddAssert("KPS = 4", () => counter.Current.Value == 4);
|
||||||
[Test]
|
AddStep("Pause player", () => Player.Pause());
|
||||||
public void TestManualTrigger()
|
AddAssert("KPS = 4", () => counter.Current.Value == 4);
|
||||||
{
|
AddStep("Resume player", () => Player.Resume());
|
||||||
AddAssert("Counter = 0", () => counter.Current.Value == 0);
|
AddStep("press 4 keys", () =>
|
||||||
AddRepeatStep("manual trigger", KeysPerSecondCalculator.AddInput, 20);
|
{
|
||||||
AddAssert("Counter is not 0", () => counter.Current.Value > 0);
|
InputManager.Key(Key.D);
|
||||||
}
|
InputManager.Key(Key.F);
|
||||||
|
InputManager.Key(Key.J);
|
||||||
[Test]
|
InputManager.Key(Key.K);
|
||||||
public void TestKpsAsideKeyCounter()
|
});
|
||||||
{
|
AddAssert("KPS = 8", () => counter.Current.Value == 8);
|
||||||
AddStep("Create key counter display", () =>
|
AddUntilStep("Wait for KPS cooldown", () => counter.Current.Value <= 0);
|
||||||
Add(new KeyCounterDisplay
|
AddStep("Add DT", () =>
|
||||||
|
{
|
||||||
|
var dt = new ManiaModDoubleTime
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomCentre,
|
SpeedChange =
|
||||||
Anchor = Anchor.BottomCentre,
|
|
||||||
Y = 100,
|
|
||||||
Children = new KeyCounter[]
|
|
||||||
{
|
{
|
||||||
new KeyCounterKeyboard(Key.W),
|
Value = 2
|
||||||
new KeyCounterKeyboard(Key.X),
|
|
||||||
new KeyCounterKeyboard(Key.C),
|
|
||||||
new KeyCounterKeyboard(Key.V)
|
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
);
|
Player.Mods.Value.Concat((dt.Yield()).ToArray());
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user