Skip to content

Commit

Permalink
Merge pull request #2 from kmoroz/1-chuu-is-translated-into-ちゅ-instea…
Browse files Browse the repository at this point in the history
…d-of-ちゅう

fix issue-1 and add respective test case
  • Loading branch information
kmoroz committed Oct 24, 2023
2 parents 0a64b67 + 6950630 commit 9f766e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void ToKana_WhenPassedAnEmptyString_ReturnsAnEmptyString(string input, st
[TestCase("chyx", "chyx")]
[TestCase("shyp", "shyp")]
[TestCase("ltsb", "ltsb")]
[TestCase("chuu", "ちゅう")]
public void ToKana_WhenPassedInput_ConvertsItCorrectly(string input, string expectedOutput)
{
string result = WanaKana.ToKana(input);
Expand Down
16 changes: 8 additions & 8 deletions WanaKanaShaapu/TreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ private static void AddToTree(Dictionary<string, Node> tree, (string Romaji, str

private static void AddNode(Node node, string romaji, string kana)
{
if (romaji.Length == 1 && !node.Children.ContainsKey(romaji))
if (romaji.Length == 0)
return;
else if (romaji.Length == 1 && !node.Children.ContainsKey(romaji))
node.Children.Add(romaji, new Node(kana));
else if (romaji.Length == 1 && node.Children.ContainsKey(romaji))
node.Children[romaji].Data = kana;
else
{
foreach (char c in romaji)
{
if (!node.Children.ContainsKey(c.ToString()))
node.Children.Add(c.ToString(), new Node(string.Empty));
node = node.Children[c.ToString()];
AddNode(node, romaji[1..], kana);
}
var firstChar = romaji.First().ToString();
if (!node.Children.ContainsKey(firstChar))
node.Children.Add(firstChar.First().ToString(), new Node(string.Empty));
node = node.Children[firstChar.ToString()];
AddNode(node, romaji[1..], kana);
}
}

Expand Down

0 comments on commit 9f766e4

Please sign in to comment.