Rename function and make public again for test usage

This commit is contained in:
Dean Herbert 2022-01-29 14:05:23 +09:00
parent c75ffe9b07
commit 035a84e75c
2 changed files with 37 additions and 21 deletions

View File

@ -32,9 +32,12 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
{
var testBeatmap = createRawBeatmap();
var noteValues = new List<double>(testBeatmap.HitObjects.OfType<HoldNote>().Count());
foreach (HoldNote h in testBeatmap.HitObjects.OfType<HoldNote>()) {
noteValues.Add(ManiaModHoldOff.getNoteValue(h, (ManiaBeatmap)testBeatmap));
foreach (HoldNote h in testBeatmap.HitObjects.OfType<HoldNote>())
{
noteValues.Add(ManiaModHoldOff.GetNoteDurationInBeatLength(h, (ManiaBeatmap)testBeatmap));
}
noteValues.Sort();
Assert.AreEqual(noteValues, new List<double> { 0.125, 0.250, 0.500, 1.000, 2.000 });
}
@ -43,7 +46,8 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
[TestCase(ManiaModHoldOff.BeatDivisors.Half)]
[TestCase(ManiaModHoldOff.BeatDivisors.Quarter)]
[TestCase(ManiaModHoldOff.BeatDivisors.Eighth)]
public void TestCorrectObjectCount(ManiaModHoldOff.BeatDivisors minBeatSnap) {
public void TestCorrectObjectCount(ManiaModHoldOff.BeatDivisors minBeatSnap)
{
/*
This test is to ensure that, given that end notes are enabled,
the mod produces the expected number of objects when the mod is applied.
@ -57,12 +61,17 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
int expectedObjectCount = 0;
double beatSnapValue = 1 / (Math.Pow(2, (int)minBeatSnap));
foreach (ManiaHitObject h in rawBeatmap.HitObjects) {
foreach (ManiaHitObject h in rawBeatmap.HitObjects)
{
// Both notes and hold notes account for at least one object
expectedObjectCount++;
if (h.GetType() == typeof(HoldNote)) {
var noteValue = ManiaModHoldOff.getNoteValue((HoldNote)h, (ManiaBeatmap)rawBeatmap);
if (noteValue >= beatSnapValue) {
if (h.GetType() == typeof(HoldNote))
{
var noteValue = ManiaModHoldOff.GetNoteDurationInBeatLength((HoldNote)h, (ManiaBeatmap)rawBeatmap);
if (noteValue >= beatSnapValue)
{
// Should generate an end note if it's longer than the minimum note value
expectedObjectCount++;
}
@ -73,10 +82,12 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
}
[Test]
public void TestDifficultyIncrease() {
public void TestDifficultyIncrease()
{
// A lower minimum beat snap divisor should only make the map harder, never easier
// (as more notes can be spawned)
var beatmaps = new ManiaBeatmap[] {
var beatmaps = new ManiaBeatmap[]
{
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Whole),
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Half),
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Quarter),
@ -85,11 +96,15 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
};
var mapDifficulties = new double[beatmaps.Length];
for (int i = 0; i < mapDifficulties.Length; i++) {
for (int i = 0; i < mapDifficulties.Length; i++)
{
var workingBeatmap = new TestWorkingBeatmap(beatmaps[i]);
var difficultyCalculator = new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, workingBeatmap);
mapDifficulties[i] = difficultyCalculator.Calculate().StarRating;
if (i > 0) {
if (i > 0)
{
Assert.LessOrEqual(mapDifficulties[i - 1], mapDifficulties[i]);
Assert.LessOrEqual(beatmaps[i - 1].HitObjects.Count, beatmaps[i].HitObjects.Count);
}
@ -110,6 +125,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
return (ManiaBeatmap)beatmap;
}
private static ManiaBeatmap createRawBeatmap()
{
var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 });

View File

@ -56,7 +56,7 @@ namespace osu.Game.Rulesets.Mania.Mods
});
// Don't add an end note if the duration is shorter than some threshold, or end notes are disabled
double noteValue = getNoteValue(h, maniaBeatmap); // 1/1, 1/2, 1/4, etc.
double noteValue = GetNoteDurationInBeatLength(h, maniaBeatmap); // 1/1, 1/2, 1/4, etc.
if (AddEndNotes.Value && noteValue >= beatSnap)
{
@ -72,7 +72,7 @@ namespace osu.Game.Rulesets.Mania.Mods
maniaBeatmap.HitObjects = maniaBeatmap.HitObjects.OfType<Note>().Concat(newObjects).OrderBy(h => h.StartTime).ToList();
}
private static double getNoteValue(HoldNote holdNote, ManiaBeatmap beatmap)
public static double GetNoteDurationInBeatLength(HoldNote holdNote, ManiaBeatmap beatmap)
{
double bpmAtNoteTime = beatmap.ControlPointInfo.TimingPointAt(holdNote.StartTime).BPM;
return (60 * holdNote.Duration) / (1000 * bpmAtNoteTime);