1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 06:42:56 +08:00

Fix key counter test not testing the full binding of IsCounting

This commit is contained in:
Dean Herbert 2023-04-25 21:37:17 +09:00
parent 807a139877
commit 0c3a015953

View File

@ -19,21 +19,21 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
public TestSceneKeyCounter() public TestSceneKeyCounter()
{ {
KeyCounterDisplay kc = new DefaultKeyCounterDisplay KeyCounterDisplay defaultDisplay = new DefaultKeyCounterDisplay
{ {
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Position = new Vector2(0, 72.7f) Position = new Vector2(0, 72.7f)
}; };
KeyCounterDisplay argonKc = new ArgonKeyCounterDisplay KeyCounterDisplay argonDisplay = new ArgonKeyCounterDisplay
{ {
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Position = new Vector2(0, -72.7f) Position = new Vector2(0, -72.7f)
}; };
kc.AddRange(new InputTrigger[] defaultDisplay.AddRange(new InputTrigger[]
{ {
new KeyCounterKeyboardTrigger(Key.X), new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterKeyboardTrigger(Key.X), new KeyCounterKeyboardTrigger(Key.X),
@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.Gameplay
new KeyCounterMouseTrigger(MouseButton.Right), new KeyCounterMouseTrigger(MouseButton.Right),
}); });
argonKc.AddRange(new InputTrigger[] argonDisplay.AddRange(new InputTrigger[]
{ {
new KeyCounterKeyboardTrigger(Key.X), new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterKeyboardTrigger(Key.X), new KeyCounterKeyboardTrigger(Key.X),
@ -49,32 +49,29 @@ namespace osu.Game.Tests.Visual.Gameplay
new KeyCounterMouseTrigger(MouseButton.Right), new KeyCounterMouseTrigger(MouseButton.Right),
}); });
var testCounter = (DefaultKeyCounter)kc.Counters.First(); var testCounter = (DefaultKeyCounter)defaultDisplay.Counters.First();
AddStep("Add random", () => AddStep("Add random", () =>
{ {
Key key = (Key)((int)Key.A + RNG.Next(26)); Key key = (Key)((int)Key.A + RNG.Next(26));
kc.Add(new KeyCounterKeyboardTrigger(key)); defaultDisplay.Add(new KeyCounterKeyboardTrigger(key));
argonKc.Add(new KeyCounterKeyboardTrigger(key)); argonDisplay.Add(new KeyCounterKeyboardTrigger(key));
}); });
Key testKey = ((KeyCounterKeyboardTrigger)kc.Counters.First().Trigger).Key; Key testKey = ((KeyCounterKeyboardTrigger)defaultDisplay.Counters.First().Trigger).Key;
void addPressKeyStep()
{
AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
}
addPressKeyStep(); addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 1); AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 1);
addPressKeyStep(); addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 2); AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 2);
AddStep("Disable counting", () => testCounter.IsCounting.Value = false); AddStep("Disable counting", () => defaultDisplay.IsCounting.Value = false);
addPressKeyStep(); addPressKeyStep();
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses.Value == 2); AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses.Value == 2);
Add(kc); Add(defaultDisplay);
Add(argonKc); Add(argonDisplay);
void addPressKeyStep() => AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
} }
} }
} }