Beispiel #1
0
        public void Test_StringManipulator_IndexOfStringStartIndexInLaterSectionNotFound()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("k", 7), m.IndexOf("k", 7));
        }
Beispiel #2
0
        public void Test_StringManipulator_InsertString()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello");
            m.Append("  world");
            m.Insert("cruel", 6);
            Assert.AreEqual("hello cruel world", m.ToString());
        }
Beispiel #3
0
        public void Test_StringManipulator_IndexOfStringStartIndex()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("l", 3), m.IndexOf("l", 3));
        }
Beispiel #4
0
        public void Test_StringManipulator_AddTwoStrings()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello");
            m.Append(" world");

            Assert.AreEqual("hello world", m.ToString());
        }
Beispiel #5
0
        public void Test_StringManipulator_IndexOfSingleLetter()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello".IndexOf('l'), m.IndexOf("l"));
        }
Beispiel #6
0
        public void Test_StringManipulator_IndexOfStringInSecondSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("rld"), m.IndexOf("rld"));
        }
Beispiel #7
0
        public void Test_StringManipulator_SubstringMultipleSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("cruel", m.Substring(6, 5));
        }
Beispiel #8
0
        public void Test_StringManipulator_RemoveWholeFirstSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("world");
            m.Remove("hello ");

            Assert.AreEqual("world", m.ToString());
        }
Beispiel #9
0
        public void Test_StringManipulator_RemoveSingleStringAcrossTwoSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cr");
            m.Append("uel world");
            m.Remove("cruel");

            Assert.AreEqual("hello  world", m.ToString());
        }
Beispiel #10
0
        public void Test_StringManipulator_RemoveWholeLastSectionAndReplace()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("cruel ");
            m.Append("world");
            m.Replace("world", "suzy");

            Assert.AreEqual("hello cruel suzy", m.ToString());
        }
Beispiel #11
0
        public void Test_StringManipulator_RemoveMidTextAndReplace()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello");
            m.Append(" cruel ");
            m.Append("world");
            m.Replace(" cruel ", " big ");

            Assert.AreEqual("hello big world", m.ToString());
        }
Beispiel #12
0
        public void Test_StringManipulator_RemoveSingleStringAcrossThreeSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cr");
            m.Append("u");
            m.Append("el world");
            m.Remove("cruel");

            Assert.AreEqual("hello  world", m.ToString());
            Assert.AreEqual("hello  world".Length, m.Length, "The Lengths should be the same too");
        }
Beispiel #13
0
        private static void TestStringManipulator()
        {
            Console.Write("String Manipulator: ");
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new StringManipulator();

            for (int x = 0; x < 1000; x++)
            {
                sb.Append("Hello ");
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Insert("World", 50);
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Replace("Hello ", "Hey ");
            }
            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Beispiel #14
0
        public void TestTimingSM()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new StringManipulator();

            for (int x = 0; x < 1000; x++)
            {
                sb.Append("Hello ");
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Insert("World", 50);
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Replace("Hello ", "Hey ");
            }
            sw.Stop();

            Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}");
        }
Beispiel #15
0
        public void Test_StringManipulator_ReplaceMany()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Replace("l", "L");

            Assert.AreEqual("heLLo crueL worLd", m.ToString());
        }
Beispiel #16
0
        public void Test_StringManipulator_RemoveTwoStringsInsideSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Remove("l");

            Assert.AreEqual("heo crue word", m.ToString());
        }