Beispiel #1
0
        public void PopAfterPush()
        {
            var stack = new LimitedSizeStack <int>(20);

            stack.Push(0);
            stack.Push(1);
            stack.Push(2);
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Pop());
            Assert.AreEqual(0, stack.Pop());
        }
Beispiel #2
0
        public void PushAfterEmptyStack()
        {
            var stack = new LimitedSizeStack <int>(20);

            stack.Push(0);
            stack.Push(1);
            stack.Pop();
            stack.Pop();
            stack.Push(2);
            Assert.AreEqual(2, stack.Pop());
        }
        public void PopPushAfterLimitReached()
        {
            var stack = new LimitedSizeStack <int>(2);

            stack.Push(0);
            stack.Push(1);
            stack.Push(2);
            stack.Pop();
            stack.Push(3);
            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(1, stack.Pop());
        }
Beispiel #4
0
 public void Undo()
 {
     if (stackKeys.Pop() == 'r')
     {
         Items.Insert(indexesRemovedItems.Pop(), stackValues.Pop());
     }
     else
     {
         Items.RemoveAt(Items.Count - 1);
         stackValues.Pop();
         indexesRemovedItems.Pop();
     }
 }
Beispiel #5
0
 public void Undo()
 {
     if (CanUndo())
     {
         SizeStack.Pop().Undo();
     }
 }
Beispiel #6
0
        public void ForgetFirstElement_AfterPushBeyondLimit_Twice()
        {
            var stack = new LimitedSizeStack <int>(2);

            stack.Push(0);
            stack.Push(1);
            stack.Push(2);
            stack.Pop();
            stack.Pop(); // empty!
            stack.Push(0);
            stack.Push(10);
            stack.Push(20);
            Assert.AreEqual(2, stack.Count);
            Assert.AreEqual(20, stack.Pop());
            Assert.AreEqual(10, stack.Pop());
        }
Beispiel #7
0
        public void Undo()
        {
            if (CanUndo())
            {
                var action = ActionStack.Pop();
                switch (action)
                {
                case ActionMade.Pushed:
                    Items.Remove(ItemsStack.Pop());
                    IndexStack.Pop();
                    break;

                case ActionMade.Poped:
                    Items.Insert(IndexStack.Pop(), ItemsStack.Pop());
                    break;
                }
            }
        }
        public void Undo()
        {
            if (CanUndo())
            {
                var lastAction = actionsList.Pop();
                switch (lastAction.Item1)
                {
                case Action.AddItem: Items.RemoveAt(lastAction.Item3); break;

                case Action.RemoveItem: Items.Insert(lastAction.Item3, lastAction.Item2); break;
                }
            }
        }
Beispiel #9
0
        public void Undo()
        {
            var value = Events.Pop();

            if (value.Item3)
            {
                Items.RemoveAt(value.Item2);
            }
            else
            {
                Items.Insert(value.Item2, value.Item1);
            }
        }
        public void Undo()
        {
            var lastAction = storyAction.Pop();

            switch (lastAction.Item1)
            {
            case TypeAction.AddItem:
                Items.RemoveAt(storyAction.Count);
                break;

            case TypeAction.RemoveItem:
                Items.Insert(lastAction.Item3, lastAction.Item2);
                break;
            }
        }
Beispiel #11
0
        public void Undo()
        {
            var prevAction = stack.Pop();

            switch (prevAction.Action)
            {
            case Command.Remove:
                Items.Insert(prevAction.Index, prevAction.Value);
                break;

            case Command.Add:
                Items.RemoveAt(prevAction.Index);
                break;
            }
        }
Beispiel #12
0
 public void Undo()
 {
     if (executeList.Count != 0)
     {
         var result = executeList.Pop();
         if (result.action == ActionEx.Add)
         {
             Items.RemoveAt(result.Index);
         }
         else if (result.action == ActionEx.Remove)
         {
             Items.Insert(result.Index, result.Item);
         }
     }
 }
Beispiel #13
0
        public void Undo()
        {
            var lastActoin = actionStory.Pop();

            switch (lastActoin.Item1)
            {
            case ActionType.AddItem:
                Items.RemoveAt(actionStory.Count);
                break;

            case ActionType.RemoveItem:
                Items.Insert(lastActoin.Item3, lastActoin.Item2);
                break;
            }
        }
Beispiel #14
0
        public void Undo()
        {
            var undoAction = lastActions.Pop();

            // Если последнее событие это удаление, то возращаем дело обратно
            if (undoAction.Item1)
            {
                Items.Add(undoAction.Item2);
            }
            // Если добавление, то удаляем
            else
            {
                Items.Remove(undoAction.Item2);
            }
        }
Beispiel #15
0
        public void Pop_ShouldTakeConstantTime()
        {
            int limit = 200000;
            var stack = new LimitedSizeStack <int>(limit);

            for (int i = 0; i < limit; ++i)
            {
                stack.Push(0);
            }
            Assert.AreEqual(limit, stack.Count);
            for (int i = 0; i < limit; ++i)
            {
                stack.Pop();
            }
            Assert.AreEqual(0, stack.Count);
        }
Beispiel #16
0
        public void Undo()
        {
            if (CanUndo())
            {
                var operation = _historyOperations.Pop();
                var item      = _historyItems.Pop();
                var index     = _historyIndex.Pop();
                if (operation == '+')
                {
                    Items.RemoveAt(index);
                }
                if (operation == '-')
                {
                    Items.Insert(index, item);
                }
            }

            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #17
0
 public void Undo() => backup.Pop().Undo();
Beispiel #18
0
 public void Undo()
 {
     commands.Pop().Undo();
 }
 public void UndoCommand()
 {
     _commandHistory.Pop().UnDo();
 }
        public void Undo()
        {
            var commandToUndo = commandStack.Pop();

            commandToUndo.Undo();
        }