public void ConcatenateSmallRopesByInsertionInMiddle() { StringBuilder b = new StringBuilder(); Rope <char> rope = new Rope <char>(); for (int i = 1; i <= 1000; i++) { b.Append(i.ToString("d3")); b.Append(' '); } int middle = 0; for (int i = 1; i <= 500; i++) { rope.InsertRange(middle, CharRope.Create(i.ToString("d3") + " ")); middle += 4; rope.InsertRange(middle, CharRope.Create((1001 - i).ToString("d3") + " ")); } Assert.AreEqual(b.ToString(), rope.ToString()); }
public void ConcatenateSmallRopesToRopeBackwards() { StringBuilder b = new StringBuilder(); Rope <char> rope = new Rope <char>(); for (int i = 1; i <= 1000; i++) { b.Append(i.ToString()); b.Append(' '); } for (int i = 1000; i >= 1; i--) { rope.InsertRange(0, CharRope.Create(i.ToString() + " ")); } Assert.AreEqual(b.ToString(), rope.ToString()); }
/// <summary> /// Inserts text into this rope. /// Runs in O(lg N + M). /// </summary> /// <exception cref="ArgumentNullException">newElements is null.</exception> /// <exception cref="ArgumentOutOfRangeException">index or length is outside the valid range.</exception> public static void InsertText(this Rope <char> rope, int index, string text) { if (rope == null) { throw new ArgumentNullException("rope"); } rope.InsertRange(index, text.ToCharArray(), 0, text.Length); /*if (index < 0 || index > rope.Length) { * throw new ArgumentOutOfRangeException("index", index, "0 <= index <= " + rope.Length.ToString(CultureInfo.InvariantCulture)); * } * if (text == null) * throw new ArgumentNullException("text"); * if (text.Length == 0) * return; * rope.root = rope.root.Insert(index, text); * rope.OnChanged();*/ }