|
| 1 | +using System.Collections.Generic; |
| 2 | +using Algorithms.Sorting; |
| 3 | +using NUnit.Framework; |
| 4 | + |
| 5 | +namespace AlgorithmsTests.Sorting |
| 6 | +{ |
| 7 | + [TestFixture] |
| 8 | + public class BubbleSorterTests |
| 9 | + { |
| 10 | + [TestCase(new[] { 0, 2 }, new[] { 0, 2 })] |
| 11 | + [TestCase(new []{3,2},new []{2,3})] |
| 12 | + [TestCase(new[] { 1, 9, 3, 7, 5, 2 }, new[] { 1, 2, 3, 5, 7, 9 })] |
| 13 | + [TestCase(new[] { 541, 87, 23, 87, 18, 687, 1587, 579, 25742, 5841, 2 }, new[] { 2, 18, 23, 87, 87, 541, 579, 687, 1587, 5841, 25742 })] |
| 14 | + public void BubbleSortTest(int[] toSortInts, int[] expectedSortedInts) |
| 15 | + { |
| 16 | + toSortInts.BubbleSort(); |
| 17 | + CollectionAssert.AreEqual(toSortInts,expectedSortedInts); |
| 18 | + } |
| 19 | + |
| 20 | + [TestCase(new[] { 0, 2 }, new[] { 0, 2 })] |
| 21 | + [TestCase(new[] { 3, 2 }, new[] { 2, 3 })] |
| 22 | + [TestCase(new[] { 1, 9, 3, 7, 5, 2 }, new[] { 1, 2, 3, 5, 7, 9 })] |
| 23 | + [TestCase(new[] { 541, 87, 23, 87, 18, 687, 1587, 579, 25742, 5841, 2 }, new[] { 2, 18, 23, 87, 87, 541, 579, 687, 1587, 5841, 25742 })] |
| 24 | + public void BubbleSortAscendingTest(int[] toSortInts, int[] expectedSortedInts) |
| 25 | + { |
| 26 | + toSortInts.BubbleSortAscending(Comparer<int>.Default); |
| 27 | + CollectionAssert.AreEqual(toSortInts, expectedSortedInts); |
| 28 | + } |
| 29 | + |
| 30 | + [TestCase(new[] { 0, 2 }, new[] { 2, 0 })] |
| 31 | + [TestCase(new[] { 3, 2 }, new[] { 3, 2 })] |
| 32 | + [TestCase(new[] { 1, 9, 3, 7, 5, 2 }, new[] {9,7,5,3,2,1})] |
| 33 | + [TestCase(new[] { 541, 87, 23, 87, 18, 687, 1587, 579, 25742, 5841, 2 }, new[] { 25742, 5841, 1587, 687, 579, 541, 87, 87, 23, 18, 2 })] |
| 34 | + public void BubbleSortDescendingTest(int[] toSortInts, int[] expectedSortedInts) |
| 35 | + { |
| 36 | + toSortInts.BubbleSortDescending(Comparer<int>.Default); |
| 37 | + CollectionAssert.AreEqual(toSortInts, expectedSortedInts); |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments