OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 #include "SkTSort.h" | 11 #include "SkTSort.h" |
12 | 12 |
13 extern "C" { | 13 extern "C" { |
14 static int compare_int(const void* a, const void* b) { | 14 static int compare_int(const void* a, const void* b) { |
15 return *(const int*)a - *(const int*)b; | 15 return *(const int*)a - *(const int*)b; |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 static void rand_array(SkRandom& rand, int array[], int n) { | 19 static void rand_array(SkRandom& rand, int array[], int n) { |
20 for (int j = 0; j < n; j++) { | 20 for (int j = 0; j < n; j++) { |
21 array[j] = rand.nextS() & 0xFF; | 21 array[j] = rand.nextS() & 0xFF; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 static void check_sort(skiatest::Reporter* reporter, const char label[], | 25 static void check_sort(skiatest::Reporter* reporter, const char label[], |
26 const int array[], const int reference[], int n) { | 26 const int array[], const int reference[], int n) { |
27 for (int j = 0; j < n; ++j) { | 27 for (int j = 0; j < n; ++j) { |
28 if (array[j] != reference[j]) { | 28 if (array[j] != reference[j]) { |
29 SkString str; | 29 ERRORF(reporter, "%sSort [%d] failed %d %d", |
30 str.printf("%sSort [%d] failed %d %d", label, n, array[j], reference
[j]); | 30 label, n, array[j], reference[j]); |
31 reporter->reportFailed(str); | |
32 } | 31 } |
33 } | 32 } |
34 } | 33 } |
35 | 34 |
36 DEF_TEST(Sort, reporter) { | 35 DEF_TEST(Sort, reporter) { |
37 /** An array of random numbers to be sorted. */ | 36 /** An array of random numbers to be sorted. */ |
38 int randomArray[500]; | 37 int randomArray[500]; |
39 /** The reference sort of the random numbers. */ | 38 /** The reference sort of the random numbers. */ |
40 int sortedArray[SK_ARRAY_COUNT(randomArray)]; | 39 int sortedArray[SK_ARRAY_COUNT(randomArray)]; |
41 /** The random numbers are copied into this array, sorted by an SkSort, | 40 /** The random numbers are copied into this array, sorted by an SkSort, |
(...skipping 13 matching lines...) Expand all Loading... |
55 SkTHeapSort<int>(workingArray, count); | 54 SkTHeapSort<int>(workingArray, count); |
56 check_sort(reporter, "Heap", workingArray, sortedArray, count); | 55 check_sort(reporter, "Heap", workingArray, sortedArray, count); |
57 | 56 |
58 memcpy(workingArray, randomArray, sizeof(randomArray)); | 57 memcpy(workingArray, randomArray, sizeof(randomArray)); |
59 SkTQSort<int>(workingArray, workingArray + count - 1); | 58 SkTQSort<int>(workingArray, workingArray + count - 1); |
60 check_sort(reporter, "Quick", workingArray, sortedArray, count); | 59 check_sort(reporter, "Quick", workingArray, sortedArray, count); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 // need tests for SkStrSearch | 63 // need tests for SkStrSearch |
OLD | NEW |