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


C# Deque.Add方法代码示例

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


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

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

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

示例3: TestAdd

        public void TestAdd()
        {
            Deque<int> deque = new Deque<int>();

            Assert.IsTrue(deque.IsEmpty);

            int item = 1;

            Assert.IsFalse(deque.Contains(item));
            deque.Add(item);

            int actualBack;
            actualBack = deque[0];

            Assert.IsTrue(deque.Contains(item));
            Assert.AreEqual(item, actualBack);

            int itemNewBack = 2;
            Assert.IsFalse(deque.Contains(itemNewBack));
            deque.AddBack(itemNewBack);

            Assert.IsTrue(deque.Contains(itemNewBack));
            actualBack = deque[1];
            Assert.AreEqual(itemNewBack, actualBack);

            actualBack = deque.RemoveBack();
            Assert.AreEqual(itemNewBack, actualBack);

            int itemNewFront = -1;
            Assert.IsFalse(deque.Contains(itemNewFront));
            deque.AddFront(itemNewFront);

            int actualFront;
            Assert.IsTrue(deque.Contains(itemNewFront));

            actualFront = deque[0];
            Assert.AreEqual(itemNewFront, actualFront);

            actualFront = deque.RemoveFront();
            Assert.AreEqual(itemNewFront, actualFront);

            int[] itemRange = new[] { 3, 4, 5, 6 };
            int offset = deque.Count;
            deque.AddRange(itemRange);

            foreach (var itm in itemRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemBackRange = new[] { 7, 8, 9, 10 };
            offset = deque.Count;
            deque.AddBackRange(itemBackRange);
            foreach (var itm in itemBackRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemFrontRange = new[] { 3, 4, 5, 6 };
            deque.AddFrontRange(itemFrontRange);

            for (int i = 0; i < itemFrontRange.Length; i++)
            {
                var itm = itemFrontRange[i];
                Assert.AreEqual(itm, deque[i]);
            }
        }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:69,代码来源:DequeTests.cs

示例4: Update

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (IPointerOverUI.Instance.IsPointerOverUIObject())
            {
                return;
            }
            curr = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0))
        {
            Vector3 cuurent = Input.mousePosition;
            float currDis = Vector3.Distance(curr,cuurent);
            if (currDis>distanceOffset)
            {
                return;
            }
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.gameObject.CompareTag("Finish") || hit.collider.gameObject.CompareTag("Fe")) //地面,铁丝网可点击
                {
                    short gridX, gridY;
                    if (getDestination(hit.point, out gridX, out gridY))
                    {
                        IList<SpriteSoldier> list = new Deque<SpriteSoldier>();
                        bool oneSoldierType = true;
                        for (int i = 0; i < soilders.Count; i++)
                        {
                            SpriteSoldier sn = soilders[i];
                            if (!sn.soldier.isSelected || sn.soldier.destination.x == gridX && sn.soldier.destination.y == gridY)
                            {
                                continue;
                            }
                            if (oneSoldierType && i + 1 < soilders.Count)
                            {
                                SpriteSoldier ss = soilders[i + 1];
                                if (ss.soldier.isSelected && sn.soldier.type != ss.soldier.type)
                                    oneSoldierType = false;
                            }

                            sn.soldier.destination.x = gridX;
                            sn.soldier.destination.y = gridY;
                            sn.soldier._target.x = hit.point.x;
                            sn.soldier._target.y = hit.point.z;

                            list.Add(soilders[i]);
                        }
                        StartCoroutine(startFindPath(list, oneSoldierType));
                    }
                }
            }
        }
    }
开发者ID:jacky20140731,项目名称:MiniBattle,代码行数:57,代码来源:Map.cs

示例5: TestBulkAdd

        public void TestBulkAdd()
        {
            int loops = 10000;
            Deque<int> deque = new Deque<int>();
            for (int i = 1; i < loops; i++)
            {
                deque.Add(i);
            }

            deque.AddFront(0);

            Deque<int> dequeCopy = new Deque<int>(deque);

            for (int expected = 0; expected < loops; expected++)
            {
                int actual = deque.RemoveFront();
                int actualCopy = dequeCopy[expected];

                Assert.AreEqual(expected, actual, "Original deque item differs from expected value");
                Assert.AreEqual(expected, actualCopy, "Copied deque item differs from expected value");
            }
        }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:22,代码来源:DequeTests.cs


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