public void Pop_Should_RespectCapacity()
        {
            var arr = new List <object> {
                new { }
            };
            var obj = new CircularStack(arr);

            obj.Pop();

            Assert.Throws <InvalidOperationException>(() => obj.Pop());
        }
        public void Pop_Should_Work_When_ItemDropped()
        {
            var obj = new CircularStack(2);

            obj.Push("a");
            obj.Push("b");
            obj.Push("c");

            Assert.AreEqual("c", obj.Pop());
            Assert.AreEqual("b", obj.Pop());
            Assert.Throws <InvalidOperationException>(() => obj.Pop());
        }
        public void Pop_Should_Work_When_StackIsInitializedFromCollection()
        {
            var arr = new List <string> {
                "a", "b", "c", "d"
            };
            var obj = new CircularStack(arr);

            Assert.AreEqual("d", obj.Pop());
            Assert.AreEqual("c", obj.Pop());
            Assert.AreEqual("b", obj.Pop());
            Assert.AreEqual("a", obj.Pop());
        }
Esempio n. 4
0
        public void Count01()
        {
            var cq = new CircularStack <int>(4);

            Assert.AreEqual(0, cq.Count());
            cq.Push(1);
            cq.Push(1);
            Assert.AreEqual(2, cq.Count());
            cq.Pop();
            Assert.AreEqual(1, cq.Count());
            cq.Pop();
            Assert.AreEqual(0, cq.Count());
        }
Esempio n. 5
0
        public void Pop01()
        {
            var capacity = 4;
            var cq       = new CircularStack <int>(capacity);

            for (int i = 0; i < capacity; i++)
            {
                cq.Push(i);
            }
            for (int i = 0; i < capacity; i++)
            {
                Assert.AreEqual(capacity - (i + 1), cq.Pop());
                Assert.AreEqual(capacity - (i + 1), cq.Count());
            }
            Assert.Throws <InvalidOperationException>(() => cq.Pop());
        }
        public void Pop_Should_Work_When_ItemDroppedAndInitializedFromCollectionAndCapacity()
        {
            var items = new List <string> {
                "a", "b", "c"
            };
            var obj = new CircularStack <string>(items, 4);

            obj.Push("d");
            obj.Push("e");
            obj.Push("f");

            Assert.AreEqual("f", obj.Pop());
            Assert.AreEqual("e", obj.Pop());
            Assert.AreEqual("d", obj.Pop());
            Assert.AreEqual("c", obj.Pop());
            Assert.Throws <InvalidOperationException>(() => obj.Pop());
        }
Esempio n. 7
0
        public void IsEmpty01()
        {
            var cq = new CircularStack <int>(1);

            Assert.IsTrue(cq.IsEmpty());
            cq.Push(1);
            Assert.IsFalse(cq.IsEmpty());
            cq.Pop();
            Assert.IsTrue(cq.IsEmpty());
        }
Esempio n. 8
0
 void DoRewind()
 {
     //Debug.Log("Doing Rewind");
     if (!isRewindPressed || storedPositions.GetSize() <= 0)
     {
         StopRewind();
         return;
     }
     playerTransform.position = storedPositions.Pop();
 }
        public void Pop_ShouldNot_ChangeCapacity()
        {
            var arr = new List <object> {
                new { }, new { }
            };
            var obj = new CircularStack(arr);

            obj.Pop();

            Assert.AreEqual(2, obj.Capacity);
        }
        public void Pop_Should_RemoveItem_When_ThereIsOnlyOne()
        {
            var arr = new List <string> {
                "a"
            };
            var obj = new CircularStack(arr);

            obj.Pop();

            Assert.AreEqual(0, obj.Count);
        }
Esempio n. 11
0
        public void Redo()
        {
            if (backup.Count == 0)
            {
                return;
            }

            var storyItem = backup.Pop();

            CommandList[storyItem.Key].Redo(storyItem.Value);
            history.Push(storyItem);
        }
        public void Pop_Should_RemoveItem()
        {
            var arr = new List <string> {
                "a", "b"
            };
            var obj = new CircularStack <string>(arr);

            obj.Pop();

            Assert.AreEqual(1, obj.Count);
            obj.ShouldContainElementsInOrder("a");
        }
        public void Pop_Should_ReturnItem_When_ThereIsOnlyOne()
        {
            var expected = "a";
            var arr      = new List <string> {
                "a"
            };
            var obj = new CircularStack(arr);

            var actual = obj.Pop();

            Assert.AreSame(expected, actual);
        }
        public void Pop_Should_ReturnItem()
        {
            var expected = "b";
            var arr      = new List <string> {
                "a", "b"
            };
            var obj = new CircularStack(arr);

            var actual = obj.Pop();

            Assert.AreSame(expected, actual);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var items = new List <string> {
                "a", "b", "2", "1"
            };
            var stack = new CircularStack(items);

            $"initial state: {stack.GetState()}".Dump();

            stack.Push("c");
            $"push('c') state: {stack.GetState()}".Dump();

            stack.Push("d");
            $"push('d') state: {stack.GetState()}".Dump();

            $"pop() yields: {stack.Pop()}".Dump();
            $"pop() state: {stack.GetState()}".Dump();

            $"pop() yields: {stack.Pop()}".Dump();
            $"pop() state: {stack.GetState()}".Dump();
        }
Esempio n. 16
0
        public void Undo()
        {
            if (history.Count == 0)
            {
                return;
            }

            var storyItem = history.Pop();

            CommandList[storyItem.Key].Undo(storyItem.Value);
            backup.Push(storyItem);
        }
Esempio n. 17
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal object Redo()
        {
            var img = HistoryRedo.Pop();

            if (img is Image)
            {
                HistoryUndo.Push(imgEditor.Image);
                imgEditor.Image = img;
            }
            Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.Undo, HistoryUndo.Count > 1));
            Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.Redo, HistoryRedo.Count > 0));
            return(true);
        }
Esempio n. 18
0
        public void PushPop01()
        {
            var capacity = 4;
            var cq       = new CircularStack <int>(capacity);

            cq.Push(0);
            cq.Push(1);
            cq.Push(2);
            cq.Push(3);
            cq.Pop();
            cq.Pop();
            Assert.AreEqual(1, cq.Peek());
            Assert.AreEqual(0, cq.PeekBottom());
            cq.Push(4);
            cq.Push(5);
            Assert.AreEqual(5, cq.Peek());
            Assert.AreEqual(0, cq.PeekBottom());
            cq.Push(6);
            cq.Push(7);
            Assert.AreEqual(7, cq.Peek());
            Assert.AreEqual(4, cq.PeekBottom());
        }
        public void Pop_Should_WorkAfterPush()
        {
            var expected = "k";
            var arr      = new List <string> {
                "a", "b", "d"
            };
            var obj = new CircularStack <string>(arr);

            obj.Push(expected);
            var actual = obj.Pop();

            Assert.AreSame(expected, actual);
            obj.ShouldContainElementsInOrder("d", "b");
        }
        public void Push_Should_WorkAfterPop()
        {
            var expected = "c";
            var arr      = new List <string> {
                "a", "b", "d"
            };
            var obj = new CircularStack <string>(arr);

            obj.Pop();
            obj.Push(expected);

            Assert.AreSame(expected, obj.Peek());
            obj.ShouldContainElementsInOrder("c", "b", "a");
        }