1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 00:22:58 +08:00

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 testBeatmap = createRawBeatmap();
var noteValues = new List<double>(testBeatmap.HitObjects.OfType<HoldNote>().Count()); 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(); noteValues.Sort();
Assert.AreEqual(noteValues, new List<double> { 0.125, 0.250, 0.500, 1.000, 2.000 }); 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.Half)]
[TestCase(ManiaModHoldOff.BeatDivisors.Quarter)] [TestCase(ManiaModHoldOff.BeatDivisors.Quarter)]
[TestCase(ManiaModHoldOff.BeatDivisors.Eighth)] [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, 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. the mod produces the expected number of objects when the mod is applied.
@ -55,14 +59,19 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
// Calculate expected number of objects // Calculate expected number of objects
int expectedObjectCount = 0; int expectedObjectCount = 0;
double beatSnapValue = 1/(Math.Pow(2, (int)minBeatSnap)); 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 // Both notes and hold notes account for at least one object
expectedObjectCount++; expectedObjectCount++;
if (h.GetType() == typeof(HoldNote)) {
var noteValue = ManiaModHoldOff.getNoteValue((HoldNote)h, (ManiaBeatmap)rawBeatmap); if (h.GetType() == typeof(HoldNote))
if (noteValue >= beatSnapValue) { {
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 // Should generate an end note if it's longer than the minimum note value
expectedObjectCount++; expectedObjectCount++;
} }
@ -73,10 +82,12 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
} }
[Test] [Test]
public void TestDifficultyIncrease() { public void TestDifficultyIncrease()
{
// A lower minimum beat snap divisor should only make the map harder, never easier // A lower minimum beat snap divisor should only make the map harder, never easier
// (as more notes can be spawned) // (as more notes can be spawned)
var beatmaps = new ManiaBeatmap[] { var beatmaps = new ManiaBeatmap[]
{
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Whole), createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Whole),
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Half), createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Half),
createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Quarter), createModdedBeatmap(ManiaModHoldOff.BeatDivisors.Quarter),
@ -85,18 +96,22 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
}; };
var mapDifficulties = new double[beatmaps.Length]; 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 workingBeatmap = new TestWorkingBeatmap(beatmaps[i]);
var difficultyCalculator = new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, workingBeatmap); var difficultyCalculator = new ManiaDifficultyCalculator(new ManiaRuleset().RulesetInfo, workingBeatmap);
mapDifficulties[i] = difficultyCalculator.Calculate().StarRating; mapDifficulties[i] = difficultyCalculator.Calculate().StarRating;
if (i > 0) {
Assert.LessOrEqual(mapDifficulties[i-1], mapDifficulties[i]); if (i > 0)
Assert.LessOrEqual(beatmaps[i-1].HitObjects.Count, beatmaps[i].HitObjects.Count); {
Assert.LessOrEqual(mapDifficulties[i - 1], mapDifficulties[i]);
Assert.LessOrEqual(beatmaps[i - 1].HitObjects.Count, beatmaps[i].HitObjects.Count);
} }
} }
} }
private static ManiaBeatmap createModdedBeatmap(ManiaModHoldOff.BeatDivisors minBeatSnap=ManiaModHoldOff.BeatDivisors.Whole) private static ManiaBeatmap createModdedBeatmap(ManiaModHoldOff.BeatDivisors minBeatSnap = ManiaModHoldOff.BeatDivisors.Whole)
{ {
var beatmap = createRawBeatmap(); var beatmap = createRawBeatmap();
var holdOffMod = new ManiaModHoldOff(); var holdOffMod = new ManiaModHoldOff();
@ -110,17 +125,18 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods
return (ManiaBeatmap)beatmap; return (ManiaBeatmap)beatmap;
} }
private static ManiaBeatmap createRawBeatmap() private static ManiaBeatmap createRawBeatmap()
{ {
var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 }); var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 });
beatmap.ControlPointInfo.Add(0.0, new TimingControlPoint { BeatLength = 1000 } ); // Set BPM to 60 beatmap.ControlPointInfo.Add(0.0, new TimingControlPoint { BeatLength = 1000 }); // Set BPM to 60
// Add test hit objects // Add test hit objects
beatmap.HitObjects.Add(new Note { StartTime = 4000 }); beatmap.HitObjects.Add(new Note { StartTime = 4000 });
beatmap.HitObjects.Add(new Note { StartTime = 4500 }); beatmap.HitObjects.Add(new Note { StartTime = 4500 });
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 125 }); // 1/8 note beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 125 }); // 1/8 note
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 250 }); // 1/4 note beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 250 }); // 1/4 note
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 500 }); // 1/2 note beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 500 }); // 1/2 note
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 1000 }); // 1/1 note beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 1000 }); // 1/1 note
beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 2000 }); // 2/1 note beatmap.HitObjects.Add(new HoldNote { StartTime = 0, EndTime = 2000 }); // 2/1 note

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 // 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) 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(); 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; double bpmAtNoteTime = beatmap.ControlPointInfo.TimingPointAt(holdNote.StartTime).BPM;
return (60 * holdNote.Duration) / (1000 * bpmAtNoteTime); return (60 * holdNote.Duration) / (1000 * bpmAtNoteTime);