public void RandomTests()
        {
            const int _NUM_ITERATIONS = 100;
            const int _MIN_INSERTS = 10;
            const int _MAX_INSERTS = 100;

            var rand = new Random();

            for(var i = 0; i < _NUM_ITERATIONS; i++)
            {
                var s = new StackMin<int>();
                int min = int.MaxValue;

                for(var j = 0; j < rand.Next(_MIN_INSERTS, _MAX_INSERTS); j++)
                {
                    var num = rand.Next(int.MinValue, int.MaxValue);

                    if(num < min)
                    {
                        min = num;
                    }

                    s.Push(num);

                    Assert.AreEqual(min, s.Minimum);
                }
            }
        }
        public void SortedTests()
        {
            var s = new StackMin<int>();

            for(var i = 10; i >= 0; i--)
            {
                s.Push(i);
                Assert.AreEqual(i, s.Minimum);
            }
        }
Exemplo n.º 3
0
        public void Push_An_Element()
        {
            var stack = new StackMin();

            stack.Push(10);

            Assert.Equal(1, stack.Length);
            Assert.Equal(10, stack.Top.Value);
            Assert.Equal(10, stack.Bottom.Value);
            Assert.Equal(10, stack.Min());
        }
Exemplo n.º 4
0
        public void TestStackMin()
        {
            StackMin minStack = new StackMin();

            minStack.Push(2);
            minStack.Push(6);
            minStack.Push(7);
            minStack.Push(3);

            Assert.Equal(2, minStack.Min());
        }
Exemplo n.º 5
0
        public void Stack_Is_Empty()
        {
            var stack = new StackMin();

            var isEmpty = stack.IsEmpty();

            Assert.True(isEmpty);
            Assert.Equal(0, stack.Length);
            Assert.Null(stack.Top);
            Assert.Null(stack.Bottom);
            Assert.Equal(int.MaxValue, stack.Min());
        }
Exemplo n.º 6
0
        public void Peek_An_Element_In_A_Stack_With_No_Element()
        {
            var stack = new StackMin();

            var item = stack.Peek();

            Assert.Equal(0, item);
            Assert.Equal(0, stack.Length);
            Assert.Null(stack.Top);
            Assert.Null(stack.Bottom);
            Assert.Equal(int.MaxValue, stack.Min());
        }
        public void StackMinTest(StackNode <int>[] list, int expected)
        {
            //StackMin.DuplicateRemoval(input);
            StackMin <int> smin = new StackMin <int>();

            foreach (var item in list)
            {
                smin.Push(item);
            }
            var min = smin.Min();

            Assert.Equal(expected, min.smallest);
        }
Exemplo n.º 8
0
        public void Stack_Is_Not_Empty()
        {
            var stack = new StackMin();

            stack.Push(10);
            var isEmpty = stack.IsEmpty();

            Assert.False(isEmpty);
            Assert.Equal(1, stack.Length);
            Assert.NotNull(stack.Top);
            Assert.NotNull(stack.Bottom);
            Assert.Equal(10, stack.Min());
        }
Exemplo n.º 9
0
        public void Pop_An_Element_In_A_Stack_With_One_Element()
        {
            var stack = new StackMin();

            stack.Push(20);

            var item = stack.Pop();

            Assert.Equal(20, item);
            Assert.Equal(0, stack.Length);
            Assert.Null(stack.Top);
            Assert.Null(stack.Bottom);
            Assert.Equal(int.MaxValue, stack.Min());
        }
Exemplo n.º 10
0
        public void Peek_Element_In_A_Stack_With_One_Element()
        {
            var stack = new StackMin();

            stack.Push(20);

            var item = stack.Peek();

            Assert.Equal(20, item);
            Assert.Equal(1, stack.Length);
            Assert.Equal(20, stack.Top.Value);
            Assert.Equal(20, stack.Bottom.Value);
            Assert.Equal(20, stack.Min());
        }
Exemplo n.º 11
0
        public void Pop_An_Element_In_A_Stack_With_Two_Elements()
        {
            var stack = new StackMin();

            stack.Push(10);
            stack.Push(20);

            var item = stack.Pop();

            Assert.Equal(20, item);
            Assert.Equal(1, stack.Length);
            Assert.Equal(10, stack.Top.Value);
            Assert.Equal(10, stack.Bottom.Value);
            Assert.Equal(10, stack.Min());
        }
Exemplo n.º 12
0
        public void Push_Three_Elements()
        {
            var stack = new StackMin();

            stack.Push(10);
            Assert.Equal(10, stack.Min());

            stack.Push(20);
            Assert.Equal(10, stack.Min());

            stack.Push(30);
            Assert.Equal(10, stack.Min());

            Assert.Equal(3, stack.Length);
            Assert.Equal(30, stack.Top.Value);
            Assert.Equal(10, stack.Bottom.Value);
        }
Exemplo n.º 13
0
 public void Initialize()
 {
     stack   = new StackMin();
     fixture = new Fixture();
 }