Exemplo n.º 1
0
        public void TestIndexAccess()
        {
            ArraySegmentList <char> source = new ArraySegmentList <char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            char[] exptected = "I lovHell".ToCharArray();

            for (int i = source.Count - 1; i >= 0; i--)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }

            for (int i = 0; i < source.Count; i++)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }

            source.RemoveSegmentAt(0);
            source.RemoveSegmentAt(0);

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            for (int i = 0; i < source.Count; i++)
            {
                Assert.AreEqual(exptected[i], source[i], i + " is expected!");
            }
        }
Exemplo n.º 2
0
        public void TestCount()
        {
            ArraySegmentList<char> source = new ArraySegmentList<char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.AreEqual(9, source.Count);

            source.RemoveSegmentAt(0);
            Assert.AreEqual(4, source.Count);

            source.RemoveSegmentAt(0);
            Assert.AreEqual(0, source.Count);

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.AreEqual(9, source.Count);
        }
Exemplo n.º 3
0
        public void TestCount()
        {
            ArraySegmentList <char> source = new ArraySegmentList <char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.AreEqual(9, source.Count);

            source.RemoveSegmentAt(0);
            Assert.AreEqual(4, source.Count);

            source.RemoveSegmentAt(0);
            Assert.AreEqual(0, source.Count);

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.AreEqual(9, source.Count);
        }
Exemplo n.º 4
0
        public void TestOutOfIndex()
        {
            ArraySegmentList<char> source = new ArraySegmentList<char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);
            
            char currentChar = ' ';

            Assert.Throws<IndexOutOfRangeException>(delegate
            {
                currentChar = source[-1];
            });

            Assert.Throws<IndexOutOfRangeException>(delegate
            {
                currentChar = source[10];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws<IndexOutOfRangeException>(delegate
            {
                currentChar = source[4];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws<IndexOutOfRangeException>(delegate
            {
                currentChar = source[0];
            });

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.Throws<IndexOutOfRangeException>(delegate
            {
                currentChar = source[10];
            });
            
            Console.Write(currentChar);
        }
Exemplo n.º 5
0
        public void TestOutOfIndex()
        {
            ArraySegmentList <char> source = new ArraySegmentList <char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            char currentChar = ' ';

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                currentChar = source[-1];
            });

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                currentChar = source[10];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                currentChar = source[4];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                currentChar = source[0];
            });

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                currentChar = source[10];
            });

            Console.Write(currentChar);
        }
Exemplo n.º 6
0
        public void TestOutOfIndex()
        {
            ArraySegmentList <char> source = new ArraySegmentList <char>(new List <ArraySegment <char> >
            {
                new ArraySegment <char>("I love you,".ToCharArray(), 0, 5),
                new ArraySegment <char>("Hello world!".ToCharArray(), 0, 4)
            });

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                char currentChar = source[-1];
            });

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                char currentChar = source[10];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                char currentChar = source[4];
            });

            source.RemoveSegmentAt(0);
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                char currentChar = source[0];
            });

            source.AddSegment(new ArraySegment <char>("I love you,".ToCharArray(), 0, 5));
            source.AddSegment(new ArraySegment <char>("Hello world!".ToCharArray(), 0, 4));

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                char currentChar = source[10];
            });
        }
Exemplo n.º 7
0
        public void TestRemoveSegment()
        {
            ArraySegmentList <char> source = new ArraySegmentList <char>();

            source.AddSegment(new ArraySegment <char>("I love you,".ToCharArray(), 0, 5));
            source.AddSegment(new ArraySegment <char>("Hello world!".ToCharArray(), 0, 4));
            Assert.AreEqual(9, source.Count);
            Assert.AreEqual(2, source.SegmentCount);

            source.RemoveSegmentAt(1);
            Assert.AreEqual(5, source.Count);
            Assert.AreEqual(1, source.SegmentCount);

            char[] exptected = "I lov".ToCharArray();

            for (var i = 0; i < exptected.Length; i++)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }
        }
Exemplo n.º 8
0
        public void TestIndexAccess()
        {
            ArraySegmentList<char> source = new ArraySegmentList<char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            char[] exptected = "I lovHell".ToCharArray();

            for (int i = source.Count - 1; i >= 0; i--)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }

            for (int i = 0; i < source.Count; i++)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }

            source.RemoveSegmentAt(0);
            source.RemoveSegmentAt(0);

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            for (int i = 0; i < source.Count; i++)
            {
                Assert.AreEqual(exptected[i], source[i], i + " is expected!");
            }
        }
Exemplo n.º 9
0
        public void TestRemoveSegment()
        {
            ArraySegmentList<char> source = new ArraySegmentList<char>();

            source.AddSegment("I love you,".ToCharArray(), 0, 5);
            source.AddSegment("Hello world!".ToCharArray(), 0, 4);

            Assert.AreEqual(9, source.Count);
            Assert.AreEqual(2, source.SegmentCount);

            source.RemoveSegmentAt(1);
            Assert.AreEqual(5, source.Count);
            Assert.AreEqual(1, source.SegmentCount);

            char[] exptected = "I lov".ToCharArray();

            for (var i = 0; i < exptected.Length; i++)
            {
                Assert.AreEqual(exptected[i], source[i]);
            }
        }