13 |
13 |
14 using namespace std; |
14 using namespace std; |
15 using namespace lemon; |
15 using namespace lemon; |
16 |
16 |
17 void checkRadixSort() { |
17 void checkRadixSort() { |
18 int n = 10000; |
18 { |
19 vector<int> data1(n), data2(n); |
19 int n = 10000; |
20 for (int i = 0; i < n; ++i) { |
20 vector<int> data1(n), data2(n); |
21 data1[i] = data2[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500; |
21 for (int i = 0; i < n; ++i) { |
22 } |
22 data1[i] = data2[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500; |
23 radixSort(data1.begin(), data1.end()); |
23 } |
24 sort(data2.begin(), data2.end()); |
24 radixSort(data1.begin(), data1.end()); |
25 for (int i = 0; i < n; ++i) { |
25 sort(data2.begin(), data2.end()); |
26 check(data1[i] == data2[i], "Test failed"); |
26 for (int i = 0; i < n; ++i) { |
|
27 check(data1[i] == data2[i], "Test failed"); |
|
28 } |
|
29 } { |
|
30 int n = 10000; |
|
31 vector<unsigned char> data1(n), data2(n); |
|
32 for (int i = 0; i < n; ++i) { |
|
33 data1[i] = data2[i] = (int)(200 * (rand() / (RAND_MAX + 1.0))); |
|
34 } |
|
35 radixSort(data1.begin(), data1.end()); |
|
36 sort(data2.begin(), data2.end()); |
|
37 for (int i = 0; i < n; ++i) { |
|
38 check(data1[i] == data2[i], "Test failed"); |
|
39 } |
27 } |
40 } |
28 } |
41 } |
29 |
42 |
30 |
43 |
31 void checkCounterSort() { |
44 void checkCounterSort() { |
32 int n = 10000; |
45 { |
33 vector<int> data1(n), data2(n); |
46 int n = 10000; |
34 for (int i = 0; i < n; ++i) { |
47 vector<int> data1(n), data2(n); |
35 data1[i] = data2[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500; |
48 for (int i = 0; i < n; ++i) { |
36 } |
49 data1[i] = data2[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500; |
37 counterSort(data1.begin(), data1.end()); |
50 } |
38 sort(data2.begin(), data2.end()); |
51 counterSort(data1.begin(), data1.end()); |
39 for (int i = 0; i < n; ++i) { |
52 sort(data2.begin(), data2.end()); |
40 check(data1[i] == data2[i], "Test failed"); |
53 for (int i = 0; i < n; ++i) { |
|
54 check(data1[i] == data2[i], "Test failed"); |
|
55 } |
|
56 } { |
|
57 int n = 10000; |
|
58 vector<unsigned char> data1(n), data2(n); |
|
59 for (int i = 0; i < n; ++i) { |
|
60 data1[i] = data2[i] = (int)(200 * (rand() / (RAND_MAX + 1.0))); |
|
61 } |
|
62 counterSort(data1.begin(), data1.end()); |
|
63 sort(data2.begin(), data2.end()); |
|
64 for (int i = 0; i < n; ++i) { |
|
65 check(data1[i] == data2[i], "Test failed"); |
|
66 } |
41 } |
67 } |
42 } |
68 } |
43 |
69 |
44 void checkSorts() { |
70 void checkSorts() { |
45 checkRadixSort(); |
71 checkRadixSort(); |