Example #1
0
        public void FIFO_supports_removeAt()
        {
            FIFOBuffer <int> f = new FIFOBuffer <int>(0);

            Assert.Throws <IndexOutOfRangeException>(() => f.RemoveAt(0));
            Assert.Throws <IndexOutOfRangeException>(() => f.RemoveAt(-1));

            f.Capacity = 1;
            f.Push(1);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 1);
                b.RemoveAt(0);
                AssertEmpty(b);
            });

            f.Capacity = 2;
            f.Push(2);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 1, 2);
                b.RemoveAt(0);
                AssertContains(b, 2);
            });

            f.Capacity = 3;
            f.Push(3);
            f.Push(4);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 2, 3, 4);
                b.RemoveAt(2);
                AssertContains(b, 2, 3);
                b.RemoveAt(1);
                AssertContains(b, 2);
                b.RemoveAt(0);
                AssertEmpty(b);
            });

            f.Capacity = 4;
            f.Clear();
            f.Push(2);
            f.Push(3);
            f.Push(4);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 2, 3, 4);
                b.RemoveAt(2);
                AssertContains(b, 2, 3);
                b.RemoveAt(1);
                AssertContains(b, 2);
            });

            f.Push(5);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 2, 3, 4, 5);
                b.RemoveAt(2);
                AssertContains(b, 2, 3, 5);
                b.RemoveAt(1);
                AssertContains(b, 2, 5);
                b.RemoveAt(1);
                AssertContains(b, 2);
            });

            f.Capacity = 5;
            f.Push(6);
            TestWithInternalOffsetsAndGrowingCapacity(f, b =>
            {
                AssertContains(b, 2, 3, 4, 5, 6);
                b.RemoveAt(2);
                AssertContains(b, 2, 3, 5, 6);
                b.RemoveAt(1);
                AssertContains(b, 2, 5, 6);
                b.RemoveAt(2);
                AssertContains(b, 2, 5);
                b.RemoveAt(1);
                AssertContains(b, 2);
            });
        }