예제 #1
0
        public void Count()
        {
            MyStack C = new MyStack(3);

            C.Push("4");
            C.Push("5");
            Assert.AreEqual(2, C.Count());
        }
예제 #2
0
        public void clear()
        {
            MyStack C = new MyStack(3);

            C.Push("4");
            C.Push("5");
            C.clear();
            Assert.AreEqual(0, C.Count());
        }
예제 #3
0
        public void TestStack()
        {
            Stack <int>   stdStack = new Stack <int>();   // standard queue implemented by .NET
            MyStack <int> ourStack = new MyStack <int>(); // our manually implemented stack

            // Test generates 100 random integers and adds to both queues
            Random r = new Random();

            for (int i = 0; i < 100; i++)
            {
                int randVal = r.Next();
                stdStack.Push(randVal);
                ourStack.Push(randVal);
            }

            // Test reading back half the added integers
            for (int i = 0; i < 50; i++)
            {
                Assert.AreEqual(stdStack.Pop(), ourStack.Pop());
                Assert.AreEqual(stdStack.Peek(), ourStack.Peek());
                Assert.AreEqual(stdStack.Count, ourStack.Count());
            }

            // Test adding 50 more random integers
            for (int i = 0; i < 50; i++)
            {
                int randVal = r.Next();
                stdStack.Push(randVal);
                ourStack.Push(randVal);
            }

            // Test reading back all the remaining values
            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(stdStack.Peek(), ourStack.Peek());
                Assert.AreEqual(stdStack.Pop(), ourStack.Pop());
                Assert.AreEqual(stdStack.Count, ourStack.Count());
            }
        }