From 265a56bede4c66e0632e6a6dad6cf6ed0d7bedd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 16 Jan 2024 19:40:01 +0100 Subject: [PATCH] Add basic test coverage of taiko health processor --- .../TaikoHealthProcessorTest.cs | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs diff --git a/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs b/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs new file mode 100644 index 0000000000..51dcf1ba91 --- /dev/null +++ b/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs @@ -0,0 +1,110 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.Taiko.Beatmaps; +using osu.Game.Rulesets.Taiko.Judgements; +using osu.Game.Rulesets.Taiko.Objects; +using osu.Game.Rulesets.Taiko.Scoring; + +namespace osu.Game.Rulesets.Taiko.Tests +{ + [TestFixture] + public class TaikoHealthProcessorTest + { + [Test] + public void TestHitsOnlyGreat() + { + var beatmap = new TaikoBeatmap + { + HitObjects = + { + new Hit(), + new Hit { StartTime = 1000 }, + new Hit { StartTime = 2000 }, + new Hit { StartTime = 3000 }, + new Hit { StartTime = 4000 }, + } + }; + + var healthProcessor = new TaikoHealthProcessor(); + healthProcessor.ApplyBeatmap(beatmap); + + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new TaikoJudgement()) { Type = HitResult.Great }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], new TaikoJudgement()) { Type = HitResult.Great }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], new TaikoJudgement()) { Type = HitResult.Great }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], new TaikoJudgement()) { Type = HitResult.Great }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[4], new TaikoJudgement()) { Type = HitResult.Great }); + + Assert.Multiple(() => + { + Assert.That(healthProcessor.Health.Value, Is.EqualTo(1)); + Assert.That(healthProcessor.HasFailed, Is.False); + }); + } + + [Test] + public void TestHitsAboveThreshold() + { + var beatmap = new TaikoBeatmap + { + HitObjects = + { + new Hit(), + new Hit { StartTime = 1000 }, + new Hit { StartTime = 2000 }, + new Hit { StartTime = 3000 }, + new Hit { StartTime = 4000 }, + } + }; + + var healthProcessor = new TaikoHealthProcessor(); + healthProcessor.ApplyBeatmap(beatmap); + + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new TaikoJudgement()) { Type = HitResult.Great }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[4], new TaikoJudgement()) { Type = HitResult.Miss }); + + Assert.Multiple(() => + { + Assert.That(healthProcessor.Health.Value, Is.GreaterThan(0.5)); + Assert.That(healthProcessor.HasFailed, Is.False); + }); + } + + [Test] + public void TestHitsBelowThreshold() + { + var beatmap = new TaikoBeatmap + { + HitObjects = + { + new Hit(), + new Hit { StartTime = 1000 }, + new Hit { StartTime = 2000 }, + new Hit { StartTime = 3000 }, + new Hit { StartTime = 4000 }, + } + }; + + var healthProcessor = new TaikoHealthProcessor(); + healthProcessor.ApplyBeatmap(beatmap); + + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new TaikoJudgement()) { Type = HitResult.Miss }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], new TaikoJudgement()) { Type = HitResult.Ok }); + healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[4], new TaikoJudgement()) { Type = HitResult.Miss }); + + Assert.Multiple(() => + { + Assert.That(healthProcessor.Health.Value, Is.LessThan(0.5)); + Assert.That(healthProcessor.HasFailed, Is.True); + }); + } + } +}