From 843e9c53c0cda8146b2622dafa49e6ebd738197f Mon Sep 17 00:00:00 2001 From: Endrik Tombak Date: Wed, 3 Jan 2018 15:38:43 +0200 Subject: [PATCH] Add test cases for new randomizer behaviour --- .../Visual/TestCaseBeatmapCarousel.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/osu.Game.Tests/Visual/TestCaseBeatmapCarousel.cs b/osu.Game.Tests/Visual/TestCaseBeatmapCarousel.cs index c09b987407..8a0bd31678 100644 --- a/osu.Game.Tests/Visual/TestCaseBeatmapCarousel.cs +++ b/osu.Game.Tests/Visual/TestCaseBeatmapCarousel.cs @@ -128,6 +128,20 @@ private void prevRandom() => AddStep("select random last", () => selectedSets.Pop(); }); + private bool selectedBeatmapVisible() + { + var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected); + if (currentlySelected == null) + return true; + return !currentlySelected.Item.Filtered; + } + + private void checkInvisibleDifficultiesUnselectable() + { + nextRandom(); + AddAssert("Selection is visible", selectedBeatmapVisible); + } + /// /// Test keyboard traversal /// @@ -222,6 +236,15 @@ private void testRandom() nextRandom(); AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet)); + + AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(createTestBeatmapSetWith100Difficulties(set_count + 1))); + AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false)); + checkInvisibleDifficultiesUnselectable(); + checkInvisibleDifficultiesUnselectable(); + checkInvisibleDifficultiesUnselectable(); + checkInvisibleDifficultiesUnselectable(); + checkInvisibleDifficultiesUnselectable(); + AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false)); } /// @@ -384,6 +407,40 @@ private BeatmapSetInfo createTestBeatmapSet(int i) }; } + private BeatmapSetInfo createTestBeatmapSetWith100Difficulties(int i) + { + var toReturn = new BeatmapSetInfo + { + ID = i, + OnlineBeatmapSetID = i, + Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(), + Metadata = new BeatmapMetadata + { + OnlineBeatmapSetID = i, + // Create random metadata, then we can check if sorting works based on these + Artist = $"peppy{i.ToString().PadLeft(6, '0')}", + Title = $"test set #{i}!", + AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, i - 1)), 5)) + }, + Beatmaps = new List(), + }; + for (int b = 1; b < 101; b++) + { + toReturn.Beatmaps.Add(new BeatmapInfo + { + OnlineBeatmapID = b * 10, + Path = $"extra{b}.osu", + Version = $"Extra {b}", + StarDifficulty = 2, + BaseDifficulty = new BeatmapDifficulty + { + OverallDifficulty = 3.5f, + } + }); + } + return toReturn; + } + private class TestBeatmapCarousel : BeatmapCarousel { public new List Items => base.Items;