Пример #1
0
        public void InsertMoreElementAndDrainToTest()
        {
            int offset = 5;
            BufferWithFifoEviction <string> buffer = new BufferWithFifoEviction <string>(5, new StringLengthCostAssigner());

            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            long limit = buffer.Capacity + offset;

            for (int i = 5; i < limit; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(5, buffer.Count);

            var drainedItems = new List <string>();

            buffer.DrainTo(drainedItems);
            for (int i = 0; i < buffer.Capacity; i++)
            {
                long expected = i + offset;
                Assert.Equal(expected.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
        public void DrainToTest()
        {           
            var buffer = new BufferWithFifoEviction<string>(10, new StringLengthCostAssigner());
            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(10, buffer.Count);

            var drainedItems = new List<string>();
            buffer.DrainTo(drainedItems);
            for (int i = 0; i < drainedItems.Count; i++)
            {
                Assert.Equal(i.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
Пример #3
0
        public void DrainToTest()
        {
            var buffer = new BufferWithFifoEviction <string>(10, new StringLengthCostAssigner());

            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(10, buffer.Count);

            var drainedItems = new List <string>();

            buffer.DrainTo(drainedItems);
            for (int i = 0; i < drainedItems.Count; i++)
            {
                Assert.Equal(i.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }
        public void InsertMoreElementAndDrainToTest()
        {
            int offset = 5;
            BufferWithFifoEviction<string> buffer = new BufferWithFifoEviction<string>(5, new StringLengthCostAssigner());
            for (int i = 0; i < buffer.Capacity; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            long limit = buffer.Capacity + offset;
            for (int i = 5; i < limit; i++)
            {
                string a = i.ToString(CultureInfo.CurrentCulture);
                Assert.True(buffer.Add(a));
            }

            Assert.Equal(5, buffer.Count);

            var drainedItems = new List<string>();
            buffer.DrainTo(drainedItems);
            for (int i = 0; i < buffer.Capacity; i++)
            {
                long expected = i + offset;
                Assert.Equal(expected.ToString(CultureInfo.CurrentCulture), drainedItems[i]);
            }
        }