Skip to content

Commit

Permalink
Add test cases covering overlapping slider input expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Sep 5, 2023
1 parent 611933a commit 40d1196
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
54 changes: 54 additions & 0 deletions osu.Game.Rulesets.Osu.Tests/TestSceneLegacyHitPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,54 @@ public void TestAutopilotReducesHittableRange()
addClickActionAssert(0, ClickAction.Shake);
}

[Test]
public void TestInputDoesNotFallThroughOverlappingSliders()
{
const double time_first_slider = 1000;
const double time_second_slider = 1250;
Vector2 positionFirstSlider = new Vector2(100, 50);
Vector2 positionSecondSlider = new Vector2(100, 80);
var midpoint = (positionFirstSlider + positionSecondSlider) / 2;

var hitObjects = new List<OsuHitObject>
{
new Slider
{
StartTime = time_first_slider,
Position = positionFirstSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
},
new Slider
{
StartTime = time_second_slider,
Position = positionSecondSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};

performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_slider, Position = midpoint, Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_first_slider + 25, Position = midpoint, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_slider + 50, Position = midpoint },
});

addJudgementAssert(hitObjects[0], HitResult.Ok);
addJudgementOffsetAssert("first slider head", () => ((Slider)hitObjects[0]).HeadCircle, 0);
addJudgementAssert(hitObjects[1], HitResult.Miss);
// the slider head of the first slider prevents the second slider's head from being hit, so the judgement offset should be very late.
addJudgementOffsetAssert("second slider head", () => ((Slider)hitObjects[1]).HeadCircle, referenceHitWindows.WindowFor(HitResult.Meh));
addClickActionAssert(0, ClickAction.Hit);
}

private void addJudgementAssert(OsuHitObject hitObject, HitResult result)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judgement is {result}",
Expand All @@ -523,6 +571,12 @@ private void addJudgementOffsetAssert(OsuHitObject hitObject, double offset)
() => judgementResults.Single(r => r.HitObject == hitObject).TimeOffset, () => Is.EqualTo(offset).Within(50));
}

private void addJudgementOffsetAssert(string name, Func<OsuHitObject?> hitObject, double offset)
{
AddAssert($"{name} @ judged at {offset}",
() => judgementResults.Single(r => r.HitObject == hitObject()).TimeOffset, () => Is.EqualTo(offset).Within(50));
}

private void addClickActionAssert(int inputIndex, ClickAction action)
=> AddAssert($"input #{inputIndex} resulted in {action}", () => testPolicy.ClickActions[inputIndex], () => Is.EqualTo(action));

Expand Down
52 changes: 52 additions & 0 deletions osu.Game.Rulesets.Osu.Tests/TestSceneStartTimeOrderedHitPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,52 @@ public void TestHitSliderHeadBeforeHitCircle()
addJudgementAssert(hitObjects[1], HitResult.IgnoreHit);
}

[Test]
public void TestInputFallsThroughJudgedSliders()
{
const double time_first_slider = 1000;
const double time_second_slider = 1250;
Vector2 positionFirstSlider = new Vector2(100, 50);
Vector2 positionSecondSlider = new Vector2(100, 80);
var midpoint = (positionFirstSlider + positionSecondSlider) / 2;

var hitObjects = new List<OsuHitObject>
{
new TestSlider
{
StartTime = time_first_slider,
Position = positionFirstSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
},
new TestSlider
{
StartTime = time_second_slider,
Position = positionSecondSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};

performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_slider, Position = midpoint, Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_first_slider + 25, Position = midpoint, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_slider + 50, Position = midpoint },
});

addJudgementAssert("first slider head", () => ((Slider)hitObjects[0]).HeadCircle, HitResult.Great);
addJudgementOffsetAssert("first slider head", () => ((Slider)hitObjects[0]).HeadCircle, 0);
addJudgementAssert("second slider head", () => ((Slider)hitObjects[1]).HeadCircle, HitResult.Great);
addJudgementOffsetAssert("second slider head", () => ((Slider)hitObjects[1]).HeadCircle, -200);
}

private void addJudgementAssert(OsuHitObject hitObject, HitResult result)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judgement is {result}",
Expand All @@ -354,6 +400,12 @@ private void addJudgementOffsetAssert(OsuHitObject hitObject, double offset)
() => Precision.AlmostEquals(judgementResults.Single(r => r.HitObject == hitObject).TimeOffset, offset, 100));
}

private void addJudgementOffsetAssert(string name, Func<OsuHitObject> hitObject, double offset)
{
AddAssert($"{name} @ judged at {offset}",
() => judgementResults.Single(r => r.HitObject == hitObject()).TimeOffset, () => Is.EqualTo(offset).Within(50));
}

private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;

Expand Down

0 comments on commit 40d1196

Please sign in to comment.