public void GetMaxFromStack()
        {
            //[6] => getMax() => 6
            //[6, 10] => getMax() => 10
            //[6, 10, 10] => getMax() => 10
            //[6, 10, 10, 4] => getMax() => 10

            var stack = new MaxStack();

            stack.Push(6);
            var max = stack.GetMax();

            Assert.AreEqual(max, 6);
            stack.Push(10);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Push(10);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Push(4);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 6);
        }
Beispiel #2
0
        public void PushMoreThenMax_ExcessIsLost()
        {
            var ms = new MaxStack <string>(2);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            Assert.AreEqual("3", ms.Pop());
            Assert.AreEqual("2", ms.Pop());
            Assert.IsNull(ms.Peek());
        }
Beispiel #3
0
 void DoUndo()
 {
     if (undoinputfieldstack.Count >= 2)
     {
         undoinputfieldstack.Pop();
         redoinputfieldstack.Push(CodeInputField.text);
         CodeInputField.text = undoinputfieldstack.Pop();
         CodeInputField.Select();
         recordtimer = undorecorddelay;
     }
 }
Beispiel #4
0
        public void Grow_AddSpaceAtEnd()
        {
            var ms = new MaxStack <int>(2);

            ms.Push(1);
            ms.Push(2);
            ms.Grow(0.5f);
            Assert.AreEqual(3, ms.MaxSize);
            Assert.AreEqual(2, ms.Pop());
            Assert.AreEqual(1, ms.Pop());
            Assert.AreEqual(0, ms.Peek());
        }
Beispiel #5
0
        public void RemoveItem_GivesCorrectSequence()
        {
            var ms = new MaxStack <string>(3);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            ms.Remove("2");
            Assert.AreEqual("3", ms.Pop());
            Assert.AreEqual("1", ms.Pop());
            Assert.IsNull(ms.Peek());
        }
Beispiel #6
0
        public void Push_Pop_Peek_All_CorrectItem()
        {
            var ms = new MaxStack <int>(5);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            Assert.AreEqual(3, ms.Peek());
            Assert.AreEqual(3, ms.Pop());
            Assert.AreEqual(2, ms.Peek());
            Assert.AreEqual(2, ms.Pop());
            Assert.AreEqual(1, ms.Peek());
            Assert.AreEqual(1, ms.Pop());
        }
Beispiel #7
0
        public void Shrink_ExcessIsLost()
        {
            var ms = new MaxStack <int>(4);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            ms.Push(4);
            ms.Shrink(0.5f);
            Assert.AreEqual(2, ms.MaxSize);
            Assert.AreEqual(4, ms.Pop());
            Assert.AreEqual(3, ms.Pop());
            Assert.AreEqual(0, ms.Peek());
        }
Beispiel #8
0
 public static void RunTests()
 {
     MaxStack stack = new MaxStack();
     stack.Push(5);
     stack.Push(0);
     stack.Push(-10);
     Console.WriteLine(stack.Max());
     stack.Push(12);
     Console.WriteLine(stack.Max());
     stack.Push(15);
     Console.WriteLine(stack.Max());
     stack.Pop();
     stack.Pop();
     Console.WriteLine(stack.Max());
 }
        public void Max_WhenCalled_Returns_Maximum_Value()
        {
            var stack = new MaxStack <int>();

            var list = new List <int> {
                1, 8, 44, 44, 3, 9, 2, 20, 12, 10, 4, 50, -70, 100, 99, 0, 8, 45
            };

            var max = list[0];

            for (var i = 0; i < list.Count; i++)
            {
                if (list[i] > max)
                {
                    max = list[i];
                }

                stack.Push(list[i]);
                Assert.AreEqual(max, stack.Max());
            }

            for (var i = list.Count - 1; i >= 0; i--)
            {
                Assert.AreEqual(list.Max(), stack.Max());

                stack.Pop();
                list.RemoveAt(i);
            }
        }
Beispiel #10
0
        public void Run()
        {
            MaxStack<int> stack = new MaxStack<int>();
            string command = null;
            Console.Write("Enter a command:");
            while (!string.IsNullOrEmpty(command = Console.ReadLine()))
            {
                string[] tokens = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    if (tokens[0] == "p")
                    {
                        stack.Push(int.Parse(tokens[1]));
                    }
                    else if (tokens[0] == "x")
                    {
                        if (stack.Count == 0) Console.WriteLine("Stack empty");
                        else Console.WriteLine("Popped {0}", stack.Pop());
                    }
                    else if (tokens[0] == "m")
                    {
                        if (stack.Count == 0) Console.WriteLine("Stack empty");
                        else Console.WriteLine("Max is {0}", stack.Max);
                    }
                }
                catch(Exception)
                {
                    Console.WriteLine("Bad Command");
                }
                Console.Write("Enter a command:");
            }
        }
