public void SimpleQuickTest() { int[] xs = { 3, 2, 1, 6, 5, 9, 4 }; Quick <int> .SimpleSort(xs); Assert.True(Sorting <int> .IsSorted(xs)); }
public void MaxPriorityQueueTest() { int[] xs = { 3, 2, 1, 6, 5, 9, 4 }; var queue = new MaxPriorityQueue <int>(xs.Length); for (int i = 0; i < xs.Length; i++) { queue.Insert(xs[i]); } Quick <int> .SimpleSort(xs); for (int i = xs.Length - 1; i > 0; i--) { int v = queue.DelMax(); Assert.Equal(v, xs[i]); } }
public void IndexMinPrivorityQueueTest() { string[] strings1 = { "it", "was", "the", "best", "of", "times", "it", "was", "the", "worst" }; string[] strings2 = new string[strings1.Length]; Array.Copy(strings1, strings2, strings1.Length); var queue = new IndexMinPriorityQueue <string>(strings1.Length); for (int i = 0; i < strings1.Length; i++) { queue.Insert(i, strings1[i]); } Quick <string> .SimpleSort(strings2); for (int i = 0; i < strings1.Length; i++) { int index = queue.DelMin(); Assert.Equal(strings1[index], strings2[i]); } }