public void EmptyConcatenation() { foreach (var rope in someRopes) { Assert.Same(rope, Rope.Concat(rope, Rope.Empty)); Assert.Same(rope, Rope.Concat(Rope.Empty, rope)); } }
public void ConcatNull() { foreach (var r in someRopes) { Assert.Throws <ArgumentNullException>(() => { Rope.Concat(r, null); }); Assert.Throws <ArgumentNullException>(() => { Rope.Concat(null, r); }); } }
public void TestConcat(string a, string b) { Rope ropeA = new Rope(a); Rope ropeB = new Rope(b); ropeA.Concat(ropeB); Assert.Equal(a + b, ropeA.Report()); }
static void JustifyText(Rope rope, int width) { for (int i = width; i < rope.Length; i += width) { while (!Regex.IsMatch(rope[i].ToString(), @"\s")) // Look for whitespace to split upon { i--; } // Split then concat at i Rope other = rope.Split(i); rope.Concat(other); } }
public void Overflow() { Rope r = Rope.ForString("x"); Rope all = r; Assert.Equal(1, all.Length); for (int i = 1; i < 31; i++) { r = Rope.Concat(r, r); all = Rope.Concat(all, r); Assert.Equal(1 << i, r.Length); Assert.Equal((1 << (i + 1)) - 1, all.Length); } Assert.Equal(int.MaxValue, all.Length); var waferThinMint = Rope.ForString("y"); Assert.Throws <OverflowException>(() => Rope.Concat(all, waferThinMint)); Assert.Throws <OverflowException>(() => Rope.Concat(waferThinMint, all)); Assert.Throws <OverflowException>(() => Rope.Concat(all, all)); }
public void Concatenation() { foreach (var r1 in someRopes) { foreach (var r2 in someRopes) { foreach (var r3 in someRopes) { Rope c1 = Rope.Concat(r1, Rope.Concat(r2, r3)); Rope c2 = Rope.Concat(Rope.Concat(r1, r2), r3); Assert.Equal(c1, c2); // associative Assert.Equal(c1.GetHashCode(), c2.GetHashCode()); string s = r1.ToString() + r2.ToString() + r3.ToString(); Assert.Equal(c1.ToString(), s); Assert.Equal(c2.ToString(), s); Rope c3 = Rope.ForString(s); Assert.Equal(c1.GetHashCode(), c3.GetHashCode()); Assert.Equal(c1, c3); Assert.Equal(c2, c3); Assert.Equal(c3.ToString(), s); } } } }