diff --git a/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs b/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs new file mode 100644 index 0000000000..fca39f86ec --- /dev/null +++ b/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs @@ -0,0 +1,47 @@ +// 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.Extensions; + +namespace osu.Game.Tests.Extensions +{ + [TestFixture] + public class NumberFormattingExtensionsTest + { + [TestCase(-1, false, 0, ExpectedResult = "-1")] + [TestCase(0, false, 0, ExpectedResult = "0")] + [TestCase(1, false, 0, ExpectedResult = "1")] + [TestCase(500, false, 10, ExpectedResult = "500")] + [TestCase(-1, true, 0, ExpectedResult = "-1%")] + [TestCase(0, true, 0, ExpectedResult = "0%")] + [TestCase(1, true, 0, ExpectedResult = "1%")] + [TestCase(50, true, 0, ExpectedResult = "50%")] + public string TestInteger(int input, bool percent, int decimalDigits) + { + return input.ToStandardFormattedString(decimalDigits, percent); + } + + [TestCase(-1, false, 0, ExpectedResult = "-1")] + [TestCase(-1e-6, false, 0, ExpectedResult = "0")] + [TestCase(-1e-6, false, 6, ExpectedResult = "-0.000001")] + [TestCase(0, false, 10, ExpectedResult = "0")] + [TestCase(0, false, 0, ExpectedResult = "0")] + [TestCase(double.NegativeZero, false, 0, ExpectedResult = "0")] + [TestCase(1e-6, false, 0, ExpectedResult = "0")] + [TestCase(1e-6, false, 6, ExpectedResult = "0.000001")] + [TestCase(1, false, 0, ExpectedResult = "1")] + [TestCase(1.528, false, 2, ExpectedResult = "1.53")] + [TestCase(500, false, 10, ExpectedResult = "500")] + [TestCase(-0.1, true, 0, ExpectedResult = "-10%")] + [TestCase(0, true, 0, ExpectedResult = "0%")] + [TestCase(0.4, true, 0, ExpectedResult = "40%")] + [TestCase(0.48333, true, 2, ExpectedResult = "48%")] + [TestCase(0.48333, true, 4, ExpectedResult = "48.33%")] + [TestCase(1, true, 0, ExpectedResult = "100%")] + public string TestDouble(double input, bool percent, int decimalDigits) + { + return input.ToStandardFormattedString(decimalDigits, percent); + } + } +} diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneHitEventTimingDistributionGraph.cs b/osu.Game.Tests/Visual/Ranking/TestSceneHitEventTimingDistributionGraph.cs index 760210c370..bb4b785db0 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneHitEventTimingDistributionGraph.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneHitEventTimingDistributionGraph.cs @@ -168,6 +168,19 @@ namespace osu.Game.Tests.Visual.Ranking }; }); + public static List CreateHitEvents(double offset = 0, int count = 50) + { + var hitEvents = new List(); + + for (int i = 0; i < count; i++) + { + for (int j = 0; j < count; j++) + hitEvents.Add(new HitEvent(offset, 1.0, HitResult.Perfect, placeholder_object, placeholder_object, null)); + } + + return hitEvents; + } + public static List CreateDistributedHitEvents(double centre = 0, double range = 25) { var hitEvents = new List(); diff --git a/osu.Game.Tests/Visual/Settings/TestSceneAudioOffsetAdjustControl.cs b/osu.Game.Tests/Visual/Settings/TestSceneAudioOffsetAdjustControl.cs index 85cde966b1..2fc5378ba1 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneAudioOffsetAdjustControl.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneAudioOffsetAdjustControl.cs @@ -1,11 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Configuration; using osu.Game.Overlays.Settings.Sections.Audio; @@ -70,16 +73,54 @@ namespace osu.Game.Tests.Visual.Settings AddStep("clear history", () => tracker.ClearHistory()); } + [Test] + public void TestRounding() + { + AddStep("set new score", () => statics.SetValue(Static.LastLocalUserScore, new ScoreInfo + { + HitEvents = TestSceneHitEventTimingDistributionGraph.CreateHitEvents(0.6), + BeatmapInfo = Beatmap.Value.BeatmapInfo, + })); + + checkButtonEnabled(); + AddStep("click button", () => adjustControl.ChildrenOfType