Example #1
0
        public static void Main()
        {
            var numbers = new AutoResizableStack<int>();
            int currentCapacity = numbers.Capacity;

            for (int i = 0; i < 50; i++)
            {
                numbers.Push(i);

                if (currentCapacity != numbers.Capacity)
                {
                    string line = new string('-', 50);
                    Console.WriteLine(line);
                    currentCapacity = numbers.Capacity;
                }

                Console.WriteLine(PrintMessageFormat, numbers.Count.ToString().PadRight(2), numbers.Capacity);
            }

            Console.WriteLine(RemovingMessage);

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(PrintMessageFormat, numbers.Peek(), numbers.Capacity);
                numbers.Pop();
            }
        }
        public void TestPushFuncionality()
        {
            var stack = new AutoResizableStack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            Assert.AreEqual(3, stack.Count);
        }
        public void PeekShouldNotChangeCount()
        {
            var stack = new AutoResizableStack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            Assert.AreEqual(3, stack.Count);
            Assert.AreEqual(3, stack.Peek());
            Assert.AreEqual(3, stack.Count);
        }
        public void TestCountAndCapacity()
        {
            var elementsToAdd = 930;

            var stack = new AutoResizableStack<int>();
            for (int i = 0; i < elementsToAdd; i++)
            {
                stack.Push(i);
            }

            Assert.AreEqual(elementsToAdd, stack.Count);
            Assert.AreEqual(1024, stack.Capacity);
        }
Example #5
0
        public static void Main()
        {
            int a = 2;
            Console.WriteLine(a.GetHashCode());
            AutoResizableStack<int> theStack = new AutoResizableStack<int>();
            theStack.Add(1);
            theStack.Add(2);
            theStack.Add(3);
            theStack.Add(55);
            theStack.Add(55);

            Console.WriteLine("Count of elements {0}", theStack.Count);
            Console.WriteLine("Full length {0}", theStack.LongLength);
        }
 public void TestPopFunctionalityOnEmptyStackShouldThrowException()
 {
     var stack = new AutoResizableStack<int>();
     stack.Pop();
 }