From c4e707b38e33d2f1edaa21bdd43eb601c7f59d63 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 21:47:01 +0900 Subject: [PATCH 1/6] Add time-tag assert to test time-tag comparsion. --- .../Asserts/TimeTagAssert.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Asserts/TimeTagAssert.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Asserts/TimeTagAssert.cs b/osu.Game.Rulesets.Karaoke.Tests/Asserts/TimeTagAssert.cs new file mode 100644 index 000000000..3dc5614bf --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Asserts/TimeTagAssert.cs @@ -0,0 +1,25 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using NUnit.Framework; +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Tests.Asserts +{ + public class TimeTagAssert : Assert + { + public static void AreEqual(IReadOnlyList expect, IReadOnlyList actually) + { + AreEqual(expect?.Count, actually?.Count); + if (expect == null || actually == null) + return; + + for (int i = 0; i < expect.Count; i++) + { + AreEqual(expect[i].Index, actually[i].Index); + AreEqual(expect[i].Time, actually[i].Time); + } + } + } +} From 9dcbaa36aa8eec51fd4648c0651b5c836c7823b5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 21:47:46 +0900 Subject: [PATCH 2/6] should throw exception if actual tag format are not right. --- .../Helper/TestCaseTagHelper.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs index eaca9c3ff..f3a168611 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using System.Text.RegularExpressions; using osu.Framework.Graphics.Sprites; @@ -26,7 +27,7 @@ public static RubyTag ParseRubyTag(string str) var regex = new Regex("(?[-0-9]+),(?[-0-9]+)]:(?.*$)"); var result = regex.Match(str); if (!result.Success) - return new RubyTag(); + throw new ArgumentException(nameof(str)); var startIndex = int.Parse(result.Groups["start"]?.Value); var endIndex = int.Parse(result.Groups["end"]?.Value); @@ -56,7 +57,7 @@ public static RomajiTag ParseRomajiTag(string str) var regex = new Regex("(?[-0-9]+),(?[-0-9]+)]:(?.*$)"); var result = regex.Match(str); if (!result.Success) - return new RomajiTag(); + throw new ArgumentException(nameof(str)); var startIndex = int.Parse(result.Groups["start"]?.Value); var endIndex = int.Parse(result.Groups["end"]?.Value); @@ -86,7 +87,7 @@ public static TimeTag ParseTimeTag(string str) var regex = new Regex("(?[-0-9]+),(?start|end)]:(?