1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:17:25 +08:00
osu-lazer/osu.Game.Tests/Gameplay/TestSceneDrainingHealthProcessor.cs

205 lines
6.2 KiB
C#
Raw Normal View History

2019-12-26 16:48:46 +08:00
// 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 NUnit.Framework;
using osu.Framework.Graphics;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2019-12-26 16:48:46 +08:00
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
2019-12-26 16:48:46 +08:00
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Gameplay
{
[HeadlessTest]
public class TestSceneDrainingHealthProcessor : OsuTestScene
{
private HealthProcessor processor;
private ManualClock clock;
[Test]
public void TestInitialHealthStartsAtOne()
{
createProcessor(createBeatmap(1000, 2000));
assertHealthEqualTo(1);
}
[Test]
public void TestHealthNotDrainedBeforeGameplayStart()
{
createProcessor(createBeatmap(1000, 2000));
setTime(100);
assertHealthEqualTo(1);
setTime(900);
assertHealthEqualTo(1);
}
[Test]
2020-05-12 01:03:13 +08:00
public void TestHealthDrainBetweenBreakAndObjects()
2019-12-26 16:48:46 +08:00
{
2020-05-12 01:03:13 +08:00
createProcessor(createBeatmap(0, 2000, new BreakPeriod(325, 375)));
2019-12-26 16:48:46 +08:00
2020-05-12 01:03:13 +08:00
// 275 300 325 350 375 400 425
// hitobjects o o
// break [-------------]
// no drain [---------------------------]
setTime(285);
setHealth(1);
2020-05-12 01:03:13 +08:00
setTime(295);
assertHealthNotEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(305);
setHealth(1);
2020-05-12 01:03:13 +08:00
setTime(315);
2019-12-26 16:48:46 +08:00
assertHealthEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(365);
2019-12-26 16:48:46 +08:00
assertHealthEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(395);
2019-12-26 16:48:46 +08:00
assertHealthEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(425);
assertHealthNotEqualTo(1);
2019-12-26 16:48:46 +08:00
}
[Test]
2020-05-12 01:03:13 +08:00
public void TestHealthDrainDuringMaximalBreak()
{
2020-05-12 01:03:13 +08:00
createProcessor(createBeatmap(0, 2000, new BreakPeriod(300, 400)));
// 275 300 325 350 375 400 425
// hitobjects o o
// break [---------------------------]
// no drain [---------------------------]
2020-05-12 01:03:13 +08:00
setTime(285);
setHealth(1);
2020-05-12 01:03:13 +08:00
setTime(295);
assertHealthNotEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(305);
setHealth(1);
2020-05-12 01:03:13 +08:00
setTime(395);
assertHealthEqualTo(1);
2020-05-12 01:03:13 +08:00
setTime(425);
assertHealthNotEqualTo(1);
}
[Test]
public void TestHealthNotDrainedAfterGameplayEnd()
{
createProcessor(createBeatmap(1000, 2000));
setTime(2001); // After the hitobjects
setHealth(1); // Reset the current health for assertions to take place
setTime(2100);
assertHealthEqualTo(1);
setTime(3000);
assertHealthEqualTo(1);
}
2019-12-26 16:48:46 +08:00
[Test]
public void TestHealthDrainedDuringGameplay()
{
createProcessor(createBeatmap(0, 1000));
setTime(500);
assertHealthNotEqualTo(1);
}
2019-12-27 15:55:46 +08:00
[Test]
public void TestHealthGainedAfterRewind()
{
createProcessor(createBeatmap(0, 1000));
setTime(500);
setTime(0);
assertHealthEqualTo(1);
}
2019-12-26 16:48:46 +08:00
[Test]
public void TestHealthGainedOnHit()
{
Beatmap beatmap = createBeatmap(0, 1000);
createProcessor(beatmap);
setTime(10); // Decrease health slightly
assertHealthNotEqualTo(1);
AddStep("apply hit result", () => processor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new Judgement()) { Type = HitResult.Perfect }));
assertHealthEqualTo(1);
}
[Test]
public void TestHealthRemovedOnRevert()
{
var beatmap = createBeatmap(0, 1000);
JudgementResult result = null;
createProcessor(beatmap);
setTime(10); // Decrease health slightly
AddStep("apply hit result", () => processor.ApplyResult(result = new JudgementResult(beatmap.HitObjects[0], new Judgement()) { Type = HitResult.Perfect }));
AddStep("revert hit result", () => processor.RevertResult(result));
assertHealthNotEqualTo(1);
}
private Beatmap createBeatmap(double startTime, double endTime, params BreakPeriod[] breaks)
2019-12-26 16:48:46 +08:00
{
var beatmap = new Beatmap
{
2020-05-12 01:03:13 +08:00
BeatmapInfo = { BaseDifficulty = { DrainRate = 10 } },
2019-12-26 16:48:46 +08:00
};
2020-05-12 01:03:13 +08:00
for (double time = startTime; time <= endTime; time += 100)
{
2019-12-26 16:48:46 +08:00
beatmap.HitObjects.Add(new JudgeableHitObject { StartTime = time });
}
beatmap.Breaks.AddRange(breaks);
2019-12-26 16:48:46 +08:00
return beatmap;
}
private void createProcessor(Beatmap beatmap) => AddStep("create processor", () =>
{
Child = processor = new DrainingHealthProcessor(beatmap.HitObjects[0].StartTime).With(d =>
{
d.RelativeSizeAxes = Axes.Both;
d.Clock = new FramedClock(clock = new ManualClock());
});
processor.ApplyBeatmap(beatmap);
});
private void setTime(double time) => AddStep($"set time = {time}", () => clock.CurrentTime = time);
private void setHealth(double health) => AddStep($"set health = {health}", () => processor.Health.Value = health);
private void assertHealthEqualTo(double value)
=> AddAssert($"health = {value}", () => Precision.AlmostEquals(value, processor.Health.Value, 0.0001f));
private void assertHealthNotEqualTo(double value)
=> AddAssert($"health != {value}", () => !Precision.AlmostEquals(value, processor.Health.Value, 0.0001f));
private class JudgeableHitObject : HitObject
{
public override Judgement CreateJudgement() => new Judgement();
protected override HitWindows CreateHitWindows() => new HitWindows();
2019-12-26 16:48:46 +08:00
}
}
}