Add test cases for new randomizer behaviour

This commit is contained in:
Endrik Tombak 2018-01-03 15:38:43 +02:00
parent ce156098f6
commit 843e9c53c0
1 changed files with 57 additions and 0 deletions

View File

@ -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);
}
/// <summary>
/// Test keyboard traversal
/// </summary>
@ -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));
}
/// <summary>
@ -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<BeatmapInfo>(),
};
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<DrawableCarouselItem> Items => base.Items;