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()); }
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")); }
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")); }
public void Test_StringManipulator_AddTwoStrings() { Rope m = new Rope(); m.Append("hello"); m.Append(" world"); Assert.AreEqual("hello world", m.ToString()); }
public void Test_StringManipulator_SubstringMultipleSection() { Rope m = new Rope(); m.Append("hello cru"); m.Append("el world"); Assert.AreEqual("cruel", m.Substring(6, 5)); }
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()); }
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)); }
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)); }
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()); }
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()); }
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); }
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()); }
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()); }
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()); }
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"); }
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); }
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); }
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; } }
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())); }
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}"); }
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); }
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}"); }
public void Test_Rope_RemoveStartLength_SingleAppend() { Rope m = new Rope(); m.Append("hello"); m.Remove(1, 2); Assert.AreEqual("hlo", m.ToString()); }
public void Test_Rope_RemoveStartLength_EndOfSection() { Rope m = new Rope(); m.Append("hello"); m.Remove(3, 2); Assert.AreEqual("hel", m.ToString()); }
public void Test_StringManipulator_RemoveTwoStringsInsideSection() { Rope m = new Rope(); m.Append("hello cruel world"); m.Remove("l"); Assert.AreEqual("heo crue word", m.ToString()); }
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()); }
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); }
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()))); }
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)); }
private Rope Append(Rope ropeCC, string strAppend) { log.WriteLine(GetCurrentMethod()); log.WriteLine(String.Format("Appending string: {0}", strAppend)); return(ropeCC.Append(strAppend)); }