Beispiel #1
0
        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]);
            }
        }
 public void AddFirst(IByteBuffer buf, IPromise promise)
 {
     if (promise is object && !promise.IsVoid)
     {
         _bufAndListenerPairs.AddFirst​(promise);
     }
     _bufAndListenerPairs.AddFirst​(buf);
     IncrementReadableBytes(buf.ReadableBytes);
 }
        public void AddFirstTest()
        {
            LoadInput();
            const int element = 11;

            _deque.AddFirst(element);
            var peekedElement = _deque.PeekFirst;

            Assert.AreEqual(element, peekedElement, "Could not peek the first element on a list after AddFirst");
        }
Beispiel #4
0
 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());
 }
Beispiel #5
0
    private void NormilizeParalax()
    {
        while (transform.position.y - minY > maxLenght)
        {
            maxY += height;
            minY += height;

            var down = paralaxDeque.RemoveFirst();

            var position = down.transform.position;
            position.y = maxY;
            down.transform.position = position;

            paralaxDeque.AddLast(down);
        }

        while (maxY - transform.position.y > maxLenght)
        {
            maxY -= height;
            minY -= height;

            var up = paralaxDeque.RemoveLast();

            var position = up.transform.position;
            position.y            = minY;
            up.transform.position = position;

            paralaxDeque.AddFirst(up);
        }
    }
Beispiel #6
0
        /// <summary>
        /// <para><paramref name="from"/> からの最短経路長を01-BSFで求める。</para>
        /// <para>計算量: O(|E| + |V|)</para>
        /// </summary>
        public static T[] ShortestPath01BFS <T, TOp, TNode, TEdge>(this IWGraph <T, TOp, TNode, TEdge> graph, int from)
            where T : struct
            where TOp : struct, INumOperator <T>
            where TNode : IGraphNode <TEdge>
            where TEdge : IWGraphEdge <T>
        {
            TOp op       = default;
            var graphArr = graph.AsArray();
            var INF      = op.MaxValue;
            var res      = new T[graphArr.Length];

            System.Array.Fill(res, INF);
            res[from] = default;

            var used    = new bool[graphArr.Length];
            int count   = 0;
            var remains = new Deque <int>(graphArr.Length)
            {
                from
            };

            while (remains.Count > 0)
            {
                var ix = remains.PopFirst();
                if (used[ix])
                {
                    continue;
                }
                used[ix] = true;
                if (++count >= graphArr.Length)
                {
                    break;
                }
                var len = res[ix];
                foreach (var e in graphArr[ix].Children)
                {
                    var to         = e.To;
                    var nextLength = len;
                    if (EqualityComparer <T> .Default.Equals(e.Value, default))
                    {
                        if (op.GreaterThan(res[to], nextLength))
                        {
                            res[to] = nextLength;
                            remains.AddFirst(to);
                        }
                    }
                    else
                    {
                        nextLength = op.Increment(nextLength);
                        if (op.GreaterThan(res[to], nextLength))
                        {
                            res[to] = nextLength;
                            remains.AddLast(to);
                        }
                    }
                }
            }
            return(res);
        }
        public void PushStack(ExpressionResultCacheStackEntry lambda)
        {
            if (callStack == null) {
                callStack = new ArrayDeque<ExpressionResultCacheStackEntry>();
            }

            callStack.AddFirst(lambda); //Push(lambda);
        }
Beispiel #8
0
        public void PushContext(long contextNumber)
        {
            if (callStack == null) {
                callStack = new ArrayDeque<ExpressionResultCacheStackEntry>();
                lastValueCacheStack = new ArrayDeque<long>(10);
            }

            lastValueCacheStack.AddFirst(contextNumber); // Push(contextNumber);
        }
Beispiel #9
0
 public void Given_null_item_add_should_throw_NullPointerException()
 {
     // arrange
     var deque = new Deque<string>();
     // act
     // assert
     Assert.Throws<NullReferenceException>(() => deque.AddFirst(null));
     Assert.Throws<NullReferenceException>(() => deque.AddLast(null));
 }
        public void RemoveFirstTest()
        {
            var d1 = new Deque <int>();
            int a  = 5;

            d1.AddFirst(a);

            Assert.AreEqual <int>(a, d1.RemoveFirst());
        }
        public void TryingTest()
        {
            var d1 = new Deque <int>();
            int a  = 5;

            d1.AddFirst(a);
            d1.AddLast(5);

            Assert.AreEqual <int>(a, d1.RemoveLast());
        }
Beispiel #12
0
 public void Add_element_should_increment_size()
 {
     // arrange
     var deque = new Deque<string>();
     // act
     deque.AddFirst("Item");
     deque.AddLast("Item2");
     // assert
     Assert.AreEqual(2, deque.Size());
 }
        public BulletPool()
        {
            _bulletDeque = new Deque<Bullet>(POOL_SIZE);

            //Initialize the pool.
            for (int i = 0; i < POOL_SIZE; i++)
            {
                _bulletDeque.AddFirst(new Bullet(GameContent.Assets.Images.Ships.Bullets[ShipType.BattleCruiser, ShipTier.Tier1], Vector2.Zero, GameScreen.World, null));
            }
        }
        public void AdvancedTestDequeFirst()
        {
            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.AddFirst(item);
                }
                else
                {
                    if (!deque.IsEmpty)
                    {
                        deque.RemoveFirst();
                    }
                }
            }

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

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

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

            Assert.AreEqual(0, deque.Size);
            Assert.IsTrue(deque.IsEmpty);
        }
        public void ContainsTest()
        {
            var d1 = new Deque <int>();
            int a  = 5;
            int b  = 10;

            d1.AddLast(a);
            d1.AddFirst(b);

            Assert.IsTrue(d1.Contains(a));
        }
Beispiel #16
0
 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);
 }
Beispiel #17
0
        public void TestFirst()
        {
            //arrange
            if (Deque <int> .IsEmpty)
            {
                Deque <int> .AddFirst(1);
            }
            var expected = Deque <int> .head.Data;
            int count    = Deque <int> .count;

            //act
            var actual = Deque <int> .First;

            //assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #18
0
        public void TestAddFirst()
        {
            //arrange
            var data                      = 127;
            int expectedCount             = Deque <int> .count + 1;
            DoublyNode <int> expectedHead = new DoublyNode <int>(data);

            //act
            Deque <int> .AddFirst(data);

            DoublyNode <int> actualHead = Deque <int> .head;
            int actualCount             = Deque <int> .count;

            //assert

            Assert.AreEqual(expectedHead.Data, actualHead.Data);
            Assert.AreEqual(expectedCount, actualCount);
        }
Beispiel #19
0
        public void TestClear()
        {
            //arrange
            int expectedCount = 0;

            //act
            Deque <int> .AddFirst(0);

            Deque <int> .Clear();

            int actualCount             = Deque <int> .count;
            DoublyNode <int> actualHead = Deque <int> .head;
            DoublyNode <int> actualTail = Deque <int> .tail;

            //assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.IsNull(actualHead);
            Assert.IsNull(actualTail);
        }
Beispiel #20
0
 public void Push(IUndoableCommand command) => commands.AddFirst(command);
 public void Enqueue_Front(GameObject key)
 {
     deQueue.AddFirst(key);
 }
Beispiel #22
0
        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]);
            }
        }