1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00
osu-lazer/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs

186 lines
6.1 KiB
C#
Raw Normal View History

2020-04-16 01:19:17 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Screens.Select;
using osu.Game.Tests.Visual.Navigation;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.SongSelect
{
2020-04-18 00:55:51 +08:00
[HeadlessTest]
2020-04-16 01:19:17 +08:00
public class TestSceneBeatmapRecommendations : OsuGameTestScene
{
[Resolved]
private DifficultyRecommender recommender { get; set; }
2020-04-18 00:55:51 +08:00
[Resolved]
private RulesetStore rulesets { get; set; }
2020-04-16 01:19:17 +08:00
[SetUpSteps]
public new void SetUpSteps()
{
AddStep("register request handling", () =>
{
((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case GetUserRequest userRequest:
2020-04-25 15:21:01 +08:00
userRequest.TriggerSuccess(getUser(userRequest.Ruleset.ID));
2020-04-16 01:19:17 +08:00
break;
}
};
});
2020-04-25 15:21:01 +08:00
// Force recommender to calculate its star ratings again
AddStep("calculate recommended SRs", () => recommender.APIStateChanged(API, APIState.Online));
User getUser(int? rulesetID)
{
return new User
{
Username = @"Dummy",
Id = 1001,
Statistics = new UserStatistics
{
PP = getNecessaryPP(rulesetID)
}
};
}
decimal getNecessaryPP(int? rulesetID)
{
switch (rulesetID)
{
case 0:
return 336;
case 1:
return 928;
case 2:
return 1905;
case 3:
return 3329;
default:
return 0;
}
}
2020-04-16 01:19:17 +08:00
}
[Test]
public void TestPresentedBeatmapIsRecommended()
{
2020-04-18 00:55:51 +08:00
var importFunctions = new List<Func<BeatmapSetInfo>>();
for (int i = 0; i < 5; i++)
{
importFunctions.Add(importBeatmap(i, new List<RulesetInfo> { null, null, null, null, null }));
}
2020-04-16 01:19:17 +08:00
for (int i = 0; i < 5; i++)
{
2020-04-18 00:55:51 +08:00
presentAndConfirm(importFunctions[i], i, 2);
2020-04-16 01:19:17 +08:00
}
}
2020-04-18 00:55:51 +08:00
[Test]
public void TestBestRulesetIsRecommended()
2020-04-16 01:19:17 +08:00
{
2020-04-25 15:22:19 +08:00
var osuRuleset = rulesets.GetRuleset(0);
var taikoRuleset = rulesets.GetRuleset(1);
var catchRuleset = rulesets.GetRuleset(2);
var maniaRuleset = rulesets.GetRuleset(3);
2020-04-16 01:19:17 +08:00
2020-04-18 00:55:51 +08:00
var osuImport = importBeatmap(0, new List<RulesetInfo> { osuRuleset });
var mixedImport = importBeatmap(1, new List<RulesetInfo> { taikoRuleset, catchRuleset, maniaRuleset });
// Make sure we are on standard ruleset
presentAndConfirm(osuImport, 0, 1);
// Present mixed difficulty set, expect ruleset with highest star difficulty
presentAndConfirm(mixedImport, 1, 3);
}
[Test]
public void TestSecondBestRulesetIsRecommended()
{
2020-04-25 15:22:19 +08:00
var osuRuleset = rulesets.GetRuleset(0);
var taikoRuleset = rulesets.GetRuleset(1);
var catchRuleset = rulesets.GetRuleset(2);
2020-04-18 00:55:51 +08:00
var osuImport = importBeatmap(0, new List<RulesetInfo> { osuRuleset });
var mixedImport = importBeatmap(1, new List<RulesetInfo> { taikoRuleset, catchRuleset, taikoRuleset });
// Make sure we are on standard ruleset
presentAndConfirm(osuImport, 0, 1);
2020-04-16 01:19:17 +08:00
2020-04-18 00:55:51 +08:00
// Present mixed difficulty set, expect ruleset with highest star difficulty
presentAndConfirm(mixedImport, 1, 2);
2020-04-16 01:19:17 +08:00
}
2020-04-18 00:55:51 +08:00
private Func<BeatmapSetInfo> importBeatmap(int importID, List<RulesetInfo> rulesets)
2020-04-16 01:19:17 +08:00
{
BeatmapSetInfo imported = null;
2020-04-18 00:55:51 +08:00
AddStep($"import beatmap {importID}", () =>
2020-04-16 01:19:17 +08:00
{
var difficulty = new BeatmapDifficulty();
var metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
2020-04-18 00:55:51 +08:00
Title = $"import {importID}"
2020-04-16 01:19:17 +08:00
};
var beatmaps = new List<BeatmapInfo>();
2020-04-18 00:55:51 +08:00
int difficultyID = 1;
2020-04-16 01:19:17 +08:00
2020-04-18 00:55:51 +08:00
foreach (RulesetInfo r in rulesets)
2020-04-16 01:19:17 +08:00
{
beatmaps.Add(new BeatmapInfo
{
2020-04-18 00:55:51 +08:00
OnlineBeatmapID = importID + 1024 * difficultyID,
2020-04-16 01:19:17 +08:00
Metadata = metadata,
BaseDifficulty = difficulty,
2020-04-18 00:55:51 +08:00
Ruleset = r ?? rulesets.First(),
StarDifficulty = difficultyID,
2020-04-16 01:19:17 +08:00
});
2020-04-18 00:55:51 +08:00
difficultyID++;
2020-04-16 01:19:17 +08:00
}
imported = Game.BeatmapManager.Import(new BeatmapSetInfo
{
Hash = Guid.NewGuid().ToString(),
2020-04-18 00:55:51 +08:00
OnlineBeatmapSetID = importID,
2020-04-16 01:19:17 +08:00
Metadata = metadata,
Beatmaps = beatmaps,
}).Result;
});
2020-04-18 00:55:51 +08:00
AddAssert($"import {importID} succeeded", () => imported != null);
2020-04-16 01:19:17 +08:00
return () => imported;
}
2020-04-25 15:25:07 +08:00
private void presentAndConfirm(Func<BeatmapSetInfo> getImport, int importedID, int expectedDiff)
2020-04-16 01:19:17 +08:00
{
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
2020-04-25 15:25:07 +08:00
AddUntilStep("recommended beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == importedID + 1024 * expectedDiff);
2020-04-16 01:19:17 +08:00
}
}
}