Skip to content

Commit

Permalink
Rename the method/variable name to avoid typo error.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Mar 3, 2024
1 parent 10620b5 commit ed7e997
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public void TestGenerateWithUppercase(string text, string[] timeTagStrings, stri
public void TestConvertToRomanisationGenerateResult(string text, string[] timeTagStrings, string[] romanisationParams, string[] expectedResults)
{
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings);
var romanisations = parseRomanisationGenerateResults(romanisationParams);
var results = parseRomanisationGenerateResults(romanisationParams);

var expected = RomanisationGenerateResultHelper.ParseRomanisationGenerateResults(timeTags, expectedResults);
var actual = JaRomanisationGenerator.Convert(timeTags, romanisations);
var actual = JaRomanisationGenerator.Convert(timeTags, results);

AssertEqual(expected, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ protected override IReadOnlyDictionary<TimeTag, RomanisationGenerateResult> Gene
var tokenStream = analyzer.GetTokenStream("dummy", new StringReader(text));

// get the processing tags.
var processingRomanisations = getProcessingRomanisations(text, tokenStream, Config).ToArray();
var parameters = generateParameters(text, tokenStream, Config).ToArray();

// then, trying to mapping them with the time-tags.
return Convert(item.TimeTags, processingRomanisations);
return Convert(item.TimeTags, parameters);
}

private static IEnumerable<RomanisationGeneratorParameter> getProcessingRomanisations(string text, TokenStream tokenStream, JaRomanisationGeneratorConfig config)
private static IEnumerable<RomanisationGeneratorParameter> generateParameters(string text, TokenStream tokenStream, JaRomanisationGeneratorConfig config)
{
// Reset the stream and convert all result
tokenStream.Reset();
Expand Down Expand Up @@ -85,9 +85,9 @@ private static IEnumerable<RomanisationGeneratorParameter> getProcessingRomanisa
tokenStream.Dispose();
}

internal static IReadOnlyDictionary<TimeTag, RomanisationGenerateResult> Convert(IList<TimeTag> timeTags, IList<RomanisationGeneratorParameter> romanisations)
internal static IReadOnlyDictionary<TimeTag, RomanisationGenerateResult> Convert(IList<TimeTag> timeTags, IList<RomanisationGeneratorParameter> parameters)
{
var group = createGroup(timeTags, romanisations);
var group = createGroup(timeTags, parameters);
return group.ToDictionary(k => k.Key, x =>
{
bool isFirst = timeTags.IndexOf(x.Key) == 0; // todo: use better to mark the first syllable.
Expand All @@ -100,22 +100,22 @@ internal static IReadOnlyDictionary<TimeTag, RomanisationGenerateResult> Convert
};
});

static IReadOnlyDictionary<TimeTag, List<RomanisationGeneratorParameter>> createGroup(IList<TimeTag> timeTags, IList<RomanisationGeneratorParameter> romanisations)
static IReadOnlyDictionary<TimeTag, List<RomanisationGeneratorParameter>> createGroup(IList<TimeTag> timeTags, IList<RomanisationGeneratorParameter> parameters)
{
var dictionary = timeTags.ToDictionary(x => x, v => new List<RomanisationGeneratorParameter>());

int processedIndex = 0;

foreach (var (timeTag, list) in dictionary)
{
while (processedIndex < romanisations.Count && isTimeTagInRange(timeTags, timeTag, romanisations[processedIndex]))
while (processedIndex < parameters.Count && isTimeTagInRange(timeTags, timeTag, parameters[processedIndex]))
{
list.Add(romanisations[processedIndex]);
list.Add(parameters[processedIndex]);
processedIndex++;
}
}

if (processedIndex < romanisations.Count - 1)
if (processedIndex < parameters.Count - 1)
throw new InvalidOperationException("Still have romanisations that haven't process");

return dictionary;
Expand Down

0 comments on commit ed7e997

Please sign in to comment.