示例#1
0
        public void RemoveMultipleAddedItems()
        {
            var capacity = 5;
            var cb       = new IntBuffer(capacity);

            cb.Add(1);
            cb.Add(2);
            cb.Add(3);

            cb.Remove(2).Should().Be(2);
            cb.Count.Should().Be(1);
            cb.ToArray().Should().Equal(new[] { 3 });
        }
示例#2
0
        public void AddItemsAtStart()
        {
            var capacity = 5;
            var cb       = new IntBuffer(capacity);

            cb.Add(1);
            cb.Add(2);
            cb.Add(3);
            cb.Add(4);

            cb.Capacity.Should().Be(capacity, $"the Capacity after creating a new {nameof(IntBuffer)} should be {capacity}");
            cb.Count.Should().Be(4);
            cb.ToArray().Should().Equal(new[] { 1, 2, 3, 4 });
        }
示例#3
0
        public void ConstructABufferWithInitialItemsUnderCapacity_WriteIndex()
        {
            var capacity  = 5;
            var overwrite = false;
            var cb        = new IntBuffer(new[] { 1, 2, 3 }, capacity, overwrite);

            cb.Add(99);
            cb.Count.Should().Be(4);
            cb.ToArray().Should().Equal(new[] { 1, 2, 3, 99 });
        }
示例#4
0
        public void CopyFullWrappedBuffer_LargerMemory()
        {
            var cb = new IntBuffer(new[] { 1, 2, 3 }, 5);

            cb.Remove();
            cb.Remove();
            cb.Remove(); // Write index should be positioned at 3

            cb.Count.Should().Be(0);
            cb.Add(10);
            cb.Add(11);
            cb.Add(12);
            cb.Add(13);

            var target = new int[] { -1, -1, -1, -1, -1, -1 };

            cb.CopyTo(new Memory <int>(target)).Should().Be(4);
            target.Should().Equal(new[] { 10, 11, 12, 13, -1, -1 });
        }
示例#5
0
        public void CopyWrappedFullFirstPortionOnly_Memory()
        {
            var cb = new IntBuffer(new[] { 1, 2, 3 }, 5);

            cb.Remove();
            cb.Remove();
            cb.Remove(); // Write index should be positioned at 3

            cb.Count.Should().Be(0);
            cb.Add(10);
            cb.Add(11);
            cb.Add(12);
            cb.Add(13);

            var target = new int[] { -1, -1, -1, -1, -1 };

            cb.CopyTo(new Memory <int>(target).Slice(0, 2)).Should().Be(2);
            target.Should().Equal(new[] { 10, 11, -1, -1, -1 });
        }
示例#6
0
        public void CopyWrappedSmallerFirstPortionOnly_Array()
        {
            var cb = new IntBuffer(new[] { 1, 2, 3 }, 5);

            cb.Remove();
            cb.Remove();
            cb.Remove(); // Write index should be positioned at 3

            cb.Count.Should().Be(0);
            cb.Add(10);
            cb.Add(11);
            cb.Add(12);
            cb.Add(13);

            var target = new int[] { -1, -1, -1, -1, -1 };

            cb.CopyTo(target, 0, 1);
            target.Should().Equal(new[] { 10, -1, -1, -1, -1 });
        }
示例#7
0
        public void ClearBuffer()
        {
            var capacity = 5;
            var cb       = new IntBuffer(new[] { 1, 2, 3 }, capacity);

            cb.Add(4);
            cb.Count.Should().Be(4);
            cb.Clear();
            cb.Count.Should().Be(0);
            cb.ToArray().Length.Should().Be(0);
        }
示例#8
0
        public void AddItemsOverCapacityWithoutOverwrite()
        {
            var capacity = 5;
            var cb       = new IntBuffer(capacity);

            cb.Add(1);
            cb.Add(2);
            cb.Add(3);
            cb.Add(4);
            cb.Add(5);

            new Action(() => cb.Add(6)).Should().Throw <InvalidOperationException>();
        }
示例#9
0
        public void AddItemsOverCapacityWithOverwrite()
        {
            var capacity = 5;
            var cb       = new IntBuffer(capacity, true);

            cb.Add(1);
            cb.Add(2);
            cb.Add(3);
            cb.Add(4);
            cb.Add(5);
            cb.Add(6);

            cb.Capacity.Should().Be(capacity, $"the Capacity after creating a new {nameof(IntBuffer)} should be {capacity}");
            cb.Count.Should().Be(5);
            cb.ToArray().Should().Equal(new[] { 2, 3, 4, 5, 6 });
        }