-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2077 from andy840119/adjust-the-generator
Adjust the generator.
- Loading branch information
Showing
13 changed files
with
534 additions
and
32 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/BaseRomajiGeneratorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Tests.Asserts; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis; | ||
|
||
public abstract class BaseRomajiGeneratorTest<TRomajiGenerator, TConfig> : BaseLyricGeneratorTest<TRomajiGenerator, RomajiGenerateResult[], TConfig> | ||
where TRomajiGenerator : RomajiGenerator<TConfig> where TConfig : RomajiGeneratorConfig, new() | ||
{ | ||
protected void CheckGenerateResult(Lyric lyric, string[] expectedRubies, TConfig config) | ||
{ | ||
var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(lyric.TimeTags, expectedRubies); | ||
CheckGenerateResult(lyric, expected, config); | ||
} | ||
|
||
protected override void AssertEqual(RomajiGenerateResult[] expected, RomajiGenerateResult[] actual) | ||
{ | ||
TimeTagAssert.ArePropertyEqual(expected.Select(x => x.TimeTag).ToArray(), actual.Select(x => x.TimeTag).ToArray()); | ||
Assert.AreEqual(expected.Select(x => x.InitialRomaji), actual.Select(x => x.InitialRomaji)); | ||
Assert.AreEqual(expected.Select(x => x.RomajiText), actual.Select(x => x.RomajiText)); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/Ja/JaRomajiGeneratorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Tests.Helper; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis.Ja; | ||
|
||
public class JaRomajiGeneratorTest : BaseRomajiGeneratorTest<JaRomajiGenerator, JaRomajiGeneratorConfig> | ||
{ | ||
[TestCase("花火大会", new[] { "[0,start]", "[3,end]" }, true)] | ||
[TestCase("花火大会", new[] { "[0,start]" }, true)] | ||
[TestCase("花火大会", new[] { "[3,end]" }, false)] // not able to generate the has no start time-tag. | ||
[TestCase("花火大会", new string[] { }, false)] // not able to generate the romaji if has no time-tag. | ||
[TestCase("", new string[] { }, false)] // not able to generate the romaji if lyric is empty. | ||
[TestCase(" ", new string[] { }, false)] | ||
[TestCase(null, new string[] { }, false)] | ||
public void TestCanGenerate(string text, string[] timeTagStrings, bool canGenerate) | ||
{ | ||
var config = GeneratorEmptyConfig(); | ||
|
||
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); | ||
var lyric = new Lyric | ||
{ | ||
Text = text, | ||
TimeTags = timeTags, | ||
}; | ||
|
||
CheckCanGenerate(lyric, canGenerate, config); | ||
} | ||
|
||
// the generated result is not perfect, but it's OK for now. | ||
[TestCase("はなび", new[] { "[0,start]" }, new[] { "^hana bi" })] | ||
[TestCase("花火大会", new[] { "[0,start]", "[3,end]" }, new[] { "^hanabi taikai", "" })] | ||
[TestCase("花火大会", new[] { "[0,start]", "[2,start]", "[3,end]" }, new[] { "^hanabi", "taikai", "" })] | ||
[TestCase("枯れた世界に輝く", | ||
new[] { "[0,start]", "[1,start]", "[2,start]", "[3,start]", "[4,start]", "[5,start]", "[6,start]", "[6,start]", "[6,start]", "[7,start]", "[7,end]" }, | ||
new[] { "^kare", "", "ta", "sekai", "", "ni", "kagayaku", "", "", "", "" })] | ||
public void TestGenerate(string text, string[] timeTagStrings, string[] expectedRomajies) | ||
{ | ||
var config = GeneratorEmptyConfig(); | ||
|
||
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); | ||
var lyric = new Lyric | ||
{ | ||
Text = text, | ||
TimeTags = timeTags, | ||
}; | ||
|
||
CheckGenerateResult(lyric, expectedRomajies, config); | ||
} | ||
|
||
[TestCase("はなび", new[] { "[0,start]" }, new[] { "^HANA BI" })] | ||
[TestCase("花火大会", new[] { "[0,start]", "[2,start]", "[3,end]" }, new[] { "^HANABI", "TAIKAI", "" })] | ||
public void TestGenerateWithUppercase(string text, string[] timeTagStrings, string[] expectedRomajies) | ||
{ | ||
var config = GeneratorEmptyConfig(x => x.Uppercase.Value = true); | ||
|
||
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); | ||
var lyric = new Lyric | ||
{ | ||
Text = text, | ||
TimeTags = timeTags, | ||
}; | ||
|
||
CheckGenerateResult(lyric, expectedRomajies, config); | ||
} | ||
|
||
[TestCase("花", new[] { "[0,start]", "[0,end]" }, new[] { "[0]:hana" }, new[] { "^hana", "" })] | ||
[TestCase("花火", new[] { "[0,start]", "[1,end]" }, new[] { "[0]:hana", "[1]:bi" }, new[] { "^hana bi", "" })] | ||
[TestCase("花火", new[] { "[0,start]", "[1,start]", "[1,end]" }, new[] { "[0]:hana", "[1]:bi" }, new[] { "^hana", "bi", "" })] | ||
[TestCase("花火", new[] { "[0,start]", "[0,start]", "[1,start]", "[1,end]" }, new[] { "[0]:hana", "[1]:bi" }, new[] { "^hana", "", "bi", "" })] | ||
[TestCase("はなび", new[] { "[0,start]", "[1,start]", "[2,start]", "[2,end]" }, new[] { "[0]:hana", "[2]:bi" }, new[] { "^hana", "", "bi", "" })] | ||
public void TestConvertToRomajiGenerateResult(string text, string[] timeTagStrings, string[] romajiParams, string[] expectedResults) | ||
{ | ||
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); | ||
var romajis = parseRomajiGenerateResults(romajiParams); | ||
|
||
var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(timeTags, expectedResults); | ||
var actual = JaRomajiGenerator.Convert(timeTags, romajis).ToArray(); | ||
|
||
AssertEqual(expected, actual); | ||
} | ||
|
||
/// <summary> | ||
/// Process test case time tag string format into <see cref="TimeTag"/> | ||
/// </summary> | ||
/// <example> | ||
/// <inheritdoc cref="TestCaseTagHelper.ParseRomajiTag"/> | ||
/// </example> | ||
/// <param name="str">Time tag string format</param> | ||
/// <returns><see cref="RomajiGenerateResultHelper"/>Time tag object</returns> | ||
private static JaRomajiGenerator.RomajiGeneratorParameter parseRomajiGenerateResult(string str) | ||
{ | ||
// because format is same as the text-tag testing format, so just use this helper. | ||
var romajiTag = TestCaseTagHelper.ParseRomajiTag(str); | ||
return new JaRomajiGenerator.RomajiGeneratorParameter | ||
{ | ||
StartIndex = romajiTag.StartIndex, | ||
EndIndex = romajiTag.EndIndex, | ||
RomajiText = romajiTag.Text, | ||
}; | ||
} | ||
|
||
private static JaRomajiGenerator.RomajiGeneratorParameter[] parseRomajiGenerateResults(IEnumerable<string> strings) | ||
=> strings.Select(parseRomajiGenerateResult).ToArray(); | ||
} |
51 changes: 51 additions & 0 deletions
51
...Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGenerateResultHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis; | ||
|
||
public class RomajiGenerateResultHelper | ||
{ | ||
/// <summary> | ||
/// Convert the string format into the <see cref="RomajiGenerateResult"/>. | ||
/// </summary> | ||
/// <example> | ||
/// karaoke | ||
/// ^karaoke | ||
/// </example> | ||
/// <param name="timeTag">Origin time-tag</param> | ||
/// <param name="str">Generate result string format</param> | ||
/// <returns><see cref="RomajiGenerateResult"/>Romaji generate result.</returns> | ||
public static RomajiGenerateResult ParseRomajiGenerateResult(TimeTag timeTag, string str) | ||
{ | ||
bool initialRomaji = str.StartsWith("^", StringComparison.Ordinal); | ||
|
||
return new RomajiGenerateResult | ||
{ | ||
TimeTag = timeTag, | ||
InitialRomaji = initialRomaji, | ||
RomajiText = str.Replace("^", ""), | ||
}; | ||
} | ||
|
||
public static RomajiGenerateResult[] ParseRomajiGenerateResults(IList<TimeTag> timeTags, IList<string> strings) | ||
{ | ||
if (timeTags.Count != strings.Count) | ||
throw new InvalidOperationException(); | ||
|
||
return parseRomajiGenerateResults(timeTags, strings).ToArray(); | ||
|
||
static IEnumerable<RomajiGenerateResult> parseRomajiGenerateResults(IList<TimeTag> timeTags, IList<string> strings) | ||
{ | ||
for (int i = 0; i < timeTags.Count; i++) | ||
{ | ||
yield return ParseRomajiGenerateResult(timeTags[i], strings[i]); | ||
} | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ame.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGeneratorSelectorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Globalization; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Tests.Asserts; | ||
using osu.Game.Rulesets.Karaoke.Tests.Helper; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis; | ||
|
||
public class RomajiTagGeneratorSelectorTest : BaseLyricGeneratorSelectorTest<RomajiGeneratorSelector, RomajiGenerateResult[]> | ||
{ | ||
[TestCase(17, "花火大会", true)] | ||
[TestCase(17, "我是中文", true)] // only change the language code to decide should be able to generate or not. | ||
[TestCase(17, "", false)] // will not able to generate the romaji if lyric is empty. | ||
[TestCase(17, " ", false)] | ||
[TestCase(17, null, false)] | ||
[TestCase(1028, "はなび", false)] // Should not be able to generate if language is not supported. | ||
public void TestCanGenerate(int lcid, string text, bool canGenerate) | ||
{ | ||
var selector = CreateSelector(); | ||
var lyric = new Lyric | ||
{ | ||
Language = new CultureInfo(lcid), | ||
Text = text, | ||
TimeTags = new[] | ||
{ | ||
new TimeTag(new TextIndex()), | ||
}, | ||
}; | ||
|
||
CheckCanGenerate(lyric, canGenerate, selector); | ||
} | ||
|
||
[TestCase(17, "はなび", new[] { "[0,start]" }, new[] { "^hana bi" })] // Japanese | ||
[TestCase(1041, "花火大会", new[] { "[0,start]", "[3,end]" }, new[] { "^hanabi taikai", "" })] // Japanese | ||
public void TestGenerate(int lcid, string text, string[] timeTagStrings, string[] expectedRomajies) | ||
{ | ||
var selector = CreateSelector(); | ||
|
||
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); | ||
var lyric = new Lyric | ||
{ | ||
Language = new CultureInfo(lcid), | ||
Text = text, | ||
TimeTags = timeTags, | ||
}; | ||
|
||
var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(timeTags, expectedRomajies); | ||
CheckGenerateResult(lyric, expected, selector); | ||
} | ||
|
||
protected override void AssertEqual(RomajiGenerateResult[] expected, RomajiGenerateResult[] actual) | ||
{ | ||
TimeTagAssert.ArePropertyEqual(expected.Select(x => x.TimeTag).ToArray(), actual.Select(x => x.TimeTag).ToArray()); | ||
Assert.AreEqual(expected.Select(x => x.InitialRomaji), actual.Select(x => x.InitialRomaji)); | ||
Assert.AreEqual(expected.Select(x => x.RomajiText), actual.Select(x => x.RomajiText)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.