1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 12:42:54 +08:00

don't allow null values in FilterCriteria, ensure values in test instead

This commit is contained in:
Unknown 2018-10-19 12:22:05 +02:00
parent 11dad7bf74
commit d83ce7e4bb
3 changed files with 34 additions and 28 deletions

View File

@ -65,6 +65,10 @@ namespace osu.Game.Tests.Visual
carousel.SelectionChanged = s => currentSelection = s; carousel.SelectionChanged = s => currentSelection = s;
// not being hooked up to the config leads to the SR filter only showing 0 to 0 SR maps
// thus "filter" once to assume a 0 to 10 range
carousel.Filter(new TestCriteria());
loadBeatmaps(beatmapSets); loadBeatmaps(beatmapSets);
testTraversal(); testTraversal();
@ -150,9 +154,7 @@ namespace osu.Game.Tests.Visual
private bool selectedBeatmapVisible() private bool selectedBeatmapVisible()
{ {
var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected); var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State == CarouselItemState.Selected);
if (currentlySelected == null) return currentlySelected?.Item.Visible ?? true;
return true;
return currentlySelected.Item.Visible;
} }
private void checkInvisibleDifficultiesUnselectable() private void checkInvisibleDifficultiesUnselectable()
@ -165,8 +167,8 @@ namespace osu.Game.Tests.Visual
{ {
AddStep("Toggle non-matching filter", () => AddStep("Toggle non-matching filter", () =>
{ {
carousel.Filter(new FilterCriteria { SearchText = "Dingo" }, false); carousel.Filter(new TestCriteria { SearchText = "Dingo" }, false);
carousel.Filter(new FilterCriteria(), false); carousel.Filter(new TestCriteria(), false);
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID); eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
} }
); );
@ -207,7 +209,7 @@ namespace osu.Game.Tests.Visual
setSelected(1, 1); setSelected(1, 1);
AddStep("Filter", () => carousel.Filter(new FilterCriteria { SearchText = "set #3!" }, false)); AddStep("Filter", () => carousel.Filter(new TestCriteria { SearchText = "set #3!" }, false));
checkVisibleItemCount(diff: false, count: 1); checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 3); checkVisibleItemCount(diff: true, count: 3);
checkSelected(3, 1); checkSelected(3, 1);
@ -215,7 +217,7 @@ namespace osu.Game.Tests.Visual
advanceSelection(diff: true, count: 4); advanceSelection(diff: true, count: 4);
checkSelected(3, 2); checkSelected(3, 2);
AddStep("Un-filter (debounce)", () => carousel.Filter(new FilterCriteria())); AddStep("Un-filter (debounce)", () => carousel.Filter(new TestCriteria()));
AddUntilStep(() => !carousel.PendingFilterTask, "Wait for debounce"); AddUntilStep(() => !carousel.PendingFilterTask, "Wait for debounce");
checkVisibleItemCount(diff: false, count: set_count); checkVisibleItemCount(diff: false, count: set_count);
checkVisibleItemCount(diff: true, count: 3); checkVisibleItemCount(diff: true, count: 3);
@ -223,13 +225,13 @@ namespace osu.Game.Tests.Visual
// test filtering some difficulties (and keeping current beatmap set selected). // test filtering some difficulties (and keeping current beatmap set selected).
setSelected(1, 2); setSelected(1, 2);
AddStep("Filter some difficulties", () => carousel.Filter(new FilterCriteria { SearchText = "Normal" }, false)); AddStep("Filter some difficulties", () => carousel.Filter(new TestCriteria { SearchText = "Normal" }, false));
checkSelected(1, 1); checkSelected(1, 1);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false)); AddStep("Un-filter", () => carousel.Filter(new TestCriteria(), false));
checkSelected(1, 1); checkSelected(1, 1);
AddStep("Filter all", () => carousel.Filter(new FilterCriteria { SearchText = "Dingo" }, false)); AddStep("Filter all", () => carousel.Filter(new TestCriteria { SearchText = "Dingo" }, false));
checkVisibleItemCount(false, 0); checkVisibleItemCount(false, 0);
checkVisibleItemCount(true, 0); checkVisibleItemCount(true, 0);
@ -241,7 +243,7 @@ namespace osu.Game.Tests.Visual
advanceSelection(false); advanceSelection(false);
AddAssert("Selection is null", () => currentSelection == null); AddAssert("Selection is null", () => currentSelection == null);
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false)); AddStep("Un-filter", () => carousel.Filter(new TestCriteria(), false));
AddAssert("Selection is non-null", () => currentSelection != null); AddAssert("Selection is non-null", () => currentSelection != null);
} }
@ -273,15 +275,15 @@ namespace osu.Game.Tests.Visual
AddStep("select added set", () => carousel.SelectBeatmap(manyStarDiffs.Beatmaps[0], false)); AddStep("select added set", () => carousel.SelectBeatmap(manyStarDiffs.Beatmaps[0], false));
AddStep("Filter to 1-3 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 1, DisplayStarsMaximum = 3 }, false)); AddStep("Filter to 1-3 stars", () => carousel.Filter(new TestCriteria { DisplayStarsMinimum = 1, DisplayStarsMaximum = 3 }, false));
checkVisibleItemCount(diff: false, count: 1); checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 3); checkVisibleItemCount(diff: true, count: 3);
AddStep("Filter to 3-3 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 3, DisplayStarsMaximum = 3 }, false)); AddStep("Filter to 3-3 stars", () => carousel.Filter(new TestCriteria { DisplayStarsMinimum = 3, DisplayStarsMaximum = 3 }, false));
checkVisibleItemCount(diff: false, count: 1); checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 1); checkVisibleItemCount(diff: true, count: 1);
AddStep("Filter to 4-2 stars", () => carousel.Filter(new FilterCriteria { DisplayStarsMinimum = 4, DisplayStarsMaximum = 2 }, false)); AddStep("Filter to 4-2 stars", () => carousel.Filter(new TestCriteria { DisplayStarsMinimum = 4, DisplayStarsMaximum = 2 }, false));
checkVisibleItemCount(diff: false, count: 0); checkVisibleItemCount(diff: false, count: 0);
checkVisibleItemCount(diff: true, count: 0); checkVisibleItemCount(diff: true, count: 0);
@ -291,7 +293,7 @@ namespace osu.Game.Tests.Visual
manyStarDiffs = null; manyStarDiffs = null;
}); });
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false)); AddStep("Un-filter", () => carousel.Filter(new TestCriteria(), false));
} }
/// <summary> /// <summary>
@ -322,13 +324,13 @@ namespace osu.Game.Tests.Visual
AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet)); AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet));
AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(createTestBeatmapSetWithManyDifficulties(set_count + 1))); AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(createTestBeatmapSetWithManyDifficulties(set_count + 1)));
AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false)); AddStep("Filter Extra", () => carousel.Filter(new TestCriteria { SearchText = "Extra 10" }, false));
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
AddStep("Un-filter", () => carousel.Filter(new FilterCriteria(), false)); AddStep("Un-filter", () => carousel.Filter(new TestCriteria(), false));
} }
/// <summary> /// <summary>
@ -359,9 +361,9 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
private void testSorting() private void testSorting()
{ {
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false)); AddStep("Sort by author", () => carousel.Filter(new TestCriteria { Sort = SortMode.Author }, false));
AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.AuthorString == "zzzzz"); AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.AuthorString == "zzzzz");
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); AddStep("Sort by artist", () => carousel.Filter(new TestCriteria { Sort = SortMode.Artist }, false));
AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!")); AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!"));
} }
@ -451,7 +453,7 @@ namespace osu.Game.Tests.Visual
carousel.UpdateBeatmapSet(testMixed); carousel.UpdateBeatmapSet(testMixed);
}); });
AddStep("filter to ruleset 0", () => AddStep("filter to ruleset 0", () =>
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false)); carousel.Filter(new TestCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false));
AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false)); AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
AddAssert("unfiltered beatmap selected", () => carousel.SelectedBeatmap.Equals(testMixed.Beatmaps[0])); AddAssert("unfiltered beatmap selected", () => carousel.SelectedBeatmap.Equals(testMixed.Beatmaps[0]));
@ -581,5 +583,14 @@ namespace osu.Game.Tests.Visual
public bool PendingFilterTask => PendingFilter != null; public bool PendingFilterTask => PendingFilter != null;
} }
private class TestCriteria : FilterCriteria
{
public TestCriteria()
{
DisplayStarsMinimum = 0;
DisplayStarsMaximum = 10;
}
}
} }
} }

View File

@ -25,12 +25,7 @@ namespace osu.Game.Screens.Select.Carousel
base.Filter(criteria); base.Filter(criteria);
bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps; bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps;
match &= Beatmap.StarDifficulty >= criteria.DisplayStarsMinimum && Beatmap.StarDifficulty <= criteria.DisplayStarsMaximum;
if(criteria.DisplayStarsMinimum.HasValue)
match &= Beatmap.StarDifficulty >= criteria.DisplayStarsMinimum;
if (criteria.DisplayStarsMaximum.HasValue)
match &= Beatmap.StarDifficulty <= criteria.DisplayStarsMaximum;
if (!string.IsNullOrEmpty(criteria.SearchText)) if (!string.IsNullOrEmpty(criteria.SearchText))
match &= match &=

View File

@ -13,7 +13,7 @@ namespace osu.Game.Screens.Select
public string SearchText; public string SearchText;
public RulesetInfo Ruleset; public RulesetInfo Ruleset;
public bool AllowConvertedBeatmaps; public bool AllowConvertedBeatmaps;
public double? DisplayStarsMinimum; public double DisplayStarsMinimum;
public double? DisplayStarsMaximum; public double DisplayStarsMaximum;
} }
} }