mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Merge pull request #19817 from peppy/various-test-fixes
Refactor some tests
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
@ -36,7 +34,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
TimeRange = { Value = 5000 },
|
TimeRange = { Value = 5000 },
|
||||||
};
|
};
|
||||||
|
|
||||||
private TaikoScoreProcessor scoreProcessor;
|
private TaikoScoreProcessor scoreProcessor = null!;
|
||||||
|
|
||||||
private IEnumerable<DrawableTaikoMascot> mascots => this.ChildrenOfType<DrawableTaikoMascot>();
|
private IEnumerable<DrawableTaikoMascot> mascots => this.ChildrenOfType<DrawableTaikoMascot>();
|
||||||
|
|
||||||
@ -65,6 +63,8 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestInitialState()
|
public void TestInitialState()
|
||||||
{
|
{
|
||||||
|
AddStep("set beatmap", () => setBeatmap());
|
||||||
|
|
||||||
AddStep("create mascot", () => SetContents(_ => new DrawableTaikoMascot { RelativeSizeAxes = Axes.Both }));
|
AddStep("create mascot", () => SetContents(_ => new DrawableTaikoMascot { RelativeSizeAxes = Axes.Both }));
|
||||||
|
|
||||||
AddAssert("mascot initially idle", () => allMascotsIn(TaikoMascotAnimationState.Idle));
|
AddAssert("mascot initially idle", () => allMascotsIn(TaikoMascotAnimationState.Idle));
|
||||||
@ -89,9 +89,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestIdleState()
|
public void TestIdleState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap());
|
prepareDrawableRulesetAndBeatmap(false);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle);
|
||||||
@ -100,9 +98,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestKiaiState()
|
public void TestKiaiState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(true));
|
prepareDrawableRulesetAndBeatmap(true);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Ok }, TaikoMascotAnimationState.Kiai);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Ok }, TaikoMascotAnimationState.Kiai);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Kiai);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Kiai);
|
||||||
@ -112,9 +108,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMissState()
|
public void TestMissState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap());
|
prepareDrawableRulesetAndBeatmap(false);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Miss }, TaikoMascotAnimationState.Fail);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Miss }, TaikoMascotAnimationState.Fail);
|
||||||
@ -126,9 +120,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[TestCase(false)]
|
[TestCase(false)]
|
||||||
public void TestClearStateOnComboMilestone(bool kiai)
|
public void TestClearStateOnComboMilestone(bool kiai)
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(kiai));
|
prepareDrawableRulesetAndBeatmap(kiai);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
AddRepeatStep("reach 49 combo", () => applyNewResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }), 49);
|
AddRepeatStep("reach 49 combo", () => applyNewResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }), 49);
|
||||||
|
|
||||||
@ -139,9 +131,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[TestCase(false, TaikoMascotAnimationState.Idle)]
|
[TestCase(false, TaikoMascotAnimationState.Idle)]
|
||||||
public void TestClearStateOnClearedSwell(bool kiai, TaikoMascotAnimationState expectedStateAfterClear)
|
public void TestClearStateOnClearedSwell(bool kiai, TaikoMascotAnimationState expectedStateAfterClear)
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(kiai));
|
prepareDrawableRulesetAndBeatmap(kiai);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Swell(), new TaikoSwellJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Clear);
|
assertStateAfterResult(new JudgementResult(new Swell(), new TaikoSwellJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Clear);
|
||||||
AddUntilStep($"state reverts to {expectedStateAfterClear.ToString().ToLowerInvariant()}", () => allMascotsIn(expectedStateAfterClear));
|
AddUntilStep($"state reverts to {expectedStateAfterClear.ToString().ToLowerInvariant()}", () => allMascotsIn(expectedStateAfterClear));
|
||||||
@ -175,25 +165,27 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
scoreProcessor.ApplyBeatmap(Beatmap.Value.Beatmap);
|
scoreProcessor.ApplyBeatmap(Beatmap.Value.Beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDrawableRuleset()
|
private void prepareDrawableRulesetAndBeatmap(bool kiai)
|
||||||
{
|
{
|
||||||
AddUntilStep("wait for beatmap to be loaded", () => Beatmap.Value.Track.IsLoaded);
|
AddStep("set beatmap", () => setBeatmap(kiai));
|
||||||
|
|
||||||
AddStep("create drawable ruleset", () =>
|
AddStep("create drawable ruleset", () =>
|
||||||
{
|
{
|
||||||
Beatmap.Value.Track.Start();
|
|
||||||
|
|
||||||
SetContents(_ =>
|
SetContents(_ =>
|
||||||
{
|
{
|
||||||
var ruleset = new TaikoRuleset();
|
var ruleset = new TaikoRuleset();
|
||||||
return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo));
|
return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for track to be loaded", () => MusicController.TrackLoaded);
|
||||||
|
AddStep("start track", () => MusicController.CurrentTrack.Restart());
|
||||||
|
AddUntilStep("wait for track started", () => MusicController.IsPlaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStateAfterResult(JudgementResult judgementResult, TaikoMascotAnimationState expectedState)
|
private void assertStateAfterResult(JudgementResult judgementResult, TaikoMascotAnimationState expectedState)
|
||||||
{
|
{
|
||||||
TaikoMascotAnimationState[] mascotStates = null;
|
TaikoMascotAnimationState[] mascotStates = null!;
|
||||||
|
|
||||||
AddStep($"{judgementResult.Type.ToString().ToLowerInvariant()} result for {judgementResult.Judgement.GetType().Name.Humanize(LetterCasing.LowerCase)}",
|
AddStep($"{judgementResult.Type.ToString().ToLowerInvariant()} result for {judgementResult.Judgement.GetType().Name.Humanize(LetterCasing.LowerCase)}",
|
||||||
() =>
|
() =>
|
||||||
@ -204,7 +196,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
Schedule(() => mascotStates = animatedMascots.Select(mascot => mascot.State.Value).ToArray());
|
Schedule(() => mascotStates = animatedMascots.Select(mascot => mascot.State.Value).ToArray());
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"state is {expectedState.ToString().ToLowerInvariant()}", () => mascotStates.All(state => state == expectedState));
|
AddAssert($"state is {expectedState.ToString().ToLowerInvariant()}", () => mascotStates.Distinct(), () => Is.EquivalentTo(new[] { expectedState }));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyNewResult(JudgementResult judgementResult)
|
private void applyNewResult(JudgementResult judgementResult)
|
||||||
|
@ -173,6 +173,7 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
AddStep("Seek(49)", () => Clock.Seek(49));
|
AddStep("Seek(49)", () => Clock.Seek(49));
|
||||||
|
checkTime(49);
|
||||||
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
AddStep("SeekForward, Snap", () => Clock.SeekForward(true));
|
||||||
checkTime(50);
|
checkTime(50);
|
||||||
AddStep("Seek(49.999)", () => Clock.Seek(49.999));
|
AddStep("Seek(49.999)", () => Clock.Seek(49.999));
|
||||||
@ -207,6 +208,7 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
AddStep("Seek(450)", () => Clock.Seek(450));
|
AddStep("Seek(450)", () => Clock.Seek(450));
|
||||||
|
checkTime(450);
|
||||||
AddStep("SeekBackward", () => Clock.SeekBackward());
|
AddStep("SeekBackward", () => Clock.SeekBackward());
|
||||||
checkTime(400);
|
checkTime(400);
|
||||||
AddStep("SeekBackward", () => Clock.SeekBackward());
|
AddStep("SeekBackward", () => Clock.SeekBackward());
|
||||||
@ -228,6 +230,7 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
AddStep("Seek(450)", () => Clock.Seek(450));
|
AddStep("Seek(450)", () => Clock.Seek(450));
|
||||||
|
checkTime(450);
|
||||||
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
||||||
checkTime(400);
|
checkTime(400);
|
||||||
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
||||||
@ -252,6 +255,7 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
AddStep("Seek(451)", () => Clock.Seek(451));
|
AddStep("Seek(451)", () => Clock.Seek(451));
|
||||||
|
checkTime(451);
|
||||||
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true));
|
||||||
checkTime(450);
|
checkTime(450);
|
||||||
AddStep("Seek(450.999)", () => Clock.Seek(450.999));
|
AddStep("Seek(450.999)", () => Clock.Seek(450.999));
|
||||||
@ -276,6 +280,7 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
double lastTime = 0;
|
double lastTime = 0;
|
||||||
|
|
||||||
AddStep("Seek(0)", () => Clock.Seek(0));
|
AddStep("Seek(0)", () => Clock.Seek(0));
|
||||||
|
checkTime(0);
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Screens.Edit;
|
|
||||||
using osu.Game.Screens.Edit.Components;
|
using osu.Game.Screens.Edit.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -19,19 +15,12 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
var clock = new EditorClock { IsCoupled = false };
|
Child = new PlaybackControl
|
||||||
Dependencies.CacheAs(clock);
|
|
||||||
|
|
||||||
var playback = new PlaybackControl
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(200, 100)
|
Size = new Vector2(200, 100)
|
||||||
};
|
};
|
||||||
|
|
||||||
Beatmap.Value = CreateWorkingBeatmap(new Beatmap());
|
|
||||||
|
|
||||||
Child = playback;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user