public void TestStackAddElements()
 {
     Stack testStack = new Stack();
     testStack.Push(10);
     testStack.Push(10);
     testStack.Push(10);
     testStack.Push(10);
     Assert.AreEqual(4, testStack.Size(), "The size is not calculated correctly");
 }
示例#2
0
        public void Count_PushSeveralPopAll_ReturnZero()
        {
            Stack target = new Stack();
            //Push several items
            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");
            target.Push("g");

            //Pop all items
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();

            int expected = 0;
            int actual = target.Count();

            Assert.AreEqual(expected, actual);
        }
        protected void btnPush_Click(object sender, EventArgs e)
        {
            Stack1 =(Stack)ViewState["Stack1"];
            int? PushedItem = Stack1.Push(Convert.ToInt32(txtPush.Text));
            Response.Write(Stack1.Top);
            ViewState["Stack1"] = Stack1;
            txtPush.Text = string.Empty;
            //------------------------------------------

            lblDisplay.Text = "Pushed item is " + PushedItem.ToString();
        }
示例#4
0
        public void Count_PushOneItem_ReturnOne()
        {
            Stack target = new Stack();

            target.Push("a");

            int expected = 1;
            int actual = target.Count();

            Assert.AreEqual(expected, actual);
        }
        public void TestStackResize()
        {
            Stack testStack = new Stack();
            int numberOfAddedElements = 12;

            for (int i = 0; i < numberOfAddedElements; i++)
            {
                testStack.Push(10);
            }

            Assert.AreEqual(numberOfAddedElements, testStack.Size(), "The size is not calculated correctly");
        }
        public static void Main()
        {
            Stack<int> testStack = new Stack<int>();

            testStack.Push(5);
            testStack.Push(4);
            testStack.Push(3);
            testStack.Push(2);
            testStack.Pop();

            foreach (var item in testStack)
            {
                Console.WriteLine("Item value: {0}", item);
            }

            Console.WriteLine("Stack items count: {0}", testStack.Count);
            Console.WriteLine("Stack capacity: {0}", testStack.Capacity);

            testStack.Push(6);
            testStack.Push(7);

            Console.WriteLine(new string('-', 15));
            Console.WriteLine("After adding 2 more items");
            Console.WriteLine("Stack items count: {0}", testStack.Count);
            Console.WriteLine("Stack capacity: {0}", testStack.Capacity);
        }
        public void TestStackValues()
        {
            Stack testStack = new Stack();
            int numberOfAddedElements = 12;

            for (int i = 0; i < numberOfAddedElements; i++)
            {
                testStack.Push(10 + i);
            }

            for (int i = 0; i < numberOfAddedElements; i++)
            {
                int currentElement = testStack.Pop();
                Assert.AreEqual(21 - i, currentElement, "The elements are not being popped correctly");
            }
        }
示例#8
0
        public void Count_PushSevenItems_ReturnSeven()
        {
            Stack target = new Stack();

            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");
            target.Push("g");

            int expected = 7;
            int actual = target.Count();

            Assert.AreEqual(expected,actual);
        }
示例#9
0
        public void IsEmpty_CalledOnNonEmptyStack_ReturnFalse()
        {
            Stack target = new Stack();
            //Push several items
            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");
            target.Push("g");

            Boolean expected = false;
            Boolean actual = target.IsEmpty();

            Assert.AreEqual(expected, actual);
        }
示例#10
0
        public void IsEmpty_PushSeveralAndPopAll_ReturnTrue()
        {
            Stack target = new Stack();
            //Push several items
            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");
            target.Push("g");

            //Pop all items
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();
            target.Pop();

            Boolean expected = true;
            Boolean actual = target.IsEmpty();

            Assert.AreEqual(expected, actual);
        }
示例#11
0
        public void Push_OneItemOnNewStackCallPeek_ReturnItem()
        {
            Stack target = new Stack();
            String testItem = "MyApplesAreBad";

            target.Push(testItem);

            String expected = testItem;
            String actual = target.Peek();

            Assert.AreEqual(expected, actual);
        }
示例#12
0
        public void Pop_PushSeveralItemsPopOne_ReturnLastItem()
        {
            Stack target = new Stack();

            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");

            String expected = "f";
            String actual = target.Pop();

            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void Pop_PushSeveralItemsPopOneAndCount_ReturnNMinusOne()
        {
            Stack target = new Stack();

            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");
            target.Push("e");
            target.Push("f");

            target.Pop();

            int expected = 5;
            int actual = target.Count();

            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void Pop_PushOneItemPop_ReturnLastItem()
        {
            Stack target = new Stack();
            String testItem="My apples are bad";

            target.Push(testItem);

            String expected = testItem;
            String actual = target.Pop();

            Assert.AreEqual(expected, actual);
        }
示例#15
0
        public void Pop_PushOneItemPopCount_ReturnZero()
        {
            Stack target = new Stack();
            String testItem = "My apples are bad";

            target.Push(testItem);
            target.Pop();

            int expected = 0;
            int actual = target.Count();

            Assert.AreEqual(expected, actual);
        }
示例#16
0
        public void Push_SeveralItemsStackCallCount_ReturnItemCount()
        {
            Stack target = new Stack();

            target.Push("a");
            target.Push("b");
            target.Push("c");
            target.Push("d");

            int expected = 4;
            int actual = target.Count();

            Assert.AreEqual(expected, actual);
        }
示例#17
0
        public void IsEmpty_CalledOnStackWithOneItem_ReturnFalse()
        {
            Stack target = new Stack();

            target.Push("a");

            Boolean expected = false;
            Boolean actual = target.IsEmpty();

            Assert.AreEqual(expected, actual);
        }