Example #1
0
        public void Sort_GivenSortingBySumOfElementsByDescending_ReturnSortedByMaxAbsArrayByDescending()
        {
            var arr = new int[5][];
            {
                arr[0] = new[] { 1, 3, 5, 7, 9 };
                arr[1] = new[] { 0, 2, 4, 6 };
                arr[2] = new[] { 11, 22 };
                arr[3] = new[] { 11, 22, 54, 66 };
                arr[4] = new[] { 11 };
            }
            var arrResult = new int[5][];

            {
                arrResult[4] = new[] { 11 };
                arrResult[3] = new[] { 0, 2, 4, 6 };
                arrResult[2] = new[] { 1, 3, 5, 7, 9 };
                arrResult[1] = new[] { 11, 22 };
                arrResult[0] = new[] { 11, 22, 54, 66 };
            }
            SortingForJaggedArrays.Sort(arr, new SortingBySumOfElementsByDescending());
            for (var i = 0; i < arr.Length; i++)
            {
                for (var j = 0; j < arr[i].Length; j++)
                {
                    Assert.AreEqual(arrResult[i][j], arr[i][j]);
                }
            }
        }
Example #2
0
        Sort_GivenArrayWithNullRowsAndSortingByMaxAbsOfElementsByAscending_ReturnSortedByMaxAbsArrayByDescending()
        {
            var arr = new int[5][];
            {
                arr[0] = new[] { 1, 3, 5, 7, 9 };
                arr[1] = null;
                arr[2] = new[] { 11, 22 };
                arr[3] = new[] { 11, 22, 54, -66 };
                arr[4] = new[] { 11 };
            }
            var arrResult = new int[5][];

            {
                arrResult[0] = null;
                arrResult[1] = new[] { 1, 3, 5, 7, 9 };
                arrResult[2] = new[] { 11 };
                arrResult[3] = new[] { 11, 22 };
                arrResult[4] = new[] { 11, 22, 54, -66 };
            }
            SortingForJaggedArrays.Sort(arr, new SortingByMaxAbsOfElementsByAscending());
            for (var i = 0; i < arr.Length; i++)
            {
                if (arrResult[i] == null)
                {
                    Assert.AreEqual(arrResult[i], arr[i]);
                }
                else
                {
                    for (var j = 0; j < arr[i].Length; j++)
                    {
                        Assert.AreEqual(arrResult[i][j], arr[i][j]);
                    }
                }
            }
        }