|
| 1 | +// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. |
| 2 | +// See the LICENCE file in the repository root for full licence text. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using NUnit.Framework; |
| 6 | +using osu.Game.Beatmaps; |
| 7 | +using osu.Game.Rulesets.Catch.Beatmaps; |
| 8 | +using osu.Game.Rulesets.Catch.Objects; |
| 9 | + |
| 10 | +namespace osu.Game.Rulesets.Catch.Tests |
| 11 | +{ |
| 12 | + [TestFixture] |
| 13 | + public class CatchBeatmapProcessorTest |
| 14 | + { |
| 15 | + [Test] |
| 16 | + public void TestHardRockOffsetDoublePrecision() |
| 17 | + { |
| 18 | + // Setup a beatmap with two fruits that will trigger the logic difference. |
| 19 | + // We need a time difference that has a fractional part. |
| 20 | + // And we need HardRock enabled. |
| 21 | + |
| 22 | + // lastPosition = 100, lastStartTime = 1000. |
| 23 | + // offsetPosition = 133.2, startTime = 1100.5. |
| 24 | + |
| 25 | + // positionDiff = 33.2. |
| 26 | + // timeDiff (int) = 100. |
| 27 | + // timeDiff (double) = 100.5. |
| 28 | + |
| 29 | + // positionDiff < timeDiff / 3 |
| 30 | + // 33.2 < 33 (False) |
| 31 | + // 33.2 < 33.5 (True) |
| 32 | + |
| 33 | + var beatmap = new Beatmap<CatchHitObject> |
| 34 | + { |
| 35 | + HitObjects = new List<CatchHitObject> |
| 36 | + { |
| 37 | + new Fruit { StartTime = 1000, X = 100 }, |
| 38 | + new Fruit { StartTime = 1000 + 100.5, X = 100 + 33.2f } |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + var processor = new CatchBeatmapProcessor(beatmap) |
| 43 | + { |
| 44 | + HardRockOffsets = true |
| 45 | + }; |
| 46 | + |
| 47 | + processor.ApplyPositionOffsets(beatmap); |
| 48 | + |
| 49 | + var secondObj = beatmap.HitObjects[1]; |
| 50 | + |
| 51 | + // If bug is present (int truncation), condition is false, XOffset is 0. |
| 52 | + // If fixed (double), condition is true, XOffset is 33.2 (approx). |
| 53 | + |
| 54 | + Assert.That(secondObj.XOffset, Is.Not.EqualTo(0).Within(0.001)); |
| 55 | + Assert.That(secondObj.XOffset, Is.EqualTo(33.2f).Within(0.001)); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments