Ejemplo n.º 1
0
        public void Should_Check_Is_Empty_False()
        {
            //arrange
            var stack = new MyArrayStack <int>(new[] { 1 });

            //act
            var result = stack.IsEmpty();

            //assert
            result.ShouldBeEquivalentTo(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 基于数组的栈的测试
        /// </summary>
        static void StackWithArrayTest()
        {
            MyArrayStack <int> stack = new MyArrayStack <int>(10);

            Console.WriteLine(stack.IsEmpty());

            Random rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                stack.Push(rand.Next(1, 10));
            }
            Console.WriteLine("IsEmpty:{0}", stack.IsEmpty());
            Console.WriteLine("Size:{0}", stack.Size);
            Console.WriteLine("-------------------------------");

            for (int i = 0; i < 10; i++)
            {
                int node = stack.Pop();
                Console.Write(node + " ");
            }
            Console.WriteLine();
            Console.WriteLine("IsEmpty:{0}", stack.IsEmpty());
            Console.WriteLine("Size:{0}", stack.Size);
            Console.WriteLine("-------------------------------");

            for (int i = 0; i < 15; i++)
            {
                stack.Push(rand.Next(1, 15));
            }
            for (int i = 0; i < 15; i++)
            {
                int node = stack.Pop();
                Console.Write(node + " ");
            }
            Console.WriteLine();
        }