Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Globalization;
- using System.Collections.Generic;
- namespace ReverseString
- {
- [TestClass]
- public class ReverseStringTests
- {
- [TestMethod]
- public void Empty()
- {
- Assert.AreEqual("", Reverse(""));
- }
- [TestMethod]
- public void SingleChar()
- {
- Assert.AreEqual("A", Reverse("A"));
- }
- [TestMethod]
- public void TwoChars()
- {
- Assert.AreEqual("BA", Reverse("AB"));
- }
- [TestMethod]
- public void ThreeChars()
- {
- Assert.AreEqual("CBA", Reverse("ABC"));
- }
- [TestMethod]
- public void LesMis_no_accent()
- {
- Assert.AreEqual("selbaresiM seL", Reverse("Les Miserables"));
- }
- [TestMethod]
- public void LesMisCopied()
- {
- Assert.AreEqual("selbarésiM seL", Reverse("Les Misérables"));
- }
- [TestMethod]
- public void LesMis()
- {
- Assert.AreEqual("selbare\u0301siM seL", Reverse("Les Mise\u0301rables"));
- }
- string Reverse2(string str)
- {
- var l = str.ToCharArray().ToList();
- l.Reverse();
- return String.Concat(l.ToArray());
- }
- string Reverse(string str)
- {
- var e = StringInfo.GetTextElementEnumerator(str);
- var l = new List<string>();
- while (e.MoveNext())
- {
- l.Add(e.GetTextElement());
- }
- l.Reverse();
- return string.Concat(l);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement