Exemplo n.º 1
0
        private static bool Test5(ISortingAlgorithm sort)
        {
            string testname = sort.GetSortName() + " Test 5";

            int[] arr1 = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // array to check
            return(Test(testname, sort, arr1));
        }
Exemplo n.º 2
0
        private static bool Test6(ISortingAlgorithm sort)
        {
            string testname = sort.GetSortName() + " Test 6";

            int[] arr1 = new int[] { 564, 854, 789, 513, 156, 758, 756, 958, 3215 }; // array to check
            return(Test(testname, sort, arr1));
        }
Exemplo n.º 3
0
        private static bool Test4(ISortingAlgorithm sort)
        {
            string testname = sort.GetSortName() + " Test 4";

            int[] arr1 = new int[] { 5, 5, 5, 5, 5, 5, 5, 5, 5 }; // array to check
            return(Test(testname, sort, arr1));
        }
Exemplo n.º 4
0
        private static bool TestRandom(ISortingAlgorithm sort)
        {
            int    nFrom    = 0;
            int    nTo      = 100;
            Random rand     = new Random();
            int    numTests = sort.numberOfTests;
            int    n        = 0;

            double[] arr;
            int[]    arr1;
            string   testname = sort.GetSortName() + " Test";

            for (int i = 0; i < numTests; i++)
            {
                n = rand.Next(nFrom, nTo);
                if (sort.allowsDecimals)
                {
                    arr = new double[n];
                    for (int j = 0; j < n; j++)
                    {
                        arr[j] = rand.NextDouble() * (double)sort.ToRandomRange;
                    }
                    if (!Test(testname + " " + i.ToString(), sort, arr))
                    {
                        return(false);
                    }
                }
                else
                {
                    arr1 = new int[n];
                    for (int j = 0; j < n; j++)
                    {
                        arr1[j] = rand.Next(sort.FromRandomRange, sort.ToRandomRange);
                    }
                    if (!Test(testname + " " + i.ToString(), sort, arr1))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }