Ejemplo n.º 1
0
 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");
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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");
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }