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


C# Deque.RemoveLast方法代码示例

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


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

示例1: Remove_on_empty_queue_should_throw_NoSuchElementException

 public void Remove_on_empty_queue_should_throw_NoSuchElementException()
 {
     // arrange
     var deque = new Deque<string>();
     // act
     // assert
     Assert.Throws<NoSuchElementException>(() => deque.RemoveFirst());
     Assert.Throws<NoSuchElementException>(() => deque.RemoveLast());
 }
开发者ID:syned,项目名称:Algoritms,代码行数:9,代码来源:DequeTests.cs

示例2: Remove_element_should_decrease_size

 public void Remove_element_should_decrease_size()
 {
     // arrange
     var deque = new Deque<string>();
     deque.AddFirst("Item");
     deque.AddFirst("Item2");
     // act
     deque.RemoveFirst();
     deque.RemoveLast();
     // assert
     Assert.AreEqual(0, deque.Size());
 }
开发者ID:syned,项目名称:Algoritms,代码行数:12,代码来源:DequeTests.cs

示例3: Remove_item_should_return_last_added_item

 public void Remove_item_should_return_last_added_item()
 {
     // arrange
     var deque = new Deque<string>();
     deque.AddLast("LastItem");
     deque.AddFirst("Item");
     // act
     var actual = deque.RemoveFirst();
     var actualLast = deque.RemoveLast();
     // assert
     Assert.AreEqual("Item", actual);
     Assert.AreEqual("LastItem", actualLast);
 }
开发者ID:syned,项目名称:Algoritms,代码行数:13,代码来源:DequeTests.cs

示例4: AdvancedTestDequeLast

        public void AdvancedTestDequeLast()
        {
            var deque = new Deque<String>();
            var items = new List<string>
            {
                "0",
                "1",
                "2",
                "-",
                "-",
                "3",
                "4",
                "5",
                "6",
                "7",
                "8",
                "9"
            };

            Assert.AreEqual(0, deque.Size);
            Assert.IsTrue(deque.IsEmpty);

            foreach (var item in items)
            {
                if (item != "-")
                {
                    deque.AddLast(item);
                }
                else
                {
                    if (!deque.IsEmpty)
                    {
                        deque.RemoveLast();
                    }
                }
            }

            var builder = new StringBuilder();
            foreach (var item in deque)
            {
                builder.Append(item);
            }

            Assert.AreEqual("03456789", builder.ToString());
            Assert.AreEqual(8, deque.Size);
            Assert.IsFalse(deque.IsEmpty);

            while (!deque.IsEmpty)
            {
                deque.RemoveLast();
            }

            Assert.AreEqual(0, deque.Size);
            Assert.IsTrue(deque.IsEmpty);
        }
开发者ID:polkhovskyi,项目名称:RandomizedQueuesAndDeques,代码行数:55,代码来源:DequeTests.cs

示例5: TestRemoveAndTrim

        public void TestRemoveAndTrim()
        {
            var d = new Deque<int>(4);
            Assert.IsTrue(d.Count == 0);
            Assert.IsTrue(d.Capacity == 4);

            d.AddLast(0);
            d.AddLast(1);
            d.AddLast(2);
            d.AddLast(3);
            d.AddLast(4);
            d.AddLast(5);
            Assert.IsTrue(d.Count == 6);
            Assert.IsTrue(d.Capacity == 8);

            d.RemoveLast();
            d.RemoveLast();
            d.RemoveLast();
            Assert.IsTrue(d.Count == 3);
            Assert.IsTrue(d.Capacity == 8);

            d.TrimExcess();
            Assert.IsTrue(d.Count == 3);
            Assert.IsTrue(d.Capacity == 3);

            var arr = d.ToArray();
            var exp = new int[] { 0, 1, 2 };
            Assert.IsTrue(arr.Length == exp.Length);
            for (int i = 0; i < arr.Length; i++) {
                Assert.IsTrue(arr[i] == exp[i]);
            }
        }
开发者ID:rzubek,项目名称:UnityGameTools,代码行数:32,代码来源:DequeTest.cs

示例6: TestValuesAndWrapAround

        public void TestValuesAndWrapAround()
        {
            var d = new Deque<int>(4);

            d.AddLast(1);   // internally it contains [H:1, 2, 3, 4]
            d.AddLast(2);
            d.AddLast(3);
            d.AddLast(4);
            Assert.IsTrue(d.PeekFirst() == 1 & d.PeekLast() == 4);

            d.RemoveFirst();
            d.RemoveLast();  // now it's [0, H:2, 3, 0]
            Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
            Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 3);

            d.AddLast(4);
            d.RemoveFirst(); // now it's [0, 0, H:3, 4]
            Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
            Assert.IsTrue(d.PeekFirst() == 3 & d.PeekLast() == 4);

            d.AddLast(5);
            d.RemoveFirst(); // now it's [5, 0, 0, H:4]
            Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
            Assert.IsTrue(d.PeekFirst() == 4 & d.PeekLast() == 5);

            d.AddFirst(3);
            d.AddFirst(2);   // now it's [5, H:2, 3, 4]
            Assert.IsTrue(d.Count == 4 && d.Capacity == 4);
            Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 5);

            d.AddFirst(1);   // reallocated to [H:1, 2, 3, 4, 5, 0, 0, 0]
            d.AddFirst(0);   // now it's [1, 2, 3, 4, 5, 0, 0, H:0]
            Assert.IsTrue(d.Count == 6 && d.Capacity == 8);
            Assert.IsTrue(d.PeekFirst() == 0 & d.PeekLast() == 5);

            var arr = d.ToArray();
            var exp = new int[] { 0, 1, 2, 3, 4, 5 };
            Assert.IsTrue(arr.Length == exp.Length);
            for (int i = 0; i < arr.Length; i++) {
                Assert.IsTrue(arr[i] == exp[i]);
            }
        }
开发者ID:rzubek,项目名称:UnityGameTools,代码行数:42,代码来源:DequeTest.cs


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