2 Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
\r
3 Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 of this software and associated documentation files (the "Software"), to deal
\r
5 in the Software without restriction, including without limitation the rights
\r
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 copies of the Software, and to permit persons to whom the Software is
\r
8 furnished to do so, subject to the following conditions:
\r
10 The above copyright notice and this permission notice shall be included in
\r
11 all copies or substantial portions of the Software.
\r
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
24 using NUnit.Framework;
\r
25 using SCG = System.Collections.Generic;
\r
27 namespace C5UnitTests.SortingTests
\r
30 public class SortRandom
\r
45 ran = new Random(3456);
\r
47 a = new int[length];
\r
48 for (int i = 0; i < length; i++)
\r
54 public void HeapSort()
\r
56 Sorting.HeapSort<int>(a, 0, length, ic);
\r
57 for (int i = 1; i < length; i++)
\r
58 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
63 public void IntroSort()
\r
65 Sorting.IntroSort<int>(a, 0, length, ic);
\r
66 for (int i = 1; i < length; i++)
\r
67 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
72 public void InsertionSort()
\r
75 Sorting.InsertionSort<int>(a, 0, length, ic);
\r
76 for (int i = 1; i < length; i++)
\r
77 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
79 Sorting.InsertionSort<int>(a, length, 2 * length, ic);
\r
80 for (int i = length + 1; i < 2 * length; i++)
\r
81 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
86 public void Dispose() { ic = null; }
\r
92 public class SortRandomDuplicates
\r
107 ran = new Random(3456);
\r
109 a = new int[length];
\r
110 for (int i = 0; i < length; i++)
\r
111 a[i] = ran.Next(3, 23);
\r
116 public void HeapSort()
\r
118 Sorting.HeapSort<int>(a, 0, length, ic);
\r
119 for (int i = 1; i < length; i++)
\r
120 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
125 public void IntroSort()
\r
127 Sorting.IntroSort<int>(a, 0, length, ic);
\r
128 for (int i = 1; i < length; i++)
\r
129 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
134 public void InsertionSort()
\r
137 Sorting.InsertionSort<int>(a, 0, length, ic);
\r
138 for (int i = 1; i < length; i++)
\r
139 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
141 Sorting.InsertionSort<int>(a, length, 2 * length, ic);
\r
142 for (int i = length + 1; i < 2 * length; i++)
\r
143 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
148 public void Dispose() { ic = null; a = null; ran = null; }
\r
154 public class SortIncreasing
\r
168 a = new int[length];
\r
169 for (int i = 0; i < length; i++)
\r
175 public void HeapSort()
\r
177 Sorting.HeapSort<int>(a, 0, length, ic);
\r
178 for (int i = 1; i < length; i++)
\r
179 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
184 public void IntroSort()
\r
186 Sorting.IntroSort<int>(a, 0, length, ic);
\r
187 for (int i = 1; i < length; i++)
\r
188 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
193 public void InsertionSort()
\r
196 Sorting.InsertionSort<int>(a, 0, length, ic);
\r
197 for (int i = 1; i < length; i++)
\r
198 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
200 Sorting.InsertionSort<int>(a, length, 2 * length, ic);
\r
201 for (int i = length + 1; i < 2 * length; i++)
\r
202 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
207 public void Dispose() { ic = null; a = null; }
\r
213 public class SortDecreasing
\r
227 a = new int[length];
\r
228 for (int i = 0; i < length; i++)
\r
234 public void HeapSort()
\r
236 Sorting.HeapSort<int>(a, 0, length, ic);
\r
237 for (int i = 1; i < length; i++)
\r
238 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
243 public void IntroSort()
\r
245 Sorting.IntroSort<int>(a, 0, length, ic);
\r
246 for (int i = 1; i < length; i++)
\r
247 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
252 public void InsertionSort()
\r
255 Sorting.InsertionSort<int>(a, 0, length, ic);
\r
256 for (int i = 1; i < length; i++)
\r
257 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
259 Sorting.InsertionSort<int>(a, length, 2 * length, ic);
\r
260 for (int i = length + 1; i < 2 * length; i++)
\r
261 Assert.IsTrue(a[i - 1] <= a[i], "Inversion at " + i);
\r
266 public void Dispose() { ic = null; a = null; }
\r