mirror of
https://github.com/osukey/osukey.git
synced 2025-05-25 15:37:24 +09:00
Add test cases for HP draining not applied before a break and after it
This commit is contained in:
parent
7fab07670e
commit
c902ba4086
@ -1,13 +1,15 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Timing;
|
||||||
using osu.Game.Rulesets.Judgements;
|
using osu.Game.Rulesets.Judgements;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
@ -18,7 +20,6 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
[HeadlessTest]
|
[HeadlessTest]
|
||||||
public class TestSceneDrainingHealthProcessor : OsuTestScene
|
public class TestSceneDrainingHealthProcessor : OsuTestScene
|
||||||
{
|
{
|
||||||
private Bindable<bool> breakTime;
|
|
||||||
private HealthProcessor processor;
|
private HealthProcessor processor;
|
||||||
private ManualClock clock;
|
private ManualClock clock;
|
||||||
|
|
||||||
@ -41,6 +42,55 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
assertHealthEqualTo(1);
|
assertHealthEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestHealthNotDrainedBeforeBreak()
|
||||||
|
{
|
||||||
|
createProcessor(createBeatmap(0, 2000,
|
||||||
|
new BreakPeriod(400, 600), new BreakPeriod(1200, 1400)));
|
||||||
|
|
||||||
|
setTime(300);
|
||||||
|
setHealth(1);
|
||||||
|
|
||||||
|
setTime(400);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
|
||||||
|
setTime(1100);
|
||||||
|
setHealth(1);
|
||||||
|
|
||||||
|
setTime(1200);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestHealthNotDrainedDuringBreak()
|
||||||
|
{
|
||||||
|
createProcessor(createBeatmap(0, 2000, new BreakPeriod(0, 1200)));
|
||||||
|
|
||||||
|
setTime(700);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
setTime(900);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestHealthNotDrainedAfterBreak()
|
||||||
|
{
|
||||||
|
createProcessor(createBeatmap(0, 2000,
|
||||||
|
new BreakPeriod(400, 600), new BreakPeriod(1200, 1400)));
|
||||||
|
|
||||||
|
setTime(600);
|
||||||
|
setHealth(1);
|
||||||
|
|
||||||
|
setTime(700);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
|
||||||
|
setTime(1400);
|
||||||
|
setHealth(1);
|
||||||
|
|
||||||
|
setTime(1500);
|
||||||
|
assertHealthEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestHealthNotDrainedAfterGameplayEnd()
|
public void TestHealthNotDrainedAfterGameplayEnd()
|
||||||
{
|
{
|
||||||
@ -54,18 +104,6 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
assertHealthEqualTo(1);
|
assertHealthEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestHealthNotDrainedDuringBreak()
|
|
||||||
{
|
|
||||||
createProcessor(createBeatmap(0, 2000));
|
|
||||||
setBreak(true);
|
|
||||||
|
|
||||||
setTime(700);
|
|
||||||
assertHealthEqualTo(1);
|
|
||||||
setTime(900);
|
|
||||||
assertHealthEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestHealthDrainedDuringGameplay()
|
public void TestHealthDrainedDuringGameplay()
|
||||||
{
|
{
|
||||||
@ -112,30 +150,39 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
assertHealthNotEqualTo(1);
|
assertHealthNotEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Beatmap createBeatmap(double startTime, double endTime)
|
private Beatmap createBeatmap(double startTime, double endTime, params BreakPeriod[] breaks)
|
||||||
{
|
{
|
||||||
var beatmap = new Beatmap
|
var beatmap = new Beatmap
|
||||||
{
|
{
|
||||||
BeatmapInfo = { BaseDifficulty = { DrainRate = 5 } },
|
BeatmapInfo = { BaseDifficulty = { DrainRate = 5 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (double time = startTime; time <= endTime; time += 100)
|
double time = startTime;
|
||||||
|
|
||||||
|
while (time <= endTime)
|
||||||
|
{
|
||||||
beatmap.HitObjects.Add(new JudgeableHitObject { StartTime = time });
|
beatmap.HitObjects.Add(new JudgeableHitObject { StartTime = time });
|
||||||
|
|
||||||
|
// leave a 100ms gap between the start and end of a break period.
|
||||||
|
time += (getCurrentBreak(breaks, time)?.Duration ?? 0) + 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
beatmap.Breaks.AddRange(breaks);
|
||||||
|
|
||||||
|
static BreakPeriod getCurrentBreak(IEnumerable<BreakPeriod> breaks, double time) =>
|
||||||
|
breaks?.FirstOrDefault(b => time >= b.StartTime && time <= b.EndTime);
|
||||||
|
|
||||||
return beatmap;
|
return beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProcessor(Beatmap beatmap) => AddStep("create processor", () =>
|
private void createProcessor(Beatmap beatmap) => AddStep("create processor", () =>
|
||||||
{
|
{
|
||||||
breakTime = new Bindable<bool>();
|
|
||||||
|
|
||||||
Child = processor = new DrainingHealthProcessor(beatmap.HitObjects[0].StartTime).With(d =>
|
Child = processor = new DrainingHealthProcessor(beatmap.HitObjects[0].StartTime).With(d =>
|
||||||
{
|
{
|
||||||
d.RelativeSizeAxes = Axes.Both;
|
d.RelativeSizeAxes = Axes.Both;
|
||||||
d.Clock = new FramedClock(clock = new ManualClock());
|
d.Clock = new FramedClock(clock = new ManualClock());
|
||||||
});
|
});
|
||||||
|
|
||||||
processor.IsBreakTime.BindTo(breakTime);
|
|
||||||
processor.ApplyBeatmap(beatmap);
|
processor.ApplyBeatmap(beatmap);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -143,8 +190,6 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
|
|
||||||
private void setHealth(double health) => AddStep($"set health = {health}", () => processor.Health.Value = health);
|
private void setHealth(double health) => AddStep($"set health = {health}", () => processor.Health.Value = health);
|
||||||
|
|
||||||
private void setBreak(bool enabled) => AddStep($"{(enabled ? "enable" : "disable")} break", () => breakTime.Value = enabled);
|
|
||||||
|
|
||||||
private void assertHealthEqualTo(double value)
|
private void assertHealthEqualTo(double value)
|
||||||
=> AddAssert($"health = {value}", () => Precision.AlmostEquals(value, processor.Health.Value, 0.0001f));
|
=> AddAssert($"health = {value}", () => Precision.AlmostEquals(value, processor.Health.Value, 0.0001f));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user