Advertisement
Guest User

Untitled

a guest
May 27th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using System.Globalization;
  5. using System.Collections.Generic;
  6.  
  7. namespace ReverseString
  8. {
  9. [TestClass]
  10. public class ReverseStringTests
  11. {
  12. [TestMethod]
  13. public void Empty()
  14. {
  15. Assert.AreEqual("", Reverse(""));
  16. }
  17.  
  18. [TestMethod]
  19. public void SingleChar()
  20. {
  21. Assert.AreEqual("A", Reverse("A"));
  22. }
  23.  
  24. [TestMethod]
  25. public void TwoChars()
  26. {
  27. Assert.AreEqual("BA", Reverse("AB"));
  28. }
  29.  
  30. [TestMethod]
  31. public void ThreeChars()
  32. {
  33. Assert.AreEqual("CBA", Reverse("ABC"));
  34. }
  35.  
  36. [TestMethod]
  37. public void LesMis_no_accent()
  38. {
  39. Assert.AreEqual("selbaresiM seL", Reverse("Les Miserables"));
  40. }
  41.  
  42. [TestMethod]
  43. public void LesMisCopied()
  44. {
  45. Assert.AreEqual("selbarésiM seL", Reverse("Les Misérables"));
  46. }
  47.  
  48. [TestMethod]
  49. public void LesMis()
  50. {
  51. Assert.AreEqual("selbare\u0301siM seL", Reverse("Les Mise\u0301rables"));
  52. }
  53.  
  54. string Reverse2(string str)
  55. {
  56. var l = str.ToCharArray().ToList();
  57. l.Reverse();
  58. return String.Concat(l.ToArray());
  59. }
  60.  
  61. string Reverse(string str)
  62. {
  63. var e = StringInfo.GetTextElementEnumerator(str);
  64. var l = new List<string>();
  65. while (e.MoveNext())
  66. {
  67. l.Add(e.GetTextElement());
  68. }
  69. l.Reverse();
  70. return string.Concat(l);
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement