mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Write tests
This commit is contained in:
parent
ee112c6f50
commit
bbbaaae3ee
@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -579,6 +580,34 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
checkVisibleItemCount(true, 15);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSelectRecommendedDifficulty()
|
||||
{
|
||||
void setRecommendedAndExpect(double recommended, int expectedSet, int expectedDiff)
|
||||
{
|
||||
AddStep($"Recommend SR {recommended}", () => carousel.RecommendedStarDifficulty.Value = recommended);
|
||||
advanceSelection(direction: 1, diff: false);
|
||||
waitForSelection(expectedSet, expectedDiff);
|
||||
}
|
||||
|
||||
createCarousel();
|
||||
AddStep("Add beatmaps", () =>
|
||||
{
|
||||
for (int i = 1; i <= 7; i++)
|
||||
{
|
||||
var set = createTestBeatmapSet(i);
|
||||
carousel.UpdateBeatmapSet(set);
|
||||
}
|
||||
});
|
||||
waitForSelection(1, 1);
|
||||
setRecommendedAndExpect(1, 2, 1);
|
||||
setRecommendedAndExpect(3.9, 3, 1);
|
||||
setRecommendedAndExpect(4.1, 4, 2);
|
||||
setRecommendedAndExpect(5.6, 5, 2);
|
||||
setRecommendedAndExpect(5.7, 6, 3);
|
||||
setRecommendedAndExpect(10, 7, 3);
|
||||
}
|
||||
|
||||
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null)
|
||||
{
|
||||
createCarousel();
|
||||
@ -781,6 +810,8 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
public new List<DrawableCarouselItem> Items => base.Items;
|
||||
|
||||
public new Bindable<double> RecommendedStarDifficulty => base.RecommendedStarDifficulty;
|
||||
|
||||
public bool PendingFilterTask => PendingFilter != null;
|
||||
|
||||
protected override IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => Enumerable.Empty<BeatmapSetInfo>();
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Screens.Select
|
||||
private const float bleed_top = FilterControl.HEIGHT;
|
||||
private const float bleed_bottom = Footer.HEIGHT;
|
||||
|
||||
private readonly Bindable<double> recommendedStarDifficulty = new Bindable<double>();
|
||||
protected readonly Bindable<double> RecommendedStarDifficulty = new Bindable<double>();
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
|
||||
@ -170,7 +170,7 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
if (api.LocalUser.Value is GuestUser)
|
||||
{
|
||||
recommendedStarDifficulty.Value = 0;
|
||||
RecommendedStarDifficulty.Value = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ namespace osu.Game.Screens.Select
|
||||
req.Success += result =>
|
||||
{
|
||||
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
|
||||
recommendedStarDifficulty.Value = Math.Pow((double)(result.Statistics.PP ?? 0), 0.4) * 0.195;
|
||||
RecommendedStarDifficulty.Value = Math.Pow((double)(result.Statistics.PP ?? 0), 0.4) * 0.195;
|
||||
};
|
||||
|
||||
api.PerformAsync(req);
|
||||
@ -617,7 +617,7 @@ namespace osu.Game.Screens.Select
|
||||
b.Metadata = beatmapSet.Metadata;
|
||||
}
|
||||
|
||||
var set = new CarouselBeatmapSet(beatmapSet, recommendedStarDifficulty);
|
||||
var set = new CarouselBeatmapSet(beatmapSet, RecommendedStarDifficulty);
|
||||
|
||||
foreach (var c in set.Beatmaps)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user