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


C# Deque.ToArray方法代码示例

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


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

示例1: TestAddAndGrow

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

            d.AddFirst(1);
            Assert.IsTrue(d.Count == 1);
            Assert.IsTrue(d.Capacity == 4);

            d.AddFirst(0);
            Assert.IsTrue(d.Count == 2);
            Assert.IsTrue(d.Capacity == 4);

            d.AddLast(2);
            d.AddLast(3);
            Assert.IsTrue(d.Count == 4);
            Assert.IsTrue(d.Capacity == 4);

            d.AddLast(4);
            Assert.IsTrue(d.Count == 5);
            Assert.IsTrue(d.Capacity == 8);

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

示例2: TestInsert

        public void TestInsert()
        {
            Deque<int> test = new Deque<int>(10);
            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            test.Add(4);
            test.Add(5);
            test.Add(6);
            test.Add(7);
            test.Add(8);
            test.Add(9);
            test.RemoveAt(0);
            test.RemoveAt(0);
            test.Insert(3, 7);
            test.Insert(3, 8);

            CollectionAssert.AreEqual(test.ToArray(), new int[] { 2, 3, 4, 8, 7, 5, 6, 7, 8, 9 });
            Assert.AreEqual(test.Count, 10);
        }
开发者ID:npcook,项目名称:terminal,代码行数:21,代码来源:DequeTests.cs

示例3: TestRemoveAt

        public void TestRemoveAt()
        {
            Deque<int> test = new Deque<int>(6);
            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            test.Add(4);
            test.Add(5);

            test.PopFront();
            test.PopFront();

            test.Add(6);
            test.Add(7);

            test.RemoveAt(2);

            int[] arr = test.ToArray();

            CollectionAssert.AreEqual(arr, new int[] { 2, 3, 5, 6, 7 });
            Assert.AreEqual(test.Count, 5);
        }
开发者ID:npcook,项目名称:terminal,代码行数:23,代码来源:DequeTests.cs

示例4: TestToArray

        private static void TestToArray(Deque deque)
        {
            deque.Clear();

            PopulateDequePushBack(deque);

            object[] array = deque.ToArray();
            int i = 0;

            foreach(object obj in deque)
            {
                System.Diagnostics.Debug.Assert(obj.Equals(array[i]));
                i++;
            }
        }
开发者ID:jordanajlouni,项目名称:ProjectAccountingSoftware,代码行数:15,代码来源:Tester.cs

示例5: TestToArray

        private static void TestToArray(Deque<int> deque)
        {
            deque.Clear();

            PopulateDequePushBack(deque);

            int[] array = deque.ToArray();
            int i = 0;

            foreach(int item in deque)
            {
                Debug.Assert(item.Equals(array[i]));
                i++;
            }
        }
开发者ID:blahblahblahblah831,项目名称:brawltools2,代码行数:15,代码来源:GenericTester.cs

示例6: ToArrayTest

        public void ToArrayTest()
        {
            Deque<int> actual = new Deque<int> { 123, 324, 12, 90, 23 };
            int[] expected = { 123, 324, 12, 90, 23 };

            CollectionAssert.AreEqual(expected, actual.ToArray());
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:7,代码来源:DequeTest.cs

示例7: 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

示例8: 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

示例9: ToArrayPUT

 public void ToArrayPUT([PexAssumeUnderTest]int[] values)
 {
     Deque<int> actual = new Deque<int>(values);
     CollectionAssert.AreEqual(values, actual.ToArray());
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:5,代码来源:DequeTest.cs


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