Ejemplo n.º 1
0
        public void Test_Rope_RemoveStartLength_AcrossTwoAppends()
        {
            Rope m = new Rope();

            m.Append("hello");
            m.Append(" world");
            m.Remove(1, 6);
            Assert.AreEqual("horld", m.ToString());
        }
Ejemplo n.º 2
0
        public void Test_StringManipulator_IndexOfSingleLetter()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello".IndexOf('l'), m.IndexOf("l"));
        }
Ejemplo n.º 3
0
        public void Test_StringManipulator_IndexOfStringInSecondSections()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello cruel world".IndexOf("rld"), m.IndexOf("rld"));
        }
Ejemplo n.º 4
0
        public void Test_StringManipulator_AddTwoStrings()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello world", m.ToString());
        }
Ejemplo n.º 5
0
        public void Test_StringManipulator_SubstringMultipleSection()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("cruel", m.Substring(6, 5));
        }
Ejemplo n.º 6
0
        public void Test_StringManipulator_InsertStringInBetweenSections()
        {
            Rope m = new Rope();

            m.Append("hello ");
            m.Append(" world");
            m.Insert("cruel", 6);
            Assert.AreEqual("hello cruel world", m.ToString());
        }
Ejemplo n.º 7
0
        public void Test_StringManipulator_IndexOfStringStartIndexInLaterSectionNotFound()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello cruel world".IndexOf("k", 7), m.IndexOf("k", 7));
        }
Ejemplo n.º 8
0
        public void Test_StringManipulator_IndexOfStringStartIndex()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello cruel world".IndexOf("l", 3), m.IndexOf("l", 3));
        }
Ejemplo n.º 9
0
        public void Test_StringManipulator_RemoveSingleStringAcrossTwoSections()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello  world", m.ToString());
        }
Ejemplo n.º 10
0
        public void Test_StringManipulator_RemoveWholeFirstSectionAndReplace()
        {
            Rope m = new Rope();

            m.Append("hello ");
            m.Append("world");
            m.Replace("hello ", "bonjour ");

            Assert.AreEqual("bonjour world", m.ToString());
        }
Ejemplo n.º 11
0
        public void Test_StringManipulator_AddThreeStrings()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello cruel world", m.ToString());
            Assert.AreEqual("hello cruel world".Length, m.Length);
        }
Ejemplo n.º 12
0
        public void Test_StringManipulator_RemoveMidTextAndReplace()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello big world", m.ToString());
        }
Ejemplo n.º 13
0
        public void Test_StringManipulator_RemoveWholeLastSectionAndReplace()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello cruel suzy", m.ToString());
        }
Ejemplo n.º 14
0
        public void Test_StringManipulator_RemoveWholeMidSection()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("hello world", m.ToString());
        }
Ejemplo n.º 15
0
        public void Test_StringManipulator_RemoveSingleStringAcrossThreeSections()
        {
            Rope m = new Rope();

            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");
        }
Ejemplo n.º 16
0
        public void TestIndexOfAcrossConcatenateRopes()
        {
            Rope r = RopeBuilder.BUILD("aaaaaaaaaaaaaaaa12");

            r = r.Append("3456789aaaaaa");
            r = r.SubSequence(1, r.Length());
            Assert.AreEqual(r.IndexOf("123456789", 3), 15);

            r = RopeBuilder.BUILD("aaaaaaaaaaaa1111");
            r = r.Append("1bbbbbbbbbbbbbbbb");
            Assert.AreEqual(r.IndexOf("1111", 3), 12);
        }
Ejemplo n.º 17
0
        private static void TestRope()
        {
            Console.Write("Rope: ");
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new Rope();

            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);
        }
Ejemplo n.º 18
0
        public void TestIterator()
        {
            Rope r = RopeBuilder.BUILD("01234aaa56789");

            r = r.Remove(5, 8);             // "0123456789"
            for (int i = 0; i < r.Length(); ++i)
            {
                Assert.AreEqual("0123456789"[i], r.CharAt(i));
            }

            r = r.SubSequence(1, r.Length());             // "123456789"
            for (int i = 0; i < r.Length(); ++i)
            {
                Assert.AreEqual("123456789"[i], r.CharAt(i));
            }

            r = r.Append('0');             // "1234567890"
            int j = 0;

            foreach (char c in r)
            {
                Assert.AreEqual("1234567890"[j], c);
                ++j;
            }
        }
