public void TestSort([Values] SortType sortType, [Values] InitType initType)
        {
            Action <int[]> sortFunc = sortType switch
            {
                SortType.Merge => Sorts.MergeSort,
                SortType.Quick => Sorts.QuickSort,
                SortType.Radix => Sorts.RadixSort,
                _ => throw new ArgumentException("Unknown SortType"),
            };

            var array = initType switch
            {
                InitType.Empty => new int[] { },
                InitType.Single => new int[] { 1 },
                InitType.Asc => new int[] { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 },
                InitType.Desc => new int[] { 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 },
                InitType.Mixed => new int[] { 0, 2, -2, 5, -4, 1, 3, -1, -3, 4, -5 },
                _ => throw new ArgumentException("Unknown InitType"),
            };

            var expected = new ControlList(typeof(SortedArrayList));

            expected.Initialize(array);

            sortFunc(array);

            Assert.AreEqual(expected.ToString(), $"[{string.Join(',', array)}]");
        }
Exemple #2
0
        // Note: ToString() is tested implicitly by Check()

        private (ITestCollection, ITestCollection) Startup(TestableType testableType, InitType initType)
        {
            var initial = initType switch
            {
                InitType.Empty => new int[] { },
                InitType.Single => new int[] { 1 },
                InitType.Asc => new int[] { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 },
                InitType.Desc => new int[] { 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 },
                InitType.Mixed => new int[] { 0, 2, -2, 5, -4, 1, 3, -1, -3, 4, -5 },
                _ => throw new ArgumentException("Unknown InitType"),
            };

            ITestCollection collection = testableType switch
            {
                TestableType.ArrayList => new ArrayList(),
                TestableType.SortedArrayList => new SortedArrayList(),
                TestableType.LinkedList => new LinkedList(),
                TestableType.ArrayStack => new ArrayStack(),
                TestableType.LinkedQueue => new LinkedQueue(),
                TestableType.BinarySearchTree => new BinarySearchTree(),
                _ => throw new ArgumentException("Unknown TestableType"),
            };

            var expected = new ControlList(collection.GetType());

            expected.Initialize(initial);
            collection.Initialize(initial);

            Check(expected, collection);
            return(expected, collection);
        }