Refactor test to support custom hitobjects

This commit is contained in:
smoogipoo
2020-03-30 15:11:15 +09:00
parent 3f8fbebbb4
commit b9277165f7

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -23,8 +24,6 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
public class TestSceneNoteLock : RateAdjustedBeatmapTestScene public class TestSceneNoteLock : RateAdjustedBeatmapTestScene
{ {
private const double time_first_circle = 1500;
private const double time_second_circle = 1600;
private const double early_miss_window = 1000; // time after -1000 to -500 is considered a miss private const double early_miss_window = 1000; // time after -1000 to -500 is considered a miss
private const double late_miss_window = 500; // time after +500 is considered a miss private const double late_miss_window = 500; // time after +500 is considered a miss
@ -37,82 +36,10 @@ namespace osu.Game.Rulesets.Osu.Tests
[Test] [Test]
public void TestClickSecondCircleBeforeFirstCircleTime() public void TestClickSecondCircleBeforeFirstCircleTime()
{ {
performTest(new List<ReplayFrame> const double time_first_circle = 1500;
{ const double time_second_circle = 1600;
new OsuReplayFrame { Time = time_first_circle - 100, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(HitResult.Miss, HitResult.Miss); var hitObjects = new List<OsuHitObject>
addJudgementOffsetAssert(late_miss_window);
}
/// <summary>
/// Tests clicking the second circle at the first hitobject's start time, while the first hitobject HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAtFirstCircleTime()
{
performTest(new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(HitResult.Miss, HitResult.Great);
addJudgementOffsetAssert(0);
}
/// <summary>
/// Tests clicking the second circle after the first hitobject's start time, while the first hitobject HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAfterFirstCircleTime()
{
performTest(new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle + 100, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(HitResult.Miss, HitResult.Great);
addJudgementOffsetAssert(100);
}
/// <summary>
/// Tests clicking the second circle before the first hitobject's start time, while the first hitobject HAS been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTimeWithFirstCircleJudged()
{
performTest(new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 200, Position = position_first_circle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_circle - 100, Position = position_second_circle, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(HitResult.Great, HitResult.Great);
}
private void addJudgementAssert(HitResult firstCircle, HitResult secondCircle)
{
AddAssert($"first circle judgement is {firstCircle}", () => judgementResults.Single(r => r.HitObject.StartTime == time_first_circle).Type == firstCircle);
AddAssert($"second circle judgement is {secondCircle}", () => judgementResults.Single(r => r.HitObject.StartTime == time_second_circle).Type == secondCircle);
}
private void addJudgementOffsetAssert(double offset)
{
AddAssert($"first circle judged at {offset}", () => Precision.AlmostEquals(judgementResults.Single(r => r.HitObject.StartTime == time_first_circle).TimeOffset, offset, 100));
}
private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
private void performTest(List<ReplayFrame> frames)
{
AddStep("load player", () =>
{
Beatmap.Value = CreateWorkingBeatmap(new Beatmap<OsuHitObject>
{
HitObjects =
{ {
new TestHitCircle new TestHitCircle
{ {
@ -124,7 +51,142 @@ namespace osu.Game.Rulesets.Osu.Tests
StartTime = time_second_circle, StartTime = time_second_circle,
Position = position_second_circle Position = position_second_circle
} }
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 100, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Miss);
addJudgementOffsetAssert(hitObjects[0], late_miss_window);
}
/// <summary>
/// Tests clicking the second circle at the first hitobject's start time, while the first hitobject HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAtFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = position_first_circle
}, },
new TestHitCircle
{
StartTime = time_second_circle,
Position = position_second_circle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 0);
}
/// <summary>
/// Tests clicking the second circle after the first hitobject's start time, while the first hitobject HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAfterFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = position_first_circle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = position_second_circle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle + 100, Position = position_second_circle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 100);
}
/// <summary>
/// Tests clicking the second circle before the first hitobject's start time, while the first hitobject HAS been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTimeWithFirstCircleJudged()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = position_first_circle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = position_second_circle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 200, Position = position_first_circle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_circle - 100, Position = position_second_circle, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], -200); // time_first_circle - 200
addJudgementOffsetAssert(hitObjects[0], -200); // time_second_circle - first_circle_time - 100
}
private void addJudgementAssert(OsuHitObject hitObject, HitResult result)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judgement is {result}",
() => judgementResults.Single(r => r.HitObject == hitObject).Type == result);
}
private void addJudgementOffsetAssert(OsuHitObject hitObject, double offset)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judged at {offset}",
() => Precision.AlmostEquals(judgementResults.Single(r => r.HitObject == hitObject).TimeOffset, offset, 100));
}
private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
private void performTest(List<OsuHitObject> hitObjects, List<ReplayFrame> frames)
{
AddStep("load player", () =>
{
Beatmap.Value = CreateWorkingBeatmap(new Beatmap<OsuHitObject>
{
HitObjects = hitObjects,
BeatmapInfo = BeatmapInfo =
{ {
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 }, BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },