public void QuickSortAllSameEvenLength() { int[] a = new int[] { 1, 1, 1, 1 }; int[] expectedOutput = a.Clone() as int[]; QuickSort.Sort(a, QuickSortCCI.Partition); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(a, expectedOutput)); }
public void HeapSortSingletonArray() { int[] a = new int[] { 88 }; int[] expectedOutput = a.Clone() as int[]; HeapSort.Sort(a); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(a, expectedOutput)); }
public void QuickSortSingletonArray() { int[] a = new int[] { 88 }; int[] expectedOutput = a.Clone() as int[]; QuickSort.Sort(a, QuickSortCCI.Partition); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(a, expectedOutput)); }
public void GetKeys() { int[] random = ArrayUtility.GenerateRandomIntArray(5, 1000); int[] sortedDistinct = ArrayUtility.GetSortedDistinct(random); KevinDictionary <int, string> kd = new KevinDictionary <int, string>(100); SortedList <int, int> originalKeys = new SortedList <int, int>(); for (int i = 0; i < sortedDistinct.Length; i++) { kd.Put(sortedDistinct[i], sortedDistinct[i].ToString()); originalKeys.Add(sortedDistinct[i], sortedDistinct[i]); } int[] keysFromDictionary = kd.Keys.ToArray(); int[] sdk = ArrayUtility.GetSortedDistinct(keysFromDictionary); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(originalKeys.Values.ToArray(), sdk)); for (int i = 0; i < sortedDistinct.Length; i++) { kd.Remove(sortedDistinct[i]); originalKeys.Remove(sortedDistinct[i]); keysFromDictionary = kd.Keys.ToArray(); sdk = ArrayUtility.GetSortedDistinct(keysFromDictionary); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(originalKeys.Values.ToArray(), sdk)); } }
public void QuickSortReverseSortedEvenLength() { int[] a = new int[] { 4, 3, 2, 1 }; int[] expectedOutput = a.Clone() as int[]; Array.Sort(expectedOutput); QuickSort.Sort(a, QuickSortCCI.Partition); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(a, expectedOutput)); }
public void SingletonList() { int[] a = new int[] { 1 }; List <int> result = LongestIncreasingSequence.Find(a); List <int> expected = new List <int>(a); ArrayUtility.AreIntegerEnumerablesEqual(result, expected); }
public void HeapSortLargeRandomArray() { int[] inputArray = ArrayUtility.GenerateRandomIntArray(1000); int[] expectedArray = inputArray.Clone() as int[]; // default sort puts min at the front of the sorted array Array.Sort(expectedArray); HeapSort.Sort(inputArray); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(inputArray, expectedArray)); }
public void QuickSortLargeRandomArray() { int[] inputArray = ArrayUtility.GenerateRandomIntArray(arrayLength: 1000, maxValue: 20); int[] expectedArray = inputArray.Clone() as int[]; // default sort puts min at the front of the sorted array Array.Sort(expectedArray); QuickSort.Sort(inputArray, QuickSortCCI.Partition); Assert.IsTrue(ArrayUtility.AreIntegerEnumerablesEqual(inputArray, expectedArray)); }
public void LongerList() { int[] a = new int[] { 98, 99, 1, 2, 3, 4, 0, 100 }; List <int> result = LongestIncreasingSequence.Find(a); List <int> expected = new List <int>() { 1, 2, 3, 4, 100 }; ArrayUtility.AreIntegerEnumerablesEqual(result, expected); }
private static Tree BuildTreeFromList(List <int> values) { Tree t = new Tree(); for (int i = 0; i < values.Count; i++) { t.Insert(values[i]); } Assert.AreEqual(t.Count(), values.Count); List <int> traversal = t.Traverse(); Assert.AreEqual(traversal.Count, t.Count()); ArrayUtility.AreIntegerEnumerablesEqual(traversal, values); return(t); }