Beispiel #11
0
    public static void RunTests()
    {
        MaxStack stack = new MaxStack();

        stack.Push(5);
        stack.Push(0);
        stack.Push(-10);
        Console.WriteLine(stack.Max());
        stack.Push(12);
        Console.WriteLine(stack.Max());
        stack.Push(15);
        Console.WriteLine(stack.Max());
        stack.Pop();
        stack.Pop();
        Console.WriteLine(stack.Max());
    }
Beispiel #12
0
    /// <summary>
    /// Extrae el ultimo memento
    /// </summary>
    /// <returns>El ultimo memento o null si no hay ninguno</returns>
    public GridMemento Pop()
    {
        if (_stack.Count == 0)
        {
            return(null);
        }

        return(_stack.Pop());
    }
Beispiel #13
0
        public void MaxStack_NothingInStack_Pop_ThrowsException()
        {
            // Arrange
            MaxStack maxStack = new MaxStack();
            // Act
            Action action = () => maxStack.Pop();

            // Assert
            Assert.ThrowsException <EmptyStackException>(action, stackEmptyMessage);
        }
Beispiel #14
0
 void DoRedo()
 {
     if (redoinputfieldstack.Count >= 1)
     {
         record = false;
         CodeInputField.text = redoinputfieldstack.Pop();
         CodeInputField.Select();
         undoinputfieldstack.Push(CodeInputField.text);
     }
 }
Beispiel #15
0
        public void MaxStackTest()
        {
            var s = new MaxStack();

            s.Push(5);
            Assert.AreEqual(5, s.GetMax());
            s.Push(4);
            s.Push(7);
            s.Push(7);
            s.Push(8);
            Assert.AreEqual(8, s.GetMax());
            Assert.AreEqual(8, s.Pop());
            Assert.AreEqual(7, s.GetMax());
            Assert.AreEqual(7, s.Pop());
            Assert.AreEqual(7, s.GetMax());
            Assert.AreEqual(7, s.Pop());
            Assert.AreEqual(5, s.GetMax());
            Assert.AreEqual(4, s.Pop());
            Assert.AreEqual(5, s.GetMax());
        }
Beispiel #16
0
        public void SetSize_ExcessIsLost()
        {
            var ms = new MaxStack <int>(4);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            ms.Push(4);
            ms.MaxSize = 1;
            Assert.AreEqual(1, ms.MaxSize);
            Assert.AreEqual(4, ms.Pop());
        }
Beispiel #17
0
        protected override void Run()
        {
            MaxStack <int> stack = new MaxStack <int>();

            stack.Push(5);
            stack.Push(3);
            stack.Push(18);
            Console.WriteLine("Assert max = 18: {0}.", stack.Max() == 18);
            int value = stack.Pop();

            Console.WriteLine("Assert pop = 18: {0}.", value == 18);
            Console.WriteLine("Assert max = 5: {0}.", stack.Max() == 5);
        }
Beispiel #18
0
        public void MaxStack_PushThreeIntegers_Pop_PopReturnsLast()
        {
            // Arrange
            int      expectedInt = 5;
            MaxStack maxStack    = new MaxStack();

            // Act
            maxStack.Push(1);
            maxStack.Push(-2);
            maxStack.Push(expectedInt);
            // Assert
            Assert.AreEqual(expectedInt, maxStack.Pop());
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            var stack = new MaxStack();

            //stack.Push(5);
            stack.Push(1);
            stack.Push(5);
            stack.Push(3);
            stack.Top();
            stack.PopMax();
            stack.Top();
            stack.PeekMax();
            stack.Pop();
            stack.Top();

            Console.WriteLine();
        }
Beispiel #20
0
        public void MaxStack()
        {
            MaxStack node = new MaxStack();

            node.Push(1);
            node.Push(5);
            node.Push(2);

            node.Push(10);

            node.Pop();

            int actual   = node.Max();
            int expected = 5;

            Assert.AreEqual(actual, expected);
        }
Beispiel #21
0
    public void Redo()
    {
        Dictionary <GameObject, UndoRedoState> groupToRedo = redoStack.Pop();

        if (groupToRedo == null)
        {
            return;
        }
        undoStack.Push(groupToRedo);
        foreach (KeyValuePair <GameObject, UndoRedoState> pair in groupToRedo)
        {
            if (UndoRedoState.Instantiated.Equals(pair.Value))
            {
                pair.Key.gameObject.SetActive(true);
            }
            else if (UndoRedoState.Destroyed.Equals(pair.Value))
            {
                pair.Key.gameObject.SetActive(false);
            }
        }
    }
Beispiel #22
0
        public void Pop_WhenEmpty_throwsInvalidOperationException()
        {
            var ms = new MaxStack <string>(5);

            ms.Pop();
        }