Exemple #1
0
        public void FullStackArrayTests0()
        {
            var stackArray = new StackArray <int>(5);

            for (var i = 0; i < 5; i++)
            {
                Assert.True(stackArray.Count == i);
                stackArray.Push(i * 2);
            }
            Assert.True(stackArray.IsFull);
            Assert.False(stackArray.IsEmpty);
            Assert.Throws <InvalidOperationException>(() => stackArray.Push(10));
            Assert.Throws <InvalidOperationException>(() => stackArray.Push(12));
            Assert.True(stackArray.Peek() == 8);
            Assert.True(stackArray.Pop() == 8);
            Assert.True(stackArray.Count == 4);
            Assert.True(stackArray.Length == 5);
            Assert.False(stackArray.IsFull);
            Assert.False(stackArray.IsEmpty);
            stackArray.Push(8);
            Assert.True(stackArray.Peek() == 8);
            Assert.Throws <InvalidOperationException>(() => stackArray.Push(10));
            Assert.True(stackArray.IsFull);
            Assert.False(stackArray.IsEmpty);
            Assert.True(stackArray.Length == 5);
            Assert.True(stackArray.Count == 5);
        }
Exemple #2
0
            public void PeekTest()
            {
                Stack stack = new StackArray();

                stack.Push(5);
                var peek = stack.Peek();

                Assert.IsNotNull(peek);
                Assert.AreEqual(5, peek);
                peek = stack.Peek();
                Assert.IsNotNull(peek);
                Assert.AreEqual(5, peek);
                var pop = stack.Pop();

                Assert.IsNotNull(pop);
                Assert.AreEqual(5, pop);
                peek = stack.Peek();
                Assert.IsNull(peek);
                Assert.IsNull(stack.Pop());
            }
Exemple #3
0
            public void FullTest()
            {
                Stack  stack      = new StackArray(100);
                int    testLength = 512;
                Random rnd        = new Random();

                int[] comparisonArray = new int[testLength];
                for (int i = 0; i < testLength; i++)
                {
                    int element = rnd.Next(0, 10000000);
                    comparisonArray[comparisonArray.Length - i - 1] = element;
                    stack.Push(element);
                }

                for (int i = 0; i < comparisonArray.Length; i++)
                {
                    Assert.AreEqual(comparisonArray[i], stack.Peek());
                    Assert.AreEqual(comparisonArray[i], stack.Pop());
                }
            }