Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename from "romaji" into "romanization" in the time-tag. #2165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void TestAutoGenerateTimeTagRomaji()

AssertSelectedHitObject(h =>
{
Assert.AreEqual("karaoke", h.TimeTags[0].RomajiText);
Assert.AreEqual("karaoke", h.TimeTags[0].RomanizedSyllable);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void TestSetTimeTagTime()
}

[Test]
public void TestSetTimeTagInitialRomaji()
public void TestSetTimeTagFirstSyllable()
{
var timeTag = new TimeTag(new TextIndex(), 1000);
PrepareHitObject(() => new Lyric
Expand All @@ -50,16 +50,16 @@ public void TestSetTimeTagInitialRomaji()
},
});

TriggerHandlerChanged(c => c.SetTimeTagInitialRomaji(timeTag, true));
TriggerHandlerChanged(c => c.SetTimeTagFirstSyllable(timeTag, true));

AssertSelectedHitObject(_ =>
{
Assert.AreEqual(true, timeTag.InitialRomaji);
Assert.AreEqual(true, timeTag.FirstSyllable);
});
}

[Test]
public void TestSetTimeTagRomajiText()
public void TestSetTimeTagRomanizedSyllable()
{
var timeTag = new TimeTag(new TextIndex(), 1000);
PrepareHitObject(() => new Lyric
Expand All @@ -71,18 +71,18 @@ public void TestSetTimeTagRomajiText()
},
});

TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, "karaoke"));
TriggerHandlerChanged(c => c.SetTimeTagRomanizedSyllable(timeTag, "karaoke"));

AssertSelectedHitObject(_ =>
{
Assert.AreEqual("karaoke", timeTag.RomajiText);
Assert.AreEqual("karaoke", timeTag.RomanizedSyllable);
});

TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, " "));
TriggerHandlerChanged(c => c.SetTimeTagRomanizedSyllable(timeTag, " "));

