-
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.
Implement the selector for able to select the romaji generator by cul…
…ture info.
- Loading branch information
1 parent
5eebc77
commit 2468709
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorSelector.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,18 @@ | ||
// 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 osu.Game.Rulesets.Karaoke.Configuration; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; | ||
|
||
public class RomajiGeneratorSelector : LyricGeneratorSelector<RomajiGenerateResult[], RomajiGeneratorConfig> | ||
{ | ||
public RomajiGeneratorSelector(KaraokeRulesetEditGeneratorConfigManager generatorConfigManager) | ||
: base(generatorConfigManager) | ||
{ | ||
RegisterGenerator<JaRomajiGenerator, JaRomajiGeneratorConfig>(new CultureInfo(17)); | ||
RegisterGenerator<JaRomajiGenerator, JaRomajiGeneratorConfig>(new CultureInfo(1041)); | ||
} | ||
} |