mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Add proper testing
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.EventArgs;
|
using osu.Framework.Input.EventArgs;
|
||||||
@ -30,13 +33,14 @@ namespace osu.Game.Tests.Visual
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Children = new KeyCounter[]
|
Children = new KeyCounter[]
|
||||||
{
|
{
|
||||||
rewindTestKeyCounterKeyboard = new KeyCounterKeyboard(rewind_test_key),
|
rewindTestKeyCounterKeyboard = new KeyCounterKeyboard(Key.X),
|
||||||
new KeyCounterKeyboard(Key.X),
|
new KeyCounterKeyboard(Key.X),
|
||||||
new KeyCounterMouse(MouseButton.Left),
|
new KeyCounterMouse(MouseButton.Left),
|
||||||
new KeyCounterMouse(MouseButton.Right),
|
new KeyCounterMouse(MouseButton.Right),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
AddStep("Add random", () =>
|
AddStep("Add random", () =>
|
||||||
{
|
{
|
||||||
Key key = (Key)((int)Key.A + RNG.Next(26));
|
Key key = (Key)((int)Key.A + RNG.Next(26));
|
||||||
@ -44,29 +48,57 @@ namespace osu.Game.Tests.Visual
|
|||||||
});
|
});
|
||||||
AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v);
|
AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v);
|
||||||
|
|
||||||
var expectedCountPresses = rewindTestKeyCounterKeyboard.CountPresses + 1;
|
Key testKey = ((KeyCounterKeyboard)kc.Children.First()).Key;
|
||||||
AddStep($"Press {rewind_test_key} key", () =>
|
double time1 = 0;
|
||||||
|
|
||||||
|
AddStep($"Press {testKey} key", () =>
|
||||||
{
|
{
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = rewind_test_key, Repeat = false });
|
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = testKey, Repeat = false });
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = rewind_test_key });
|
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = testKey });
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"Check {rewind_test_key} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == expectedCountPresses);
|
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
||||||
|
|
||||||
IFrameBasedClock counterClock = null;
|
AddStep($"Press {testKey} key", () =>
|
||||||
AddStep($"Rewind {rewind_test_key} counter", () =>
|
|
||||||
{
|
{
|
||||||
counterClock = rewindTestKeyCounterKeyboard.Clock;
|
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = testKey, Repeat = false });
|
||||||
rewindTestKeyCounterKeyboard.Clock = new DecoupleableInterpolatingFramedClock();
|
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = testKey });
|
||||||
|
time1 = Clock.CurrentTime;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"Check {rewind_test_key} counter after rewind", () =>
|
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 2);
|
||||||
|
|
||||||
|
IFrameBasedClock oldClock = null;
|
||||||
|
|
||||||
|
AddStep($"Rewind {testKey} counter once", () =>
|
||||||
{
|
{
|
||||||
rewindTestKeyCounterKeyboard.Clock = counterClock;
|
oldClock = rewindTestKeyCounterKeyboard.Clock;
|
||||||
return rewindTestKeyCounterKeyboard.CountPresses == 0;
|
rewindTestKeyCounterKeyboard.Clock = new FramedOffsetClock(new FixedClock(time1 - 10));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddAssert($"Check {testKey} counter after rewind", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
||||||
|
|
||||||
|
AddStep($"Rewind {testKey} counter to zero", () => rewindTestKeyCounterKeyboard.Clock = new FramedOffsetClock(new FixedClock(0)));
|
||||||
|
|
||||||
|
AddAssert($"Check {testKey} counter after rewind", () => rewindTestKeyCounterKeyboard.CountPresses == 0);
|
||||||
|
|
||||||
|
AddStep("Restore clock", () => rewindTestKeyCounterKeyboard.Clock = oldClock);
|
||||||
|
|
||||||
Add(kc);
|
Add(kc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FixedClock : IClock
|
||||||
|
{
|
||||||
|
private readonly double time;
|
||||||
|
|
||||||
|
public FixedClock(double time)
|
||||||
|
{
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double CurrentTime => time;
|
||||||
|
public double Rate => 1;
|
||||||
|
public bool IsRunning => false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user