|
| 1 | +using System.Linq; |
| 2 | +using JamLib.Algorithms.Sorting.OtherSorts; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | + |
| 5 | +namespace JamLib.Algorithms.Sorting.OtherSorts.Tests |
| 6 | +{ |
| 7 | + [TestClass()] |
| 8 | + public class CountingSortTests |
| 9 | + { |
| 10 | + [TestMethod()] |
| 11 | + public void SortEmptyTest() |
| 12 | + { |
| 13 | + int[] data = new int[] { }; |
| 14 | + int[] expected = new int[] { }; |
| 15 | + var result = CountingSort.Sort(data); |
| 16 | + |
| 17 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 18 | + } |
| 19 | + |
| 20 | + [TestMethod()] |
| 21 | + public void SortEmptyWrongMinMaxTest() |
| 22 | + { |
| 23 | + int[] data = new int[] { }; |
| 24 | + int[] expected = new int[] { }; |
| 25 | + |
| 26 | + // Trying the test with a wrong min/max count |
| 27 | + var result = CountingSort.Sort(data, 8, 10); |
| 28 | + |
| 29 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 30 | + } |
| 31 | + |
| 32 | + [TestMethod()] |
| 33 | + public void SortEmptyWrongMaxTest() |
| 34 | + { |
| 35 | + int[] data = new int[] { }; |
| 36 | + int[] expected = new int[] { }; |
| 37 | + |
| 38 | + // Trying the test with a wrong max count |
| 39 | + var result = CountingSort.Sort(data, 20); |
| 40 | + |
| 41 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 42 | + } |
| 43 | + |
| 44 | + [TestMethod()] |
| 45 | + public void SortNegativeMaxTest() |
| 46 | + { |
| 47 | + int[] data = new int[] { -11, -10, 0, 2, 2 }; |
| 48 | + int[] expected = new int[] { -11, -10, 0, 2, 2 }; |
| 49 | + |
| 50 | + // Trying the test with a Negative max count |
| 51 | + var result = CountingSort.Sort(data, 2); |
| 52 | + |
| 53 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 54 | + } |
| 55 | + |
| 56 | + [TestMethod()] |
| 57 | + public void SortNegativeTest() |
| 58 | + { |
| 59 | + int[] data = new int[] { 0, 8, 8, -2, 5, 5, 5, 1, 2, 3, -1, -1, 4, 4, 4, 10 }; |
| 60 | + int[] expected = new int[] { -2, -1, -1, 0, 1, 2, 3, 4, 4, 4, 5, 5, 5, 8, 8, 10 }; |
| 61 | + var result = CountingSort.Sort(data); |
| 62 | + |
| 63 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 64 | + } |
| 65 | + |
| 66 | + [TestMethod()] |
| 67 | + public void SortTest() |
| 68 | + { |
| 69 | + int[] data = new int[] { 8, 8, 5, 5, 5, 1, 2, 3, 4, 4, 4, 10 }; |
| 70 | + int[] expected = new int[] { 1, 2, 3, 4, 4, 4, 5, 5, 5, 8, 8, 10 }; |
| 71 | + var result = CountingSort.Sort(data); |
| 72 | + |
| 73 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 74 | + } |
| 75 | + |
| 76 | + [TestMethod()] |
| 77 | + public void SortMinMaxTest() |
| 78 | + { |
| 79 | + int[] data = new int[] { 8, 8, 5, 5, 5, 1, 2, 3, 4, 4, 4, 10 }; |
| 80 | + int[] expected = new int[] { 1, 2, 3, 4, 4, 4, 5, 5, 5, 8, 8, 10 }; |
| 81 | + var result = CountingSort.Sort(data, data.Min(), data.Max()); |
| 82 | + |
| 83 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 84 | + } |
| 85 | + |
| 86 | + [TestMethod()] |
| 87 | + public void SortMaxTest() |
| 88 | + { |
| 89 | + int[] data = new int[] { 8, 8, 5, 5, 5, 1, 2, 3, 4, 4, 4, 10 }; |
| 90 | + int[] expected = new int[] { 1, 2, 3, 4, 4, 4, 5, 5, 5, 8, 8, 10 }; |
| 91 | + var result = CountingSort.Sort(data, data.Max()); |
| 92 | + |
| 93 | + CollectionAssert.AreEqual(expected, result, "CountingSort did not sort correctly"); |
| 94 | + } |
| 95 | + |
| 96 | + } |
| 97 | +} |
0 commit comments