mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Make CheckAbnormalDifficultySettings
abstract
This commit is contained in:
parent
b132734f9c
commit
a4822fd615
@ -1,93 +0,0 @@
|
|||||||
// 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 osu.Game.Rulesets.Edit.Checks;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Rulesets.Objects;
|
|
||||||
using osu.Game.Rulesets.Edit;
|
|
||||||
using osu.Game.Tests.Beatmaps;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Editing.Checks
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class CheckAbnormalDifficultySettingsTest
|
|
||||||
{
|
|
||||||
private CheckAbnormalDifficultySettings check = null!;
|
|
||||||
|
|
||||||
private IBeatmap beatmap = new Beatmap<HitObject>();
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
check = new CheckAbnormalDifficultySettings();
|
|
||||||
beatmap.Difficulty = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestSettingsNormal()
|
|
||||||
{
|
|
||||||
var context = getContext();
|
|
||||||
var issues = check.Run(context).ToList();
|
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestAllSettingsMoreThanOneDecimal()
|
|
||||||
{
|
|
||||||
beatmap.Difficulty = new()
|
|
||||||
{
|
|
||||||
ApproachRate = 5.55f,
|
|
||||||
OverallDifficulty = 7.7777f,
|
|
||||||
CircleSize = 4.444f,
|
|
||||||
DrainRate = 1.1111111111f,
|
|
||||||
};
|
|
||||||
|
|
||||||
var context = getContext();
|
|
||||||
var issues = check.Run(context).ToList();
|
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(4));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestAllSettingsLessThanZero()
|
|
||||||
{
|
|
||||||
beatmap.Difficulty = new()
|
|
||||||
{
|
|
||||||
ApproachRate = -1,
|
|
||||||
OverallDifficulty = -20,
|
|
||||||
CircleSize = -11,
|
|
||||||
DrainRate = -34,
|
|
||||||
};
|
|
||||||
|
|
||||||
var context = getContext();
|
|
||||||
var issues = check.Run(context).ToList();
|
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(4));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestAllSettingsHigherThanTen()
|
|
||||||
{
|
|
||||||
beatmap.Difficulty = new()
|
|
||||||
{
|
|
||||||
ApproachRate = 14,
|
|
||||||
OverallDifficulty = 24,
|
|
||||||
CircleSize = 30,
|
|
||||||
DrainRate = 90,
|
|
||||||
};
|
|
||||||
|
|
||||||
var context = getContext();
|
|
||||||
var issues = check.Run(context).ToList();
|
|
||||||
|
|
||||||
Assert.That(issues, Has.Count.EqualTo(4));
|
|
||||||
}
|
|
||||||
|
|
||||||
private BeatmapVerifierContext getContext()
|
|
||||||
{
|
|
||||||
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -42,9 +42,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
// Events
|
// Events
|
||||||
new CheckBreaks(),
|
new CheckBreaks(),
|
||||||
|
|
||||||
// Settings
|
|
||||||
new CheckAbnormalDifficultySettings(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||||
|
@ -6,9 +6,9 @@ using osu.Game.Rulesets.Edit.Checks.Components;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Edit.Checks
|
namespace osu.Game.Rulesets.Edit.Checks
|
||||||
{
|
{
|
||||||
public class CheckAbnormalDifficultySettings : ICheck
|
public abstract class CheckAbnormalDifficultySettings : ICheck
|
||||||
{
|
{
|
||||||
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Settings, "Abnormal difficulty settings");
|
public abstract CheckMetadata Metadata { get; }
|
||||||
|
|
||||||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||||
{
|
{
|
||||||
@ -16,42 +16,17 @@ namespace osu.Game.Rulesets.Edit.Checks
|
|||||||
new IssueTemplateOutOfRange(this),
|
new IssueTemplateOutOfRange(this),
|
||||||
};
|
};
|
||||||
|
|
||||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
public abstract IEnumerable<Issue> Run(BeatmapVerifierContext context);
|
||||||
{
|
|
||||||
var diff = context.Beatmap.Difficulty;
|
|
||||||
string ruleset = context.Beatmap.BeatmapInfo.Ruleset.ShortName;
|
|
||||||
|
|
||||||
if (hasMoreThanOneDecimalPlace(diff.ApproachRate))
|
/// <summary>
|
||||||
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Approach rate", diff.ApproachRate);
|
/// If the setting is out of the boundaries set by the editor (0 - 10)
|
||||||
|
/// </summary>
|
||||||
if (isOutOfRange(diff.ApproachRate))
|
protected bool OutOfRange(float setting)
|
||||||
yield return new IssueTemplateOutOfRange(this).Create("Approach rate", diff.ApproachRate);
|
|
||||||
|
|
||||||
if (hasMoreThanOneDecimalPlace(diff.OverallDifficulty))
|
|
||||||
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Overall difficulty", diff.OverallDifficulty);
|
|
||||||
|
|
||||||
if (isOutOfRange(diff.OverallDifficulty))
|
|
||||||
yield return new IssueTemplateOutOfRange(this).Create("Overall difficulty", diff.OverallDifficulty);
|
|
||||||
|
|
||||||
if (hasMoreThanOneDecimalPlace(diff.CircleSize))
|
|
||||||
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Circle size", diff.CircleSize);
|
|
||||||
|
|
||||||
if (ruleset != "mania" && isOutOfRange(diff.CircleSize))
|
|
||||||
yield return new IssueTemplateOutOfRange(this).Create("Circle size", diff.CircleSize);
|
|
||||||
|
|
||||||
if (hasMoreThanOneDecimalPlace(diff.DrainRate))
|
|
||||||
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Drain rate", diff.DrainRate);
|
|
||||||
|
|
||||||
if (isOutOfRange(diff.DrainRate))
|
|
||||||
yield return new IssueTemplateOutOfRange(this).Create("Drain rate", diff.DrainRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool isOutOfRange(float setting)
|
|
||||||
{
|
{
|
||||||
return setting < 0f || setting > 10f;
|
return setting < 0f || setting > 10f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hasMoreThanOneDecimalPlace(float setting)
|
protected bool HasMoreThanOneDecimalPlace(float setting)
|
||||||
{
|
{
|
||||||
return float.Round(setting, 1) != setting;
|
return float.Round(setting, 1) != setting;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user