Skip to content

Commit

Permalink
Sync reverse-string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Jul 31, 2024
1 parent 8fff6fb commit d59e2b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 13 additions & 2 deletions exercises/practice/reverse-string/.meta/Example.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

public static class ReverseString
{
public static string Reverse(string input)
{
return new string(input.ToCharArray().Reverse().ToArray());
if (string.IsNullOrEmpty(input))
{
return input;
}

StringInfo stringInfo = new(input);
IEnumerable<string> reversed = Enumerable.Range(0, stringInfo.LengthInTextElements)
.Select(i => stringInfo.SubstringByTextElements(i, 1))
.Reverse();

return string.Join("", reversed);
}
}
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
18 changes: 18 additions & 0 deletions exercises/practice/reverse-string/ReverseStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ public void An_even_sized_word()
{
Assert.Equal("reward", ReverseString.Reverse("drawer"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Wide_characters()
{
Assert.Equal("猫子", ReverseString.Reverse("子猫"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Grapheme_cluster_with_precombined_form()
{
Assert.Equal("dnatsnehctsrüW", ReverseString.Reverse("Würstchenstand"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Grapheme_clusters()
{
Assert.Equal("มรกแรปโนยขีเผู้", ReverseString.Reverse("ผู้เขียนโปรแกรม"));
}
}

0 comments on commit d59e2b6

Please sign in to comment.