public void DoTest() { String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; Assert.IsTrue(SortHelper.IsSorted(a)); Shuffle.Do(a); Assert.IsFalse(SortHelper.IsSorted(a)); }
public void SortTest_DESC_DuplicateKey() { String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "3", "4", "5", "3", "4", "5", "3", "4", "5" }; Shuffle.Do(a); Assert.IsFalse(SortHelper.IsSorted(a, SortOrder.DESC)); Quick3WaySort.Sort(a, SortOrder.DESC); Assert.IsTrue(SortHelper.IsSorted(a, SortOrder.DESC)); }
public void SortTest_DESC() { String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; Shuffle.Do(a); Assert.IsFalse(SortHelper.IsSorted(a, SortOrder.DESC)); MergeSort.Sort(a, SortOrder.DESC); Assert.IsTrue(SortHelper.IsSorted(a, SortOrder.DESC)); }
public void SortWithComparerTest_DESC() { Point[] points = new Point[10]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } Shuffle.Do(points); Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC)); MergeSort.Sort(points, Point.X_ORDER, SortOrder.DESC); Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC)); }
public void SortWithComparerTest() { Point[] points = new Point[10]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } Shuffle.Do(points); Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER)); ShellSort.Sort(points, Point.X_ORDER); Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER)); }
public void SelectTest() { String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; Shuffle.Do(a); String v = QuickSelect.Select(a, 3) as String; Assert.IsNotNull(v); Assert.AreEqual("3", v); for (int i = 0; i < 3; i++) { Assert.IsTrue(SortHelper.Less(a[i], v)); } Assert.AreEqual(a[3], v); }
public void MaxPriorityQueueTest_InitWithKey() { int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Shuffle.Do(a); MaxPriorityQueue <int> pq = new MaxPriorityQueue <int>(a); Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); for (int i = 0; i < 10; i++) { int result = pq.Max(); Assert.AreEqual(10 - i - 1, result); result = pq.DelMax(); Assert.AreEqual(10 - i - 1, result); } Assert.IsTrue(pq.IsEmpty()); Assert.AreEqual(0, pq.Size()); }
public void SelectWithComparerTest() { Point[] points = new Point[10]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } Shuffle.Do(points); Point v = QuickSelect.Select(points, Point.X_ORDER, 3) as Point; Assert.IsNotNull(v); Assert.AreEqual(3, v.X); Assert.AreEqual(7, v.Y); for (int i = 0; i < 3; i++) { Assert.IsTrue(SortHelper.Less(Point.X_ORDER, points[i], v)); } Assert.AreEqual(points[3], v); }
public void SortWithComparerTest_DESC_DuplicateKey() { Point[] points = new Point[19]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } for (int i = 0; i < 3; i++) { for (int j = 3; j <= 5; j++) { points[10 + i * 3 + j - 3] = new Point(j, 10 - i); } } Shuffle.Do(points); Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC)); Quick3WaySort.Sort(points, Point.X_ORDER, SortOrder.DESC); Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC)); }
public void DoTest_Different() { String[] a1 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; String[] a2 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; Shuffle.Do(a1); Shuffle.Do(a2); Assert.IsFalse(SortHelper.IsSorted(a1)); Assert.IsFalse(SortHelper.IsSorted(a2)); var same = true; for (int i = 0; i < 10; i++) { if (a1[i] != a2[i]) { same = false; break; } } Assert.IsFalse(same); }
public void MaxPriorityQueueTest_Comparer() { Point[] points = new Point[10]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } Shuffle.Do(points); MaxPriorityQueue <Point> pq = new MaxPriorityQueue <Point>(Point.X_ORDER); foreach (var value in points) { pq.Insert(value); } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); Point[] expectPoints = new Point[10]; for (int i = 0; i < 10; i++) { expectPoints[i] = new Point(i, 10 - i); } Shuffle.Do(expectPoints); HeapSort.Sort(expectPoints, Point.X_ORDER, SortOrder.DESC); for (int i = 0; i < 10; i++) { var result = pq.Max(); Assert.AreEqual(expectPoints[i].X, result.X); Assert.AreEqual(expectPoints[i].Y, result.Y); result = pq.DelMax(); Assert.AreEqual(expectPoints[i].X, result.X); Assert.AreEqual(expectPoints[i].Y, result.Y); } Assert.IsTrue(pq.IsEmpty()); Assert.AreEqual(0, pq.Size()); }
public void MaxPriorityQueueTest_Enumerator() { int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Shuffle.Do(a); MaxPriorityQueue <int> pq = new MaxPriorityQueue <int>(); foreach (var value in a) { pq.Insert(value); } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); int expectedValue = 9; foreach (var value in pq) { Assert.AreEqual(expectedValue--, value); } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); }
public void MinPriorityQueueTest_Comparer_Enumerator() { Point[] points = new Point[10]; for (int i = 0; i < 10; i++) { points[i] = new Point(i, 10 - i); } Shuffle.Do(points); MinPriorityQueue <Point> pq = new MinPriorityQueue <Point>(Point.X_ORDER); foreach (var value in points) { pq.Insert(value); } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); Point[] expectPoints = new Point[10]; for (int i = 0; i < 10; i++) { expectPoints[i] = new Point(i, 10 - i); } Shuffle.Do(expectPoints); HeapSort.Sort(expectPoints, Point.X_ORDER, SortOrder.ASC); int expectedIndex = 0; foreach (var result in pq) { Assert.AreEqual(expectPoints[expectedIndex].X, result.X); Assert.AreEqual(expectPoints[expectedIndex].Y, result.Y); expectedIndex++; } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); }
public void MinPriorityQueueTest_Insert() { int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Shuffle.Do(a); MinPriorityQueue <int> pq = new MinPriorityQueue <int>(); foreach (var value in a) { pq.Insert(value); } Assert.IsFalse(pq.IsEmpty()); Assert.AreEqual(10, pq.Size()); for (int i = 0; i < 10; i++) { int result = pq.Min(); Assert.AreEqual(i, result); result = pq.DelMin(); Assert.AreEqual(i, result); } Assert.IsTrue(pq.IsEmpty()); Assert.AreEqual(0, pq.Size()); }