2019-02-14 15:22:14 +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.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using NUnit.Framework;
|
2021-05-15 05:50:25 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2019-02-14 15:22:14 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2019-09-10 06:43:30 +08:00
|
|
|
using osu.Game.IO;
|
2019-02-15 13:42:42 +08:00
|
|
|
using osu.Game.Rulesets;
|
2019-02-14 15:22:14 +08:00
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Beatmaps
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public abstract class DifficultyCalculatorTest
|
|
|
|
{
|
|
|
|
private const string resource_namespace = "Testing.Beatmaps";
|
|
|
|
|
|
|
|
protected abstract string ResourceAssembly { get; }
|
|
|
|
|
|
|
|
protected void Test(double expected, string name, params Mod[] mods)
|
|
|
|
=> Assert.AreEqual(expected, CreateDifficultyCalculator(getBeatmap(name)).Calculate(mods).StarRating);
|
|
|
|
|
|
|
|
private WorkingBeatmap getBeatmap(string name)
|
|
|
|
{
|
|
|
|
using (var resStream = openResource($"{resource_namespace}.{name}.osu"))
|
2019-09-10 06:43:30 +08:00
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2019-02-14 15:22:14 +08:00
|
|
|
{
|
|
|
|
var decoder = Decoder.GetDecoder<Beatmap>(stream);
|
2019-02-15 13:42:42 +08:00
|
|
|
|
2021-06-01 13:33:21 +08:00
|
|
|
((LegacyBeatmapDecoder)decoder).ApplyOffsets = false;
|
2019-02-15 13:42:42 +08:00
|
|
|
|
2021-06-01 13:33:21 +08:00
|
|
|
return new TestWorkingBeatmap(decoder.Decode(stream))
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = CreateRuleset().RulesetInfo
|
|
|
|
}
|
|
|
|
};
|
2019-02-14 15:22:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Stream openResource(string name)
|
|
|
|
{
|
2021-05-15 05:50:25 +08:00
|
|
|
var localPath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)).AsNonNull();
|
2019-02-14 15:22:14 +08:00
|
|
|
return Assembly.LoadFrom(Path.Combine(localPath, $"{ResourceAssembly}.dll")).GetManifestResourceStream($@"{ResourceAssembly}.Resources.{name}");
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:12:37 +08:00
|
|
|
protected abstract DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap);
|
2019-02-15 13:42:42 +08:00
|
|
|
|
|
|
|
protected abstract Ruleset CreateRuleset();
|
2019-02-14 15:22:14 +08:00
|
|
|
}
|
|
|
|
}
|