Ejemplo n.º 19
0
        public void TestSubstringAppend()
        {
            Rope r = RopeBuilder.BUILD("");

            r = r.Append("round ");
            r = r.Append((0).ToString());
            r = r.Append(" 1234567890");

            Assert.AreEqual("round ", RopeToString(r, 0, 6));
            Assert.AreEqual("round 0", RopeToString(r, 0, 7));
            Assert.AreEqual("round 0 ", RopeToString(r, 0, 8));
            Assert.AreEqual("round 0 1", RopeToString(r, 0, 9));
            Assert.AreEqual("round 0 12", RopeToString(r, 0, 10));
            Assert.AreEqual("round 0 1234567890", RopeToString(r, 0, 18));
            Assert.AreEqual("round 0 1234567890", RopeToString(r, 0, r.Length()));
        }
Ejemplo n.º 20
0
        public void TestTimingSMDebug()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new Rope();

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

            Assert.AreEqual("Hello Hello Hello Hello ", sb.ToString());

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

            Assert.AreEqual("Hello HellWorldWorldo Hello Hello ", sb.ToString());


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

            Assert.AreEqual("Hey HellWorldWorldo Hey Hey ", sb.ToString());

            //  Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}");
        }
Ejemplo n.º 21
0
        public void TrimWhitespace_RopeStringEquivalence()
        {
            string str = "11111";
            Rope   r   = RopeBuilder.BUILD(new RepeatedCharacterSequence('1', 5));

            str = str.Insert(1, "aa");
            r   = r.Insert(1, "aa");
            Compare(r, str);

            // Add spaces onto the end and trim
            r   = r.Append("  ");
            str = str + "  ";
            Compare(r, str);

            r   = r.Trim();
            str = str.Trim();

            Compare(r, str);

            // Trim without any whitespace
            r   = r.Trim();
            str = str.Trim();

            Compare(r, str);

            // Lots of whitespace at the beginning
            r   = r.PadStart(r.Length() + 2);
            str = "  " + str;
            Compare(r, str);

            r   = r.Trim();
            str = str.Trim();

            Compare(r, str);
        }
Ejemplo n.º 22
0
        public void TestTimingSM()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new Rope();

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

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

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

            Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}");
        }
Ejemplo n.º 23
0
        public void Test_Rope_RemoveStartLength_SingleAppend()
        {
            Rope m = new Rope();

            m.Append("hello");
            m.Remove(1, 2);
            Assert.AreEqual("hlo", m.ToString());
        }
Ejemplo n.º 24
0
        public void Test_Rope_RemoveStartLength_EndOfSection()
        {
            Rope m = new Rope();

            m.Append("hello");
            m.Remove(3, 2);
            Assert.AreEqual("hel", m.ToString());
        }
Ejemplo n.º 25
0
        public void Test_StringManipulator_RemoveTwoStringsInsideSection()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("heo crue word", m.ToString());
        }
Ejemplo n.º 26
0
        public void Test_StringManipulator_ReplaceMany()
        {
            Rope m = new Rope();

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

            Assert.AreEqual("heLLo crueL worLd", m.ToString());
        }
Ejemplo n.º 27
0
        public void TestIndexOf()
        {
            string strTest  = "Hello, world!";
            Rope   ropeTest = RopeBuilder.BUILD(strTest);

            Compare(ropeTest, strTest);

            ropeTest = ropeTest.Insert(7, "under");
            strTest  = "Hello, underworld!";
            Compare(ropeTest, strTest);

            ropeTest = ropeTest.SubSequence(1, ropeTest.Length());
            strTest  = "ello, underworld!";
            Compare(ropeTest, strTest);

            ropeTest = ropeTest.Append("123456789");
            strTest  = strTest + "123456789";
            Compare(ropeTest, strTest);

            ropeTest = ropeTest.Append("123456789");
            strTest  = strTest + "123456789";
            Compare(ropeTest, strTest);
        }
Ejemplo n.º 28
0
        public Rope Insert(int dstOffset, string s)
        {
            Rope r = (s == null) ? RopeBuilder.BUILD("null") : RopeBuilder.BUILD(s);

            if (dstOffset == 0)
            {
                return(r.Append(this));
            }
            else if (dstOffset == this.Length())
            {
                return(this.Append(r));
            }
            else if (dstOffset < 0 || dstOffset > this.Length())
            {
                throw new IndexOutOfRangeException(dstOffset + " is out of range [" + 0 + ":" + this.Length() + "]");
            }
            return(this.SubSequence(0, dstOffset).Append(r).Append(this.SubSequence(dstOffset, this.Length())));
        }
Ejemplo n.º 29
0
 private Rope Append(Rope ropeCC, Rope ropeAppend)
 {
     log.WriteLine(GetCurrentMethod());
     log.WriteLine(String.Format("Appending rope with string: {0}", ropeAppend.ToString()));
     return(ropeCC.Append(ropeAppend));
 }
Ejemplo n.º 30
0
 private Rope Append(Rope ropeCC, string strAppend)
 {
     log.WriteLine(GetCurrentMethod());
     log.WriteLine(String.Format("Appending string: {0}", strAppend));
     return(ropeCC.Append(strAppend));
 }