mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
More testing
This commit is contained in:
parent
1ac9ee5990
commit
90fa58b3b6
@ -6,44 +6,53 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Osu;
|
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
using osu.Game.Tests.Visual.Navigation;
|
using osu.Game.Tests.Visual.Navigation;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.SongSelect
|
namespace osu.Game.Tests.Visual.SongSelect
|
||||||
{
|
{
|
||||||
|
[HeadlessTest]
|
||||||
public class TestSceneBeatmapRecommendations : OsuGameTestScene
|
public class TestSceneBeatmapRecommendations : OsuGameTestScene
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private DifficultyRecommender recommender { get; set; }
|
private DifficultyRecommender recommender { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public new void SetUpSteps()
|
public new void SetUpSteps()
|
||||||
{
|
{
|
||||||
AddStep("register request handling", () =>
|
AddStep("register request handling", () =>
|
||||||
{
|
{
|
||||||
Logger.Log($"Registering request handling for {(DummyAPIAccess)API}");
|
|
||||||
((DummyAPIAccess)API).HandleRequest = req =>
|
((DummyAPIAccess)API).HandleRequest = req =>
|
||||||
{
|
{
|
||||||
Logger.Log($"New request {req}");
|
|
||||||
|
|
||||||
switch (req)
|
switch (req)
|
||||||
{
|
{
|
||||||
case GetUserRequest userRequest:
|
case GetUserRequest userRequest:
|
||||||
|
|
||||||
|
decimal pp = userRequest.Ruleset.ID switch
|
||||||
|
{
|
||||||
|
0 => 336, // Expected recommended star difficulty 2*
|
||||||
|
1 => 928, // Expected recommended star difficulty 3*
|
||||||
|
2 => 1905, // Expected recommended star difficulty 4*
|
||||||
|
3 => 3329, // Expected recommended star difficulty 5*
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
|
||||||
userRequest.TriggerSuccess(new User
|
userRequest.TriggerSuccess(new User
|
||||||
{
|
{
|
||||||
Username = @"Dummy",
|
Username = @"Dummy",
|
||||||
Id = 1001,
|
Id = 1001,
|
||||||
Statistics = new UserStatistics
|
Statistics = new UserStatistics
|
||||||
{
|
{
|
||||||
PP = 928 // Expected recommended star difficulty is 2.999
|
PP = pp
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -57,74 +66,103 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestPresentedBeatmapIsRecommended()
|
public void TestPresentedBeatmapIsRecommended()
|
||||||
{
|
{
|
||||||
var importFunctions = importBeatmaps(5);
|
var importFunctions = new List<Func<BeatmapSetInfo>>();
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
presentAndConfirm(importFunctions[i], i);
|
importFunctions.Add(importBeatmap(i, new List<RulesetInfo> { null, null, null, null, null }));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private List<Func<BeatmapSetInfo>> importBeatmaps(int amount, RulesetInfo ruleset = null)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
|
||||||
var importFunctions = new List<Func<BeatmapSetInfo>>();
|
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++)
|
|
||||||
{
|
{
|
||||||
importFunctions.Add(importBeatmap(i, ruleset));
|
presentAndConfirm(importFunctions[i], i, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return importFunctions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null)
|
[Test]
|
||||||
|
public void TestBestRulesetIsRecommended()
|
||||||
|
{
|
||||||
|
var osuRuleset = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
||||||
|
var taikoRuleset = rulesets.AvailableRulesets.First(r => r.ID == 1);
|
||||||
|
var catchRuleset = rulesets.AvailableRulesets.First(r => r.ID == 2);
|
||||||
|
var maniaRuleset = rulesets.AvailableRulesets.First(r => r.ID == 3);
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
var osuRuleset = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
||||||
|
var taikoRuleset = rulesets.AvailableRulesets.First(r => r.ID == 1);
|
||||||
|
var catchRuleset = rulesets.AvailableRulesets.First(r => r.ID == 2);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Present mixed difficulty set, expect ruleset with highest star difficulty
|
||||||
|
presentAndConfirm(mixedImport, 1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Func<BeatmapSetInfo> importBeatmap(int importID, List<RulesetInfo> rulesets)
|
||||||
{
|
{
|
||||||
BeatmapSetInfo imported = null;
|
BeatmapSetInfo imported = null;
|
||||||
AddStep($"import beatmap {i * 1000}", () =>
|
AddStep($"import beatmap {importID}", () =>
|
||||||
{
|
{
|
||||||
var difficulty = new BeatmapDifficulty();
|
var difficulty = new BeatmapDifficulty();
|
||||||
var metadata = new BeatmapMetadata
|
var metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
Artist = "SomeArtist",
|
Artist = "SomeArtist",
|
||||||
AuthorString = "SomeAuthor",
|
AuthorString = "SomeAuthor",
|
||||||
Title = $"import {i * 1000}"
|
Title = $"import {importID}"
|
||||||
};
|
};
|
||||||
|
|
||||||
var beatmaps = new List<BeatmapInfo>();
|
var beatmaps = new List<BeatmapInfo>();
|
||||||
|
int difficultyID = 1;
|
||||||
|
|
||||||
for (int j = 1; j <= 5; j++)
|
foreach (RulesetInfo r in rulesets)
|
||||||
{
|
{
|
||||||
beatmaps.Add(new BeatmapInfo
|
beatmaps.Add(new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = j * 1024 + i * 5,
|
OnlineBeatmapID = importID + 1024 * difficultyID,
|
||||||
Metadata = metadata,
|
Metadata = metadata,
|
||||||
BaseDifficulty = difficulty,
|
BaseDifficulty = difficulty,
|
||||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo,
|
Ruleset = r ?? rulesets.First(),
|
||||||
StarDifficulty = j,
|
StarDifficulty = difficultyID,
|
||||||
});
|
});
|
||||||
|
difficultyID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
imported = Game.BeatmapManager.Import(new BeatmapSetInfo
|
imported = Game.BeatmapManager.Import(new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Hash = Guid.NewGuid().ToString(),
|
Hash = Guid.NewGuid().ToString(),
|
||||||
OnlineBeatmapSetID = i,
|
OnlineBeatmapSetID = importID,
|
||||||
Metadata = metadata,
|
Metadata = metadata,
|
||||||
Beatmaps = beatmaps,
|
Beatmaps = beatmaps,
|
||||||
}).Result;
|
}).Result;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"import {i * 1000} succeeded", () => imported != null);
|
AddAssert($"import {importID} succeeded", () => imported != null);
|
||||||
|
|
||||||
return () => imported;
|
return () => imported;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void presentAndConfirm(Func<BeatmapSetInfo> getImport, int importedID)
|
private void presentAndConfirm(Func<BeatmapSetInfo> getImport, int importedID, int expextedDiff)
|
||||||
{
|
{
|
||||||
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
|
AddStep("present beatmap", () => Game.PresentBeatmap(getImport()));
|
||||||
|
|
||||||
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
|
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
|
||||||
AddUntilStep("recommended beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == importedID * 5 + 1024 * 3);
|
AddUntilStep("recommended beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == importedID + 1024 * expextedDiff);
|
||||||
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ namespace osu.Game.Online.API.Requests
|
|||||||
public class GetUserRequest : APIRequest<User>
|
public class GetUserRequest : APIRequest<User>
|
||||||
{
|
{
|
||||||
private readonly long? userId;
|
private readonly long? userId;
|
||||||
private readonly RulesetInfo ruleset;
|
public readonly RulesetInfo Ruleset;
|
||||||
|
|
||||||
public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
|
public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
|
||||||
{
|
{
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.ruleset = ruleset;
|
Ruleset = ruleset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => userId.HasValue ? $@"users/{userId}/{ruleset?.ShortName}" : $@"me/{ruleset?.ShortName}";
|
protected override string Target => userId.HasValue ? $@"users/{userId}/{Ruleset?.ShortName}" : $@"me/{Ruleset?.ShortName}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user