当前位置: 首页>>代码示例>>C#>>正文


C# CircularBuffer.AddToHead方法代码示例

本文整理汇总了C#中CircularBuffer.AddToHead方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.AddToHead方法的具体用法?C# CircularBuffer.AddToHead怎么用?C# CircularBuffer.AddToHead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CircularBuffer的用法示例。


在下文中一共展示了CircularBuffer.AddToHead方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsEmpty

        public void IsEmpty()
        {
            var rnd = new Random();
            var buffer = new CircularBuffer<int>(1);

            Assert.IsTrue(buffer.IsEmpty, "Step 1");
            buffer.AddToHead(rnd.Next());
            Assert.IsFalse(buffer.IsEmpty, "Step 2");
            buffer.AddToHead(rnd.Next());
            Assert.IsFalse(buffer.IsEmpty, "Step 3");
            buffer.RemoveFromHead();
            Assert.IsTrue(buffer.IsEmpty, "Step 4");
        }
开发者ID:vpfau,项目名称:Algorithms,代码行数:13,代码来源:CircularBufferTesting.cs

示例2: HeadAndTailTest

        public void HeadAndTailTest()
        {
            var rnd = new Random();
            var buffer = new CircularBuffer<int>(1);

            Assert.Throws(
                Is.TypeOf(typeof(InvalidOperationException)),
                () => { var k = buffer.Head; });

            Assert.Throws(
                Is.TypeOf(typeof(InvalidOperationException)),
                () => { var k = buffer.Tail; });

            buffer.AddToHead(rnd.Next());

            Assert.DoesNotThrow(() => { var k = buffer.Head; });
            Assert.DoesNotThrow(() => { var k = buffer.Tail; });
        }
开发者ID:vpfau,项目名称:Algorithms,代码行数:18,代码来源:CircularBufferTesting.cs

示例3: LengthTest

        public void LengthTest()
        {
            var rnd = new Random();
            var buffer = new CircularBuffer<int>(1);

            Assert.That(buffer.Length, Is.EqualTo(0), "0. Expected 0 length");
            buffer.AddToHead(rnd.Next());
            Assert.That(buffer.Length, Is.EqualTo(1), "1. Expected 1 length");
            buffer.AddToHead(rnd.Next());
            Assert.That(buffer.Length, Is.EqualTo(1), "2. Expected 1 length");
            buffer.RemoveFromHead();
            Assert.That(buffer.Length, Is.EqualTo(0), "3. Expected 0 length");
        }
开发者ID:vpfau,项目名称:Algorithms,代码行数:13,代码来源:CircularBufferTesting.cs

示例4: SingleElementBuffer

        public void SingleElementBuffer()
        {
            var rnd = new Random();
            var buffer = new CircularBuffer<int>(1);

            int value1 = rnd.Next();
            buffer.AddToHead(value1);

            Assert.That(buffer.Head, Is.EqualTo(buffer.Tail), "1. Single element buffer expect Tail equal Head");
            Assert.That(buffer.Head, Is.EqualTo(value1), "1. Head shoud be equal the last added value");

            value1 = rnd.Next();
            buffer.AddToHead(value1);

            Assert.That(buffer.Head, Is.EqualTo(buffer.Tail), "2. Single element buffer expect Tail equal Head");
            Assert.That(buffer.Head, Is.EqualTo(value1), "2. Head shoud be equal the last added value");
            Assert.That(buffer.RemoveFromHead(), Is.EqualTo(value1), "2. Remove from head should return the last added value");
        }
开发者ID:vpfau,项目名称:Algorithms,代码行数:18,代码来源:CircularBufferTesting.cs

示例5: RemoveFromTailTest

        public void RemoveFromTailTest()
        {
            var rnd = new Random();
            var buffer = new CircularBuffer<int>(2);

            var head = rnd.Next();
            var tail = rnd.Next();

            buffer.AddToTail(tail);
            buffer.AddToHead(head);

            Assert.That(buffer.Head, Is.EqualTo(head), "Invalid head value");
            Assert.That(buffer.Tail, Is.EqualTo(tail), "Invalid tail value");
            Assert.That(buffer.Length, Is.EqualTo(2), "Invalid Length value");

            Assert.That(buffer.RemoveFromTail(), Is.EqualTo(tail), "Step 1");
            Assert.That(buffer.RemoveFromTail(), Is.EqualTo(head), "Step 2");
            Assert.That(buffer.IsEmpty, Is.True, "Buffer should be empty");
            Assert.Throws(typeof(InvalidOperationException), () => buffer.RemoveFromTail());
        }
开发者ID:vpfau,项目名称:Algorithms,代码行数:20,代码来源:CircularBufferTesting.cs


注:本文中的CircularBuffer.AddToHead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。