1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Fixed up tests

This commit is contained in:
ratinfx 2023-11-04 12:04:58 +01:00
parent f867cff8c7
commit 19cdf99df8

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.Editing
protected void AddStepClickLink(string timestamp, string step = "")
{
AddStep(step + timestamp, () =>
AddStep($"{step} {timestamp}", () =>
Game.HandleLink(new LinkDetails(LinkAction.OpenEditorTimestamp, timestamp))
);
}
@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.Editing
AddStep("change screen to " + screenMode, () => Editor.Mode.Value = screenMode);
}
protected void AssertOnScreenAt(EditorScreenMode screen, double time, string text = "stays in")
protected void AssertOnScreenAt(EditorScreenMode screen, double time, string text = "stayed in")
{
AddAssert($"{text} {screen} at {time}", () =>
Editor.Mode.Value == screen
@ -51,7 +51,34 @@ namespace osu.Game.Tests.Visual.Editing
);
}
protected bool HasCombosInOrder(IEnumerable<HitObject> selected, params int[] comboNumbers)
protected void AssertMovedScreenTo(EditorScreenMode screen, string text = "moved to")
{
AddAssert($"{text} {screen}", () => Editor.Mode.Value == screen);
}
private bool checkSnapAndSelectCombo(double startTime, params int[] comboNumbers)
{
bool checkCombos = comboNumbers.Any()
? hasCombosInOrder(EditorBeatmap.SelectedHitObjects, comboNumbers)
: !EditorBeatmap.SelectedHitObjects.Any();
return EditorClock.CurrentTime == startTime
&& EditorBeatmap.SelectedHitObjects.Count == comboNumbers.Length
&& checkCombos;
}
private bool checkSnapAndSelectColumn(double startTime, List<(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 hasCombosInOrder(IEnumerable<HitObject> selected, params int[] comboNumbers)
{
List<HitObject> hitObjects = selected.ToList();
if (hitObjects.Count != comboNumbers.Length)
@ -62,7 +89,7 @@ namespace osu.Game.Tests.Visual.Editing
.Any();
}
protected bool IsNoteAt(HitObject hitObject, double time, int column)
private bool isNoteAt(HitObject hitObject, double time, int column)
{
return hitObject is IHasColumn columnInfo
&& hitObject.StartTime == time
@ -100,8 +127,7 @@ namespace osu.Game.Tests.Visual.Editing
AddStepClickLink("00:00:000");
AddAssert("recieved 'must be in edit'", () =>
Game.Notifications.UnreadCount.Value == 1
&& Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.MustBeInEdit) == 1
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.MustBeInEdit) == 1
);
AddStep("enter song select", () => Game.ChildrenOfType<ButtonSystem>().Single().OnSolo.Invoke());
@ -109,37 +135,35 @@ namespace osu.Game.Tests.Visual.Editing
AddStepClickLink("00:00:000 (1)");
AddAssert("recieved 'must be in edit'", () =>
Game.Notifications.UnreadCount.Value == 2
&& Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.MustBeInEdit) == 2
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.MustBeInEdit) == 2
);
SetUpEditor(rulesetInfo);
AddAssert("is editor Osu", () => EditorBeatmap.BeatmapInfo.Ruleset.Equals(rulesetInfo));
AddStepClickLink("00:000", "invalid link ");
AddStepClickLink("00:000", "invalid link");
AddAssert("recieved 'failed to process'", () =>
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.FailedToProcessTimestamp) == 1
);
AddStepClickLink("00:00:00:000", "invalid link ");
AddStepClickLink("00:00:00:000", "invalid link");
AddAssert("recieved 'failed to process'", () =>
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.FailedToProcessTimestamp) == 2
);
AddStepClickLink("00:00:000 ()", "invalid link ");
AddStepClickLink("00:00:000 ()", "invalid link");
AddAssert("recieved 'failed to process'", () =>
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.FailedToProcessTimestamp) == 3
);
AddStepClickLink("00:00:000 (-1)", "invalid link ");
AddStepClickLink("00:00:000 (-1)", "invalid link");
AddAssert("recieved 'failed to process'", () =>
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.FailedToProcessTimestamp) == 4
);
AddStepClickLink("50000:00:000", "too long link ");
AddStepClickLink("50000:00:000", "too long link");
AddAssert("recieved 'too long'", () =>
EditorClock.CurrentTime == 0
&& Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.TooLongTimestamp) == 1
Game.Notifications.AllNotifications.Count(x => x.Text == EditorStrings.TooLongTimestamp) == 1
);
}
@ -152,7 +176,7 @@ namespace osu.Game.Tests.Visual.Editing
SetUpEditor(rulesetInfo);
AddAssert("is editor Osu", () => EditorBeatmap.BeatmapInfo.Ruleset.Equals(rulesetInfo));
AddStepClickLink("1000:00:000", "long link ");
AddStepClickLink("1000:00:000", "long link");
AddAssert("moved to end of track", () =>
EditorClock.CurrentTime == long_link_value
|| (EditorClock.TrackLength < long_link_value && EditorClock.CurrentTime == EditorClock.TrackLength)
@ -163,40 +187,28 @@ namespace osu.Game.Tests.Visual.Editing
AssertOnScreenAt(EditorScreenMode.SongSetup, 0);
AddStepClickLink("00:05:000 (0|0)");
AddAssert("seek and change screen", () =>
Editor.Mode.Value == EditorScreenMode.Compose
&& EditorClock.CurrentTime == EditorBeatmap.HitObjects.First(x => x.StartTime >= 5_000).StartTime
);
AssertMovedScreenTo(EditorScreenMode.Compose);
AddStepScreenModeTo(EditorScreenMode.Design);
AddStepClickLink("00:10:000");
AssertOnScreenAt(EditorScreenMode.Design, 10_000);
AddStepClickLink("00:15:000 (1)");
AddAssert("seek and change screen", () =>
Editor.Mode.Value == EditorScreenMode.Compose
&& EditorClock.CurrentTime == EditorBeatmap.HitObjects.First(x => x.StartTime >= 15_000).StartTime
);
AssertMovedScreenTo(EditorScreenMode.Compose);
AddStepScreenModeTo(EditorScreenMode.Timing);
AddStepClickLink("00:20:000");
AssertOnScreenAt(EditorScreenMode.Timing, 20_000);
AddStepClickLink("00:25:000 (0,1)");
AddAssert("seek and change screen", () =>
Editor.Mode.Value == EditorScreenMode.Compose
&& EditorClock.CurrentTime == EditorBeatmap.HitObjects.First(x => x.StartTime >= 25_000).StartTime
);
AssertMovedScreenTo(EditorScreenMode.Compose);
AddStepScreenModeTo(EditorScreenMode.Verify);
AddStepClickLink("00:30:000");
AssertOnScreenAt(EditorScreenMode.Verify, 30_000);
AddStepClickLink("00:35:000 (0,1)");
AddAssert("seek and change screen", () =>
Editor.Mode.Value == EditorScreenMode.Compose
&& EditorClock.CurrentTime == EditorBeatmap.HitObjects.First(x => x.StartTime >= 35_000).StartTime
);
AssertMovedScreenTo(EditorScreenMode.Compose);
AddStepClickLink("00:00:000");
AssertOnScreenAt(EditorScreenMode.Compose, 0);
@ -215,24 +227,14 @@ namespace osu.Game.Tests.Visual.Editing
AddAssert("snap and select 1-2-3", () =>
{
firstObject = EditorBeatmap.HitObjects.First();
return EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 3
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1, 2, 3);
return checkSnapAndSelectCombo(firstObject.StartTime, 1, 2, 3);
});
AddStepClickLink("00:01:450 (2,3,4,1,2)");
AddAssert("snap and select 2-3-4-1-2", () =>
EditorClock.CurrentTime == 1_450
&& EditorBeatmap.SelectedHitObjects.Count == 5
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 2, 3, 4, 1, 2)
);
AddAssert("snap and select 2-3-4-1-2", () => checkSnapAndSelectCombo(1_450, 2, 3, 4, 1, 2));
AddStepClickLink("00:00:956 (1,1,1)");
AddAssert("snap and select 1-1-1", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 3
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1, 1, 1)
);
AddAssert("snap and select 1-1-1", () => checkSnapAndSelectCombo(firstObject.StartTime, 1, 1, 1));
}
[Test]
@ -244,61 +246,33 @@ namespace osu.Game.Tests.Visual.Editing
SetUpEditor(rulesetInfo);
AddAssert("is editor Osu", () => EditorBeatmap.BeatmapInfo.Ruleset.Equals(rulesetInfo));
AddStepClickLink("00:00:000 (1,2,3)", "invalid offset ");
AddStepClickLink("00:00:000 (1,2,3)", "invalid offset");
AddAssert("snap to next, select 1-2-3", () =>
{
firstObject = EditorBeatmap.HitObjects.First();
return EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 3
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1, 2, 3);
return checkSnapAndSelectCombo(firstObject.StartTime, 1, 2, 3);
});
AddStepClickLink("00:00:956 (2,3,4)", "invalid offset ");
AddAssert("snap to next, select 2-3-4", () =>
EditorClock.CurrentTime == EditorBeatmap.HitObjects.First(x => x.StartTime >= 956).StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 3
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 2, 3, 4)
);
AddStepClickLink("00:00:956 (2,3,4)", "invalid offset");
AddAssert("snap to next, select 2-3-4", () => checkSnapAndSelectCombo(firstObject.StartTime, 2, 3, 4));
AddStepClickLink("00:00:000 (0)", "invalid combo ");
AddAssert("snap to 1, select 1", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 1
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1)
);
AddStepClickLink("00:00:000 (0)", "invalid offset");
AddAssert("snap and select 1", () => checkSnapAndSelectCombo(firstObject.StartTime, 1));
AddStepClickLink("00:00:000 (1)", "invalid offset ");
AddAssert("snap and select 1", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 1
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1)
);
AddStepClickLink("00:00:000 (1)", "invalid offset");
AddAssert("snap and select 1", () => checkSnapAndSelectCombo(firstObject.StartTime, 1));
AddStepClickLink("00:00:000 (2)", "invalid offset ");
AddAssert("snap and select 1", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 1
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 1)
);
AddStepClickLink("00:00:000 (2)", "invalid offset");
AddAssert("snap and select 1", () => checkSnapAndSelectCombo(firstObject.StartTime, 1));
AddStepClickLink("00:00:000 (2,3)", "invalid offset ");
AddAssert("snap to 1, select 2-3", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& EditorBeatmap.SelectedHitObjects.Count == 2
&& HasCombosInOrder(EditorBeatmap.SelectedHitObjects, 2, 3)
);
AddStepClickLink("00:00:000 (2,3)", "invalid offset");
AddAssert("snap to 1, select 2-3", () => checkSnapAndSelectCombo(firstObject.StartTime, 2, 3));
AddStepClickLink("00:00:956 (956|1,956|2)", "mania link ");
AddAssert("snap to next, select none", () =>
EditorClock.CurrentTime == firstObject?.StartTime
&& !EditorBeatmap.SelectedHitObjects.Any()
);
AddStepClickLink("00:00:956 (956|1,956|2)", "mania link");
AddAssert("snap to next, select none", () => checkSnapAndSelectCombo(firstObject.StartTime));
AddStepClickLink("00:00:000 (0|1)", "mania link ");
AddAssert("snap to 1, select none", () =>
EditorClock.CurrentTime == firstObject.StartTime
&& !EditorBeatmap.SelectedHitObjects.Any()
);
AddStepClickLink("00:00:000 (0|1)", "mania link");
AddAssert("snap to 1, select none", () => checkSnapAndSelectCombo(firstObject.StartTime));
}
[Test]
@ -310,41 +284,24 @@ namespace osu.Game.Tests.Visual.Editing
AddAssert("is editor Mania", () => EditorBeatmap.BeatmapInfo.Ruleset.Equals(rulesetInfo));
AddStepClickLink("00:11:010 (11010|1,11175|5,11258|3,11340|5,11505|1)");
AddAssert("selected group", () =>
EditorClock.CurrentTime == 11010
&& EditorBeatmap.SelectedHitObjects.Count == 5
&& EditorBeatmap.SelectedHitObjects.All(x =>
IsNoteAt(x, 11010, 1) || IsNoteAt(x, 11175, 5) ||
IsNoteAt(x, 11258, 3) || IsNoteAt(x, 11340, 5) ||
IsNoteAt(x, 11505, 1))
);
AddAssert("selected group", () => checkSnapAndSelectColumn(11010, new List<(int, int)>
{ (11010, 1), (11175, 5), (11258, 3), (11340, 5), (11505, 1) }
));
AddStepClickLink("00:00:956 (956|1,956|6,1285|3,1780|4)");
AddAssert("selected ungrouped", () =>
EditorClock.CurrentTime == 956
&& EditorBeatmap.SelectedHitObjects.Count == 4
&& EditorBeatmap.SelectedHitObjects.All(x =>
IsNoteAt(x, 956, 1) || IsNoteAt(x, 956, 6) ||
IsNoteAt(x, 1285, 3) || IsNoteAt(x, 1780, 4))
);
AddAssert("selected ungrouped", () => checkSnapAndSelectColumn(956, new List<(int, int)>
{ (956, 1), (956, 6), (1285, 3), (1780, 4) }
));
AddStepClickLink("02:36:560 (156560|1,156560|4,156560|6)");
AddAssert("selected in row", () =>
EditorClock.CurrentTime == 156560
&& EditorBeatmap.SelectedHitObjects.Count == 3
&& EditorBeatmap.SelectedHitObjects.All(x =>
IsNoteAt(x, 156560, 1) || IsNoteAt(x, 156560, 4) ||
IsNoteAt(x, 156560, 6))
);
AddAssert("selected in row", () => checkSnapAndSelectColumn(156560, new List<(int, int)>
{ (156560, 1), (156560, 4), (156560, 6) }
));
AddStepClickLink("00:35:736 (35736|3,36395|3,36725|3,37384|3)");
AddAssert("selected in column", () =>
EditorClock.CurrentTime == 35736
&& EditorBeatmap.SelectedHitObjects.Count == 4
&& EditorBeatmap.SelectedHitObjects.All(x =>
IsNoteAt(x, 35736, 3) || IsNoteAt(x, 36395, 3) ||
IsNoteAt(x, 36725, 3) || IsNoteAt(x, 37384, 3))
);
AddAssert("selected in column", () => checkSnapAndSelectColumn(35736, new List<(int, int)>
{ (35736, 3), (36395, 3), (36725, 3), (37384, 3) }
));
}
[Test]
@ -355,23 +312,16 @@ namespace osu.Game.Tests.Visual.Editing
SetUpEditor(rulesetInfo);
AddAssert("is editor Mania", () => EditorBeatmap.BeatmapInfo.Ruleset.Equals(rulesetInfo));
AddStepClickLink("00:00:000 (0|1)", "invalid link ");
AddAssert("snap to 1, select none", () =>
EditorClock.CurrentTime == 956
&& !EditorBeatmap.SelectedHitObjects.Any()
AddStepClickLink("00:00:000 (0|1)", "invalid link");
AddAssert("snap to 1, select none", () => checkSnapAndSelectColumn(956));
AddStepClickLink("00:00:000 (0)", "std link");
AddAssert("snap and select 1", () => checkSnapAndSelectColumn(956, new List<(int, int)>
{ (956, 1) })
);
AddStepClickLink("00:00:000 (0)", "std link ");
AddAssert("snap and select 1", () =>
EditorClock.CurrentTime == 956
&& EditorBeatmap.SelectedHitObjects.All(x => IsNoteAt(x, 956, 1))
);
AddStepClickLink("00:00:000 (1,2)", "std link ");
AddAssert("snap to 1, select none", () =>
EditorClock.CurrentTime == 956
&& !EditorBeatmap.SelectedHitObjects.Any()
);
AddStepClickLink("00:00:000 (1,2)", "std link");
AddAssert("snap to 1, select none", () => checkSnapAndSelectColumn(956));
}
}
}