1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:07:50 +08:00
osu-lazer/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapRecommendations.cs

214 lines
7.7 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.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2020-04-16 01:19:17 +08:00
using osu.Game.Rulesets;
2020-05-01 22:59:45 +08:00
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
2020-04-16 01:19:17 +08:00
using osu.Game.Users;
namespace osu.Game.Tests.Visual.SongSelect
{
public class TestSceneBeatmapRecommendations : OsuGameTestScene
{
[SetUpSteps]
2020-05-01 22:59:45 +08:00
public override void SetUpSteps()
2020-04-16 01:19:17 +08:00
{
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));
return true;
2020-04-16 01:19:17 +08:00
}
return false;
2020-04-16 01:19:17 +08:00
};
});
2020-04-25 15:21:01 +08:00
2020-05-01 22:59:45 +08:00
base.SetUpSteps();
APIUser getUser(int? rulesetID)
2020-04-25 15:21:01 +08:00
{
return new APIUser
2020-04-25 15:21:01 +08:00
{
Username = @"Dummy",
Id = 1001,
Statistics = new UserStatistics
{
PP = getNecessaryPP(rulesetID)
}
};
}
decimal getNecessaryPP(int? rulesetID)
{
switch (rulesetID)
{
case 0:
2020-05-02 00:46:49 +08:00
return 336; // recommended star rating of 2
2020-04-25 15:21:01 +08:00
case 1:
2020-05-02 00:46:49 +08:00
return 928; // SR 3
2020-04-25 15:21:01 +08:00
case 2:
2020-05-02 00:46:49 +08:00
return 1905; // SR 4
2020-04-25 15:21:01 +08:00
case 3:
2020-05-02 00:46:49 +08:00
return 3329; // SR 5
2020-04-25 15:21:01 +08:00
default:
return 0;
}
}
2020-04-16 01:19:17 +08:00
}
[Test]
public void TestPresentedBeatmapIsRecommended()
{
2020-05-01 22:59:45 +08:00
List<BeatmapSetInfo> beatmapSets = null;
const int import_count = 5;
2020-04-18 00:55:51 +08:00
2020-05-01 22:59:45 +08:00
AddStep("import 5 maps", () =>
2020-04-18 00:55:51 +08:00
{
2020-05-01 22:59:45 +08:00
beatmapSets = new List<BeatmapSetInfo>();
2020-04-16 01:19:17 +08:00
2020-05-01 22:59:45 +08:00
for (int i = 0; i < import_count; ++i)
{
beatmapSets.Add(importBeatmapSet(i, Enumerable.Repeat(new OsuRuleset().RulesetInfo, 5)));
}
});
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(beatmapSets));
presentAndConfirm(() => beatmapSets[3], 2);
2020-04-16 01:19:17 +08:00
}
[Test]
public void TestCurrentRulesetIsRecommended()
{
BeatmapSetInfo catchSet = null, mixedSet = null;
AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(0, new[] { new CatchRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1,
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { catchSet, mixedSet }));
// Switch to catch
presentAndConfirm(() => catchSet, 1);
// Present mixed difficulty set, expect current ruleset to be selected
presentAndConfirm(() => mixedSet, 2);
}
2020-04-18 00:55:51 +08:00
[Test]
public void TestBestRulesetIsRecommended()
2020-04-16 01:19:17 +08:00
{
2020-05-01 22:59:45 +08:00
BeatmapSetInfo osuSet = null, mixedSet = null;
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1,
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
2020-04-16 01:19:17 +08:00
2020-05-01 22:59:45 +08:00
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
2020-04-18 00:55:51 +08:00
// Make sure we are on standard ruleset
2020-05-01 22:59:45 +08:00
presentAndConfirm(() => osuSet, 1);
2020-04-18 00:55:51 +08:00
// Present mixed difficulty set, expect ruleset with highest star difficulty
2020-05-01 22:59:45 +08:00
presentAndConfirm(() => mixedSet, 3);
2020-04-18 00:55:51 +08:00
}
[Test]
public void TestSecondBestRulesetIsRecommended()
{
2020-05-01 22:59:45 +08:00
BeatmapSetInfo osuSet = null, mixedSet = null;
2020-04-18 00:55:51 +08:00
2020-05-01 22:59:45 +08:00
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(1,
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new TaikoRuleset().RulesetInfo }));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
2020-04-18 00:55:51 +08:00
// Make sure we are on standard ruleset
2020-05-01 22:59:45 +08:00
presentAndConfirm(() => osuSet, 1);
2020-04-16 01:19:17 +08:00
2020-04-25 15:37:18 +08:00
// Present mixed difficulty set, expect ruleset with second highest star difficulty
2020-05-01 22:59:45 +08:00
presentAndConfirm(() => mixedSet, 2);
2020-04-16 01:19:17 +08:00
}
2020-05-02 00:08:56 +08:00
[Test]
public void TestCorrectStarRatingIsUsed()
{
BeatmapSetInfo osuSet = null, maniaSet = null;
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(0, new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(1, Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10)));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, maniaSet }));
// Make sure we are on standard ruleset
presentAndConfirm(() => osuSet, 1);
// Present mania set, expect the difficulty that matches recommended mania star rating
presentAndConfirm(() => maniaSet, 5);
}
2020-05-01 22:59:45 +08:00
private BeatmapSetInfo importBeatmapSet(int importID, IEnumerable<RulesetInfo> difficultyRulesets)
2020-04-16 01:19:17 +08:00
{
2020-05-01 22:59:45 +08:00
var metadata = new BeatmapMetadata
2020-04-16 01:19:17 +08:00
{
2020-05-01 22:59:45 +08:00
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
Title = $"import {importID}"
};
2020-04-16 01:19:17 +08:00
2020-05-01 22:59:45 +08:00
var beatmapSet = new BeatmapSetInfo
{
Hash = Guid.NewGuid().ToString(),
OnlineBeatmapSetID = importID,
Metadata = metadata,
Beatmaps = difficultyRulesets.Select((ruleset, difficultyIndex) => new BeatmapInfo
2020-04-16 01:19:17 +08:00
{
2020-05-01 22:59:45 +08:00
OnlineBeatmapID = importID * 1024 + difficultyIndex,
2020-04-16 01:19:17 +08:00
Metadata = metadata,
2020-05-01 22:59:45 +08:00
BaseDifficulty = new BeatmapDifficulty(),
Ruleset = ruleset,
2020-05-02 00:08:56 +08:00
StarDifficulty = difficultyIndex + 1,
Version = $"SR{difficultyIndex + 1}"
2020-05-01 22:59:45 +08:00
}).ToList()
};
2020-04-16 01:19:17 +08:00
return Game.BeatmapManager.Import(beatmapSet).Result.Value;
2020-04-16 01:19:17 +08:00
}
2020-05-01 22:59:45 +08:00
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);
2020-04-25 15:36:19 +08:00
private void presentAndConfirm(Func<BeatmapSetInfo> getImport, 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:36:19 +08:00
AddUntilStep("recommended beatmap displayed", () =>
{
int? expectedID = getImport().Beatmaps[expectedDiff - 1].OnlineBeatmapID;
return Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == expectedID;
});
2020-04-16 01:19:17 +08:00
}
}
}