Esempio n. 1
0
 public void EmptyConcatenation()
 {
     foreach (var rope in someRopes)
     {
         Assert.Same(rope, Rope.Concat(rope, Rope.Empty));
         Assert.Same(rope, Rope.Concat(Rope.Empty, rope));
     }
 }
Esempio n. 2
0
 public void ConcatNull()
 {
     foreach (var r in someRopes)
     {
         Assert.Throws <ArgumentNullException>(() => { Rope.Concat(r, null); });
         Assert.Throws <ArgumentNullException>(() => { Rope.Concat(null, r); });
     }
 }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
 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);
             }
         }
     }
 }