2019-02-14 07:22:14 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-02-14 07:22:14 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using NUnit.Framework;
|
2021-05-14 21:50:25 +00:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2019-02-14 07:22:14 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2019-09-09 22:43:30 +00:00
|
|
|
using osu.Game.IO;
|
2019-02-15 05:42:42 +00:00
|
|
|
using osu.Game.Rulesets;
|
2019-02-14 07:22:14 +00: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; }
|
|
|
|
|
2022-01-23 03:25:22 +00:00
|
|
|
protected void Test(double expectedStarRating, int expectedMaxCombo, string name, params Mod[] mods)
|
2021-09-14 04:45:10 +00:00
|
|
|
{
|
2022-01-23 03:25:22 +00:00
|
|
|
var attributes = CreateDifficultyCalculator(getBeatmap(name)).Calculate(mods);
|
|
|
|
|
2021-09-14 04:45:10 +00:00
|
|
|
// Platform-dependent math functions (Pow, Cbrt, Exp, etc) may result in minute differences.
|
2022-01-23 03:25:22 +00:00
|
|
|
Assert.That(attributes.StarRating, Is.EqualTo(expectedStarRating).Within(0.00001));
|
|
|
|
Assert.That(attributes.MaxCombo, Is.EqualTo(expectedMaxCombo));
|
2021-09-14 04:45:10 +00:00
|
|
|
}
|
2019-02-14 07:22:14 +00:00
|
|
|
|
2021-11-15 09:42:47 +00:00
|
|
|
private IWorkingBeatmap getBeatmap(string name)
|
2019-02-14 07:22:14 +00:00
|
|
|
{
|
|
|
|
using (var resStream = openResource($"{resource_namespace}.{name}.osu"))
|
2019-09-09 22:43:30 +00:00
|
|
|
using (var stream = new LineBufferedReader(resStream))
|
2019-02-14 07:22:14 +00:00
|
|
|
{
|
|
|
|
var decoder = Decoder.GetDecoder<Beatmap>(stream);
|
2019-02-15 05:42:42 +00:00
|
|
|
|
2021-06-01 05:33:21 +00:00
|
|
|
((LegacyBeatmapDecoder)decoder).ApplyOffsets = false;
|
2019-02-15 05:42:42 +00:00
|
|
|
|
2021-06-01 05:33:21 +00:00
|
|
|
return new TestWorkingBeatmap(decoder.Decode(stream))
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = CreateRuleset().RulesetInfo
|
|
|
|
}
|
|
|
|
};
|
2019-02-14 07:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Stream openResource(string name)
|
|
|
|
{
|
2022-12-16 10:06:11 +00:00
|
|
|
string localPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).AsNonNull();
|
2019-02-14 07:22:14 +00:00
|
|
|
return Assembly.LoadFrom(Path.Combine(localPath, $"{ResourceAssembly}.dll")).GetManifestResourceStream($@"{ResourceAssembly}.Resources.{name}");
|
|
|
|
}
|
|
|
|
|
2021-11-15 09:42:47 +00:00
|
|
|
protected abstract DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap);
|
2019-02-15 05:42:42 +00:00
|
|
|
|
|
|
|
protected abstract Ruleset CreateRuleset();
|
2019-02-14 07:22:14 +00:00
|
|
|
}
|
|
|
|
}
|