1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 09:37:23 +08:00

Add better coverage and more comments explaining the structure of test setup

This commit is contained in:
Dean Herbert 2023-03-03 17:18:14 +09:00
parent 82293c0c86
commit 7a092ea995

View File

@ -516,15 +516,20 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
sets.Clear(); sets.Clear();
for (int i = 0; i < 20; i++) for (int i = 0; i < 10; i++)
{ {
var set = TestResources.CreateTestBeatmapSetInfo(5); var set = TestResources.CreateTestBeatmapSetInfo(5);
if (i >= 2 && i < 10) // A total of 6 sets have date submitted (4 don't)
// A total of 5 sets have artist string (3 of which also have date submitted)
if (i >= 2 && i < 8) // i = 2, 3, 4, 5, 6, 7 have submitted date
set.DateSubmitted = DateTimeOffset.Now.AddMinutes(i); set.DateSubmitted = DateTimeOffset.Now.AddMinutes(i);
if (i < 5) if (i < 5) // i = 0, 1, 2, 3, 4 have matching string
set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string); set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string);
set.Beatmaps.ForEach(b => b.Metadata.Title = $"submitted: {set.DateSubmitted}");
sets.Add(set); sets.Add(set);
} }
}); });
@ -532,9 +537,14 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(sets); loadBeatmaps(sets);
AddStep("Sort by date submitted", () => carousel.Filter(new FilterCriteria { Sort = SortMode.DateSubmitted }, false)); AddStep("Sort by date submitted", () => carousel.Filter(new FilterCriteria { Sort = SortMode.DateSubmitted }, false));
checkVisibleItemCount(diff: false, count: 20); checkVisibleItemCount(diff: false, count: 10);
checkVisibleItemCount(diff: true, count: 5); checkVisibleItemCount(diff: true, count: 5);
AddAssert("missing date are at end",
() => carousel.Items.OfType<DrawableCarouselBeatmapSet>().Reverse().TakeWhile(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted == null).Count(), () => Is.EqualTo(4));
AddAssert("rest are at start", () => carousel.Items.OfType<DrawableCarouselBeatmapSet>().TakeWhile(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted != null).Count(),
() => Is.EqualTo(6));
AddStep("Sort by date submitted and string", () => carousel.Filter(new FilterCriteria AddStep("Sort by date submitted and string", () => carousel.Filter(new FilterCriteria
{ {
Sort = SortMode.DateSubmitted, Sort = SortMode.DateSubmitted,
@ -543,9 +553,10 @@ namespace osu.Game.Tests.Visual.SongSelect
checkVisibleItemCount(diff: false, count: 5); checkVisibleItemCount(diff: false, count: 5);
checkVisibleItemCount(diff: true, count: 5); checkVisibleItemCount(diff: true, count: 5);
AddAssert("missing date submitted are at end", AddAssert("missing date are at end",
() => carousel.Items.OfType<DrawableCarouselBeatmapSet>().TakeLast(2).All(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted == null)); () => carousel.Items.OfType<DrawableCarouselBeatmapSet>().Reverse().TakeWhile(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted == null).Count(), () => Is.EqualTo(2));
AddAssert("rest are at start", () => carousel.Items.OfType<DrawableCarouselBeatmapSet>().Take(3).All(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted != null)); AddAssert("rest are at start", () => carousel.Items.OfType<DrawableCarouselBeatmapSet>().TakeWhile(i => i.Item is CarouselBeatmapSet s && s.BeatmapSet.DateSubmitted != null).Count(),
() => Is.EqualTo(3));
} }
[Test] [Test]