Пример #1
0
        public void FromInterfaceToDelegate_SortByMinDown()
        {
            int[][] ExpectedResult = new int[][] {
                new int[] { 9, 11, 5 },                   // Min = 5
                new int[] { 3, 6, 4, 9, 4 },              // Min = 3
                new int[] { 2, 4, 1, 3, -1000, 4, 2, 1 }, // Min = -1000
            };

            Comparers.CompareByMinDown minDownComp = new Comparers.CompareByMinDown();
            FromInterfaceToDelegate.BubbleSort(testArray, minDownComp.Compare);
            CollectionAssert.AreEqual(testArray, ExpectedResult);

            FromInterfaceToDelegate.BubbleSort(testArray, new Comparers.CompareByMinDown());
            CollectionAssert.AreEqual(testArray, ExpectedResult);
        }
Пример #2
0
        public void FromInterfaceToDelegate_SortByMaxUp()
        {
            int[][] ExpectedResult = new int[][] {
                new int[] { 2, 4, 1, 3, -1000, 4, 2, 1 }, // Max = 4
                new int[] { 3, 6, 4, 9, 4 },              // Max = 9
                new int[] { 9, 11, 5 },                   // Max = 11
            };

            Comparers.CompareByMaxUp maxUpComp = new Comparers.CompareByMaxUp();
            FromInterfaceToDelegate.BubbleSort(testArray, maxUpComp.Compare);
            CollectionAssert.AreEqual(testArray, ExpectedResult);

            FromInterfaceToDelegate.BubbleSort(testArray, new Comparers.CompareByMaxUp());
            CollectionAssert.AreEqual(testArray, ExpectedResult);
        }
Пример #3
0
        public void FromInterfaceToDelegate_SortBySumUp()
        {
            int[][] ExpectedResult = new int[][] {
                new int[] { 2, 4, 1, 3, -1000, 4, 2, 1 }, // Sum = -983
                new int[] { 9, 11, 5 },                   // Sum = 25
                new int[] { 3, 6, 4, 9, 4 },              // Sum = 26
            };

            Comparers.CompareBySumUp sumUpComp = new Comparers.CompareBySumUp();
            FromInterfaceToDelegate.BubbleSort(testArray, sumUpComp.Compare);
            CollectionAssert.AreEqual(testArray, ExpectedResult);

            FromInterfaceToDelegate.BubbleSort(testArray, new Comparers.CompareBySumUp());
            CollectionAssert.AreEqual(testArray, ExpectedResult);
        }
Пример #4
0
 public void FromInterfaceToDelegate_WrongArrayEmptyTest()
 => Assert.Throws <ArgumentException>(()
                                      => FromInterfaceToDelegate.BubbleSort(wrongEmptyArray,
                                                                            (int[] a, int[] b) => a.Sum() - b.Sum()));