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);
        }
コード例 #2
0
        public void MaxStack_NothingInStack_GetMax_ThrowsException()
        {
            // Arrange
            MaxStack maxStack = new MaxStack();
            // Act
            Action action = () => maxStack.GetMax();

            // Assert
            Assert.ThrowsException <Exception>(action, stackEmptyMessage);
        }
コード例 #3
0
        public void MaxStackTest()
        {
            MaxStack ms = new MaxStack();

            ms.mPush(3);
            ms.mPush(11);
            ms.mPop();
            ms.mPush(4);
            ms.mPush(6);
            ms.mPop();
            ms.mPush(2);
            ms.mPop();

            Assert.Equal(ms.GetMax(), 4);
        }
コード例 #4
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());
        }