示例#1
0
        public void ImplementStackWithMaxAPITest()
        {
            StackWithMaxAPI[] stacks = new StackWithMaxAPI[]
            {
                new StackWithMaxIterate(),
                new StackWithMaxCache(),
                new StackWithMaxStack()
            };

            int[] data    = ArrayUtilities.CreateRandomArray(20, 10, 50);
            int[] results = new int[stacks.Length];

            for (int i = 0; i < data.Length; i++)
            {
                for (int j = 0; j < stacks.Length; j++)
                {
                    stacks[j].Push(data[i]);
                    results[j] = stacks[j].Max;
                    Assert.AreEqual(results[0], results[j]);
                }
            }

            for (int i = 0; i < data.Length - 1; i++)
            {
                for (int j = 0; j < stacks.Length; j++)
                {
                    stacks[j].Pop();
                    results[j] = stacks[j].Max;
                    Assert.AreEqual(results[0], results[j]);
                }
            }
        }
示例#2
0
        public void ImplementStackWithMaxAPITest()
        {
            StackWithMaxAPI[] stacks = new StackWithMaxAPI[]
            {
                new StackWithMaxIterate(),
                new StackWithMaxCache(),
                new StackWithMaxStack()
            };

            int[] data = ArrayUtilities.CreateRandomArray(20, 10, 50);
            int[] results = new int[stacks.Length];

            for (int i = 0; i < data.Length; i++)
            {
                for (int j = 0; j < stacks.Length; j++)
                {
                    stacks[j].Push(data[i]);
                    results[j] = stacks[j].Max;
                    Assert.AreEqual(results[0], results[j]);
                }
            }

            for (int i = 0; i < data.Length - 1; i++)
            {
                for (int j = 0; j < stacks.Length; j++)
                {
                    stacks[j].Pop();
                    results[j] = stacks[j].Max;
                    Assert.AreEqual(results[0], results[j]);
                }
            }
        }