From 3afaafb1d9a19692cbd6750eda24cbd7d920c7d2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 21 Nov 2023 15:05:51 +0900 Subject: [PATCH] Reorder and simplify private helper methods --- .../TestSceneOpenEditorTimestampInMania.cs | 53 +++++----- .../TestSceneOpenEditorTimestampInOsu.cs | 65 ++++++------ .../Editing/TestSceneOpenEditorTimestamp.cs | 100 +++++++++--------- 3 files changed, 103 insertions(+), 115 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneOpenEditorTimestampInMania.cs b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneOpenEditorTimestampInMania.cs index 3c6a9f3b42..05c881d284 100644 --- a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneOpenEditorTimestampInMania.cs +++ b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneOpenEditorTimestampInMania.cs @@ -14,35 +14,6 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor { protected override Ruleset CreateEditorRuleset() => new ManiaRuleset(); - private void addStepClickLink(string timestamp, string step = "", bool displayTimestamp = true) - { - AddStep(displayTimestamp ? $"{step} {timestamp}" : step, () => Editor.HandleTimestamp(timestamp)); - AddUntilStep("wait for seek", () => EditorClock.SeekingOrStopped.Value); - } - - private void addReset() - { - addStepClickLink("00:00:000", "reset", false); - } - - private bool checkSnapAndSelectColumn(double startTime, IReadOnlyCollection<(int, int)>? columnPairs = null) - { - bool checkColumns = columnPairs != null - ? EditorBeatmap.SelectedHitObjects.All(x => columnPairs.Any(col => isNoteAt(x, col.Item1, col.Item2))) - : !EditorBeatmap.SelectedHitObjects.Any(); - - return EditorClock.CurrentTime == startTime - && EditorBeatmap.SelectedHitObjects.Count == (columnPairs?.Count ?? 0) - && checkColumns; - } - - private bool isNoteAt(HitObject hitObject, double time, int column) - { - return hitObject is ManiaHitObject maniaHitObject - && maniaHitObject.StartTime == time - && maniaHitObject.Column == column; - } - [Test] public void TestNormalSelection() { @@ -95,5 +66,29 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor addStepClickLink("00:00:000 (1,2)", "std link"); AddAssert("snap to 1, select none", () => checkSnapAndSelectColumn(2_170)); } + + private void addStepClickLink(string timestamp, string step = "", bool displayTimestamp = true) + { + AddStep(displayTimestamp ? $"{step} {timestamp}" : step, () => Editor.HandleTimestamp(timestamp)); + AddUntilStep("wait for seek", () => EditorClock.SeekingOrStopped.Value); + } + + private void addReset() => addStepClickLink("00:00:000", "reset", false); + + private bool checkSnapAndSelectColumn(double startTime, IReadOnlyCollection<(int, int)>? columnPairs = null) + { + bool checkColumns = columnPairs != null + ? EditorBeatmap.SelectedHitObjects.All(x => columnPairs.Any(col => isNoteAt(x, col.Item1, col.Item2))) + : !EditorBeatmap.SelectedHitObjects.Any(); + + return EditorClock.CurrentTime == startTime + && EditorBeatmap.SelectedHitObjects.Count == (columnPairs?.Count ?? 0) + && checkColumns; + } + + private bool isNoteAt(HitObject hitObject, double time, int column) => + hitObject is ManiaHitObject maniaHitObject + && maniaHitObject.StartTime == time + && maniaHitObject.Column == column; } } diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOpenEditorTimestampInOsu.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOpenEditorTimestampInOsu.cs index 753400e10e..943858652c 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOpenEditorTimestampInOsu.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOpenEditorTimestampInOsu.cs @@ -15,40 +15,6 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor { protected override Ruleset CreateEditorRuleset() => new OsuRuleset(); - private void addStepClickLink(string timestamp, string step = "", bool displayTimestamp = true) - { - AddStep(displayTimestamp ? $"{step} {timestamp}" : step, () => Editor.HandleTimestamp(timestamp)); - AddUntilStep("wait for seek", () => EditorClock.SeekingOrStopped.Value); - } - - private void addReset() - { - addStepClickLink("00:00:000", "reset", false); - } - - private void checkSelection(Func startTime, params int[] comboNumbers) - => AddUntilStep($"seeked & selected {(comboNumbers.Any() ? string.Join(",", comboNumbers) : "nothing")}", () => - { - bool checkCombos = comboNumbers.Any() - ? hasCombosInOrder(EditorBeatmap.SelectedHitObjects, comboNumbers) - : !EditorBeatmap.SelectedHitObjects.Any(); - - return EditorClock.CurrentTime == startTime() - && EditorBeatmap.SelectedHitObjects.Count == comboNumbers.Length - && checkCombos; - }); - - private bool hasCombosInOrder(IEnumerable selected, params int[] comboNumbers) - { - List hitObjects = selected.ToList(); - if (hitObjects.Count != comboNumbers.Length) - return false; - - return !hitObjects.Select(x => (OsuHitObject)x) - .Where((x, i) => x.IndexInCurrentCombo + 1 != comboNumbers[i]) - .Any(); - } - [Test] public void TestNormalSelection() { @@ -90,5 +56,36 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor addStepClickLink("00:00:956 (956|1,956|2)", "mania link"); checkSelection(() => firstObject.StartTime); } + + private void addReset() => addStepClickLink("00:00:000", "reset", false); + + private void addStepClickLink(string timestamp, string step = "", bool displayTimestamp = true) + { + AddStep(displayTimestamp ? $"{step} {timestamp}" : step, () => Editor.HandleTimestamp(timestamp)); + AddUntilStep("wait for seek", () => EditorClock.SeekingOrStopped.Value); + } + + private void checkSelection(Func startTime, params int[] comboNumbers) + => AddUntilStep($"seeked & selected {(comboNumbers.Any() ? string.Join(",", comboNumbers) : "nothing")}", () => + { + bool checkCombos = comboNumbers.Any() + ? hasCombosInOrder(EditorBeatmap.SelectedHitObjects, comboNumbers) + : !EditorBeatmap.SelectedHitObjects.Any(); + + return EditorClock.CurrentTime == startTime() + && EditorBeatmap.SelectedHitObjects.Count == comboNumbers.Length + && checkCombos; + }); + + private bool hasCombosInOrder(IEnumerable selected, params int[] comboNumbers) + { + List hitObjects = selected.ToList(); + if (hitObjects.Count != comboNumbers.Length) + return false; + + return !hitObjects.Select(x => (OsuHitObject)x) + .Where((x, i) => x.IndexInCurrentCombo + 1 != comboNumbers[i]) + .Any(); + } } } diff --git a/osu.Game.Tests/Visual/Editing/TestSceneOpenEditorTimestamp.cs b/osu.Game.Tests/Visual/Editing/TestSceneOpenEditorTimestamp.cs index 86ceb73f7a..dacc5887d0 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneOpenEditorTimestamp.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneOpenEditorTimestamp.cs @@ -25,58 +25,6 @@ namespace osu.Game.Tests.Visual.Editing private EditorBeatmap editorBeatmap => editor.ChildrenOfType().Single(); private EditorClock editorClock => editor.ChildrenOfType().Single(); - private void addStepClickLink(string timestamp, string step = "", bool waitForSeek = true) - { - AddStep($"{step} {timestamp}", () => - Game.HandleLink(new LinkDetails(LinkAction.OpenEditorTimestamp, timestamp)) - ); - - if (waitForSeek) - AddUntilStep("wait for seek", () => editorClock.SeekingOrStopped.Value); - } - - private void addStepScreenModeTo(EditorScreenMode screenMode) - { - AddStep("change screen to " + screenMode, () => editor.Mode.Value = screenMode); - } - - private void assertOnScreenAt(EditorScreenMode screen, double time, string text = "stayed in") - { - AddAssert($"{text} {screen} at {time}", () => - editor.Mode.Value == screen - && editorClock.CurrentTime == time - ); - } - - private void assertMovedScreenTo(EditorScreenMode screen, string text = "moved to") - { - AddAssert($"{text} {screen}", () => editor.Mode.Value == screen); - } - - private void setUpEditor(RulesetInfo ruleset) - { - BeatmapSetInfo beatmapSet = null!; - - AddStep("Import test beatmap", () => - Game.BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely() - ); - AddStep("Retrieve beatmap", () => - beatmapSet = Game.BeatmapManager.QueryBeatmapSet(set => !set.Protected).AsNonNull().Value.Detach() - ); - AddStep("Present beatmap", () => Game.PresentBeatmap(beatmapSet)); - AddUntilStep("Wait for song select", () => - Game.Beatmap.Value.BeatmapSetInfo.Equals(beatmapSet) - && Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect - && songSelect.IsLoaded - ); - AddStep("Switch ruleset", () => Game.Ruleset.Value = ruleset); - AddStep("Open editor for ruleset", () => - ((PlaySongSelect)Game.ScreenStack.CurrentScreen) - .Edit(beatmapSet.Beatmaps.Last(beatmap => beatmap.Ruleset.Name == ruleset.Name)) - ); - AddUntilStep("Wait for editor open", () => editor.ReadyForUse); - } - [Test] public void TestErrorNotifications() { @@ -151,5 +99,53 @@ namespace osu.Game.Tests.Visual.Editing addStepClickLink("00:00:000"); assertOnScreenAt(EditorScreenMode.Compose, 0); } + + private void addStepClickLink(string timestamp, string step = "", bool waitForSeek = true) + { + AddStep($"{step} {timestamp}", () => + Game.HandleLink(new LinkDetails(LinkAction.OpenEditorTimestamp, timestamp)) + ); + + if (waitForSeek) + AddUntilStep("wait for seek", () => editorClock.SeekingOrStopped.Value); + } + + private void addStepScreenModeTo(EditorScreenMode screenMode) => + AddStep("change screen to " + screenMode, () => editor.Mode.Value = screenMode); + + private void assertOnScreenAt(EditorScreenMode screen, double time) + { + AddAssert($"stayed on {screen} at {time}", () => + editor.Mode.Value == screen + && editorClock.CurrentTime == time + ); + } + + private void assertMovedScreenTo(EditorScreenMode screen, string text = "moved to") => + AddAssert($"{text} {screen}", () => editor.Mode.Value == screen); + + private void setUpEditor(RulesetInfo ruleset) + { + BeatmapSetInfo beatmapSet = null!; + + AddStep("Import test beatmap", () => + Game.BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely() + ); + AddStep("Retrieve beatmap", () => + beatmapSet = Game.BeatmapManager.QueryBeatmapSet(set => !set.Protected).AsNonNull().Value.Detach() + ); + AddStep("Present beatmap", () => Game.PresentBeatmap(beatmapSet)); + AddUntilStep("Wait for song select", () => + Game.Beatmap.Value.BeatmapSetInfo.Equals(beatmapSet) + && Game.ScreenStack.CurrentScreen is PlaySongSelect songSelect + && songSelect.IsLoaded + ); + AddStep("Switch ruleset", () => Game.Ruleset.Value = ruleset); + AddStep("Open editor for ruleset", () => + ((PlaySongSelect)Game.ScreenStack.CurrentScreen) + .Edit(beatmapSet.Beatmaps.Last(beatmap => beatmap.Ruleset.Name == ruleset.Name)) + ); + AddUntilStep("Wait for editor open", () => editor.ReadyForUse); + } } }