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


C# Queue.GetBackingStore方法代码示例

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


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

示例1: Enqueue_WhenAnItemIsDequeued_EnqueingShouldAddItAtStart

        public void Enqueue_WhenAnItemIsDequeued_EnqueingShouldAddItAtStart()
        {
            // Arrange
            var q = new Queue<int>();
            q.Enqueue(10);
            q.Enqueue(20);
            q.Enqueue(30);

            q.Dequeue();

            // Act
            q.Enqueue(40);

            // Assert
            Assert.AreEqual(3, q.Count, "3 items should be in the queue.");
            Assert.AreEqual(1, q.GetHeadAndTail().Item1, "Head node should be pointing to the second slot.");
            Assert.AreEqual(3, q.GetHeadAndTail().Item2, "Tail should be pointing to the index 3.");
            Assert.AreEqual(0, q.GetBackingStore()[0], "Should contain new value.");
            Assert.AreEqual(20, q.GetBackingStore()[1], "Should contain the 20 at index 1.");
            Assert.AreEqual(30, q.GetBackingStore()[2], "Should contain 30 at index 2.");
            Assert.AreEqual(40, q.GetBackingStore()[3], "Should contain 30 at index 2.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:22,代码来源:QueueTest.cs

示例2: Dequeue_ShouldReturnFirstInItem_AndUpdateHeadIndex

        public void Dequeue_ShouldReturnFirstInItem_AndUpdateHeadIndex()
        {
            // Arrange
            var q = new Queue<int>();
            q.Enqueue(10);
            q.Enqueue(20);

            // Act
            var result = q.Dequeue();

            // Assert
            Assert.AreEqual(10, result, "Should return the first element.");
            Assert.AreEqual(1, q.GetHeadAndTail().Item1, "Head element index should update");
            Assert.AreEqual(1, q.GetHeadAndTail().Item2, "Tail element index should not change.");
            Assert.AreEqual(0, q.GetBackingStore()[0], "Old head element should be empty (zero)");
            Assert.AreEqual(1, q.Count, "Queue length should be 1.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:17,代码来源:QueueTest.cs

示例3: Enqueue_WhenNumberOfElementsBecomeMoreThan4_BackingStoreShouldIncreaseInSize

        public void Enqueue_WhenNumberOfElementsBecomeMoreThan4_BackingStoreShouldIncreaseInSize()
        {
            // Arrange
            var q = new Queue<int>();
            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);

            // Act
            q.Enqueue(5);

            // Assert
            Assert.AreEqual(5, q.Count, "Length shall be 5");
            Assert.AreEqual(8, q.GetBackingStore().Length, "Backing store should have doubled the size.");
            Assert.AreEqual(1, q.GetBackingStore()[0], "1 should be at position 0");
            Assert.AreEqual(2, q.GetBackingStore()[1], "2 should be at position 1");
            Assert.AreEqual(3, q.GetBackingStore()[2], "3 should be at position 2");
            Assert.AreEqual(4, q.GetBackingStore()[3], "4 should be at position 3");
            Assert.AreEqual(5, q.GetBackingStore()[4], "5 should be at position 4");
            Assert.AreEqual(0, q.GetHeadAndTail().Item1, "Head should still be 0.");
            Assert.AreEqual(4, q.GetHeadAndTail().Item2, "Tail should be at 4.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:23,代码来源:QueueTest.cs

示例4: Peek_ShouldReturnTheHeadItem_ShouldNotRemoveFromQueue

        public void Peek_ShouldReturnTheHeadItem_ShouldNotRemoveFromQueue()
        {
            // Arrange
            var q = new Queue<int>();
            q.Enqueue(20);
            q.Enqueue(30);
            q.Dequeue();

            // Act
            var result = q.Peek();

            // Assert
            Assert.AreEqual(30, result, "Should return expected value 30.");
            Assert.AreEqual(0, q.GetBackingStore()[0], "Index 0 should be empty.");
            Assert.AreEqual(30, q.GetBackingStore()[1], "Index 1 should have 30.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:16,代码来源:QueueTest.cs

示例5: Enqueue_WhenThereAreNoItems_NewItemShouldBeTheFirst

        public void Enqueue_WhenThereAreNoItems_NewItemShouldBeTheFirst()
        {
            // Arrange
            var q = new Queue<int>();

            // Act
            q.Enqueue(10);

            // Assert
            Assert.AreEqual(1, q.Count, "Should only be a single item in the queue.");
            Assert.AreEqual(10, q.GetBackingStore()[0], "First element should be the given value.");
            Assert.AreEqual(0, q.GetHeadAndTail().Item1, "Head node should be 0.");
            Assert.AreEqual(0, q.GetHeadAndTail().Item2, "Tail node should be 0.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:14,代码来源:QueueTest.cs

示例6: Enqueue_WhenSecondItemAdded_SecondItemShouldBeTheTail

        public void Enqueue_WhenSecondItemAdded_SecondItemShouldBeTheTail()
        {
            // Arrange
            var q = new Queue<int>();
            q.Enqueue(10);

            // Act
            q.Enqueue(20);

            // Assert
            Assert.AreEqual(2, q.Count, "Number of items in the queue.");
            Assert.AreEqual(10, q.GetBackingStore()[0], "Frist element should be 10.");
            Assert.AreEqual(20, q.GetBackingStore()[1], "Second element should be 20.");
            Assert.AreEqual(0, q.GetHeadAndTail().Item1, "Position of head should not change.");
            Assert.AreEqual(1, q.GetHeadAndTail().Item2, "Position of tail should be the new element.");
        }
开发者ID:malindasuhash,项目名称:PlayingWithDataStructures,代码行数:16,代码来源:QueueTest.cs


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