Esempio n. 1
0
        private static void Validate <T>(Stack <T> stack)
            where T : IComparable <T>
        {
            var cloneStack = new Stack <T>(stack);

            Question_3_5.SortStack(cloneStack);
            ValidateOrder(cloneStack);
        }
Esempio n. 2
0
        public void SortStackTest(int[] testNumbers)
        {
            var testStack       = TestHelper.ConvertArrayToStack(testNumbers);
            var expectedNumbers = testNumbers.OrderByDescending(x => x).ToArray();
            var expectedStack   = TestHelper.ConvertArrayToStack(expectedNumbers);
            var resultStack     = Question_3_5.SortStack(testStack);

            Assert.AreEqual(expectedStack.Count, resultStack.Count, "Stack counts do not match.");
            while (resultStack.Count > 0)
            {
                Assert.AreEqual(expectedStack.Pop(), resultStack.Pop(), $"Stacks are not equal at position {resultStack.Count}.");
            }
        }
Esempio n. 3
0
        public void Question_3_5_InvalidCases()
        {
            Stack <int> s = null;

            TestHelpers.AssertExceptionThrown(() => Question_3_5.SortStack(s), typeof(ArgumentNullException));
        }