AssertSelectedHitObject(_ =>
{
Assert.AreEqual(string.Empty, timeTag.RomajiText);
Assert.AreEqual(string.Empty, timeTag.RomanizedSyllable);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void TestCheckEmptyTime(string text, string[] timeTags)
[TestCase("カラオケ", "")] // should not be empty.
[TestCase("カラオケ", " ")] // should not be white-space only.
[TestCase("カラオケ", "卡拉OK")] // should be within latin.
public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
public void TestCheckTimeTagRomajiInvalidText(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -114,7 +114,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
{
new TimeTag(new TextIndex())
{
RomajiText = romajiText,
RomanizedSyllable = romanizedSyllable,
Time = 1000,
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
Expand All @@ -128,7 +128,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
}

[TestCase("カラオケ", null)] // should not be white-space only.
public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
public void TestCheckRomajiEmptyTextIfFirst(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -137,8 +137,8 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
{
new TimeTag(new TextIndex())
{
RomajiText = romajiText,
InitialRomaji = true,
RomanizedSyllable = romanizedSyllable,
FirstSyllable = true,
Time = 1000,
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
Expand All @@ -154,7 +154,7 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
[TestCase("カラオケ", "")] // should not have empty text if end.
[TestCase("カラオケ", " ")] // should not have empty text if end.
[TestCase("カラオケ", "123")] // should not have empty text if end.
public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText)
public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -167,7 +167,7 @@ public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText)
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
{
RomajiText = romajiText,
RomanizedSyllable = romanizedSyllable,
Time = 2000,
},
},
Expand All @@ -190,7 +190,7 @@ public void TestRomajiNotFistRomajiTextIfEnd()
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
{
InitialRomaji = true, // is invalid.
FirstSyllable = true, // is invalid.
Time = 2000,
},
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Tests.Asserts;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis;
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization;

public abstract class BaseRomajiGeneratorTest<TRomajiGenerator, TConfig> : BaseLyricGeneratorTest<TRomajiGenerator, IReadOnlyDictionary<TimeTag, RomajiGenerateResult>, TConfig>
where TRomajiGenerator : RomajiGenerator<TConfig> where TConfig : RomajiGeneratorConfig, new()
public abstract class BaseRomanizationGeneratorTest<TRomanizationGenerator, TConfig> : BaseLyricGeneratorTest<TRomanizationGenerator, IReadOnlyDictionary<TimeTag, RomanizationGenerateResult>, TConfig>
where TRomanizationGenerator : RomanizationGenerator<TConfig> where TConfig : RomanizationGeneratorConfig, new()
{
protected void CheckGenerateResult(Lyric lyric, string[] expectedRubies, TConfig config)
{
var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(lyric.TimeTags, expectedRubies);
var expected = RomanizationGenerateResultHelper.ParseRomanizationGenerateResults(lyric.TimeTags, expectedRubies);
CheckGenerateResult(lyric, expected, config);
}

protected override void AssertEqual(IReadOnlyDictionary<TimeTag, RomajiGenerateResult> expected, IReadOnlyDictionary<TimeTag, RomajiGenerateResult> actual)
protected override void AssertEqual(IReadOnlyDictionary<TimeTag, RomanizationGenerateResult> expected, IReadOnlyDictionary<TimeTag, RomanizationGenerateResult> actual)
{
TimeTagAssert.ArePropertyEqual(expected.Select(x => x.Key).ToArray(), actual.Select(x => x.Key).ToArray());
Assert.AreEqual(expected.Select(x => x.Value), actual.Select(x => x.Value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
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.Edit.Generator.Lyrics.Romanization.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;
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization.Ja;

public class JaRomajiGeneratorTest : BaseRomajiGeneratorTest<JaRomajiGenerator, JaRomajiGeneratorConfig>
public class JaRomanizationGeneratorTest : BaseRomanizationGeneratorTest<JaRomanizationGenerator, JaRomanizationGeneratorConfig>
{
[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)] // not able to make the romanization if has no time-tag.
[TestCase("", new string[] { }, false)] // not able to make the romanization if lyric is empty.
[TestCase(" ", new string[] { }, false)]
[TestCase(null, new string[] { }, false)]
public void TestCanGenerate(string text, string[] timeTagStrings, bool canGenerate)
Expand All @@ -40,7 +40,7 @@ public void TestCanGenerate(string text, string[] timeTagStrings, bool canGenera
[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)
public void TestGenerate(string text, string[] timeTagStrings, string[] expectedRomanizedSyllables)
{
var config = GeneratorEmptyConfig();

Expand All @@ -51,12 +51,12 @@ public void TestGenerate(string text, string[] timeTagStrings, string[] expected
TimeTags = timeTags,
};

CheckGenerateResult(lyric, expectedRomajies, config);
CheckGenerateResult(lyric, expectedRomanizedSyllables, 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)
public void TestGenerateWithUppercase(string text, string[] timeTagStrings, string[] expectedRomanizedSyllables)
{
var config = GeneratorEmptyConfig(x => x.Uppercase.Value = true);

Expand All @@ -67,45 +67,42 @@ public void TestGenerateWithUppercase(string text, string[] timeTagStrings, stri
TimeTags = timeTags,
};

CheckGenerateResult(lyric, expectedRomajies, config);
CheckGenerateResult(lyric, expectedRomanizedSyllables, 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)
public void TestConvertToRomanizationGenerateResult(string text, string[] timeTagStrings, string[] romanizationParams, string[] expectedResults)
{
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings);
var romajis = parseRomajiGenerateResults(romajiParams);
var romanizations = parseRomanizationGenerateResults(romanizationParams);

var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(timeTags, expectedResults);
var actual = JaRomajiGenerator.Convert(timeTags, romajis);
var expected = RomanizationGenerateResultHelper.ParseRomanizationGenerateResults(timeTags, expectedResults);
var actual = JaRomanizationGenerator.Convert(timeTags, romanizations);

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)
/// <returns><see cref="RomanizationGenerateResultHelper"/>Time tag object</returns>
private static JaRomanizationGenerator.RomanizationGeneratorParameter parseRomanizationGenerateResult(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
return new JaRomanizationGenerator.RomanizationGeneratorParameter
{
StartIndex = romajiTag.StartIndex,
EndIndex = romajiTag.EndIndex,
RomajiText = romajiTag.Text,
RomanizedSyllable = romajiTag.Text,
};
}

private static JaRomajiGenerator.RomajiGeneratorParameter[] parseRomajiGenerateResults(IEnumerable<string> strings)
=> strings.Select(parseRomajiGenerateResult).ToArray();
private static JaRomanizationGenerator.RomanizationGeneratorParameter[] parseRomanizationGenerateResults(IEnumerable<string> strings)
=> strings.Select(parseRomanizationGenerateResult).ToArray();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.Romanization;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization;

public class RomanizationGenerateResultHelper
{
/// <summary>
/// Convert the string format into the <see cref="RomanizationGenerateResult"/>.
/// </summary>
/// <example>
/// karaoke
/// ^karaoke
/// </example>
/// <param name="timeTag">Origin time-tag</param>
/// <param name="str">Generate result string format</param>
/// <returns><see cref="RomanizationGenerateResult"/>Romanization generate result.</returns>
public static KeyValuePair<TimeTag, RomanizationGenerateResult> ParseRomanizationGenerateResult(TimeTag timeTag, string str)
{
var result = new RomanizationGenerateResult
{
FirstSyllable = str.StartsWith("^", StringComparison.Ordinal),
RomanizedSyllable = str.Replace("^", ""),
};

return new KeyValuePair<TimeTag, RomanizationGenerateResult>(timeTag, result);
}

public static IReadOnlyDictionary<TimeTag, RomanizationGenerateResult> ParseRomanizationGenerateResults(IList<TimeTag> timeTags, IList<string> strings)
{
if (timeTags.Count != strings.Count)
throw new InvalidOperationException();

return parseRomanizationGenerateResults(timeTags, strings).ToDictionary(k => k.Key, v => v.Value);

static IEnumerable<KeyValuePair<TimeTag, RomanizationGenerateResult>> parseRomanizationGenerateResults(IList<TimeTag> timeTags, IList<string> strings)
{
for (int i = 0; i < timeTags.Count; i++)
{
yield return ParseRomanizationGenerateResult(timeTags[i], strings[i]);
}
}
}
}
Loading