1#include "Test.h" 2#include "SkRandom.h" 3#include "SkTSearch.h" 4#include "SkTSort.h" 5 6extern "C" { 7 int compare_int(const void* a, const void* b) { 8 return *(const int*)a - *(const int*)b; 9 } 10} 11 12static void rand_array(SkRandom& rand, int array[], int n) { 13 for (int j = 0; j < n; j++) { 14 array[j] = rand.nextS() & 0xFF; 15 } 16} 17 18static void check_sort(skiatest::Reporter* reporter, const char label[], 19 const int array[], int n) { 20 for (int j = 1; j < n; j++) { 21 if (array[j-1] > array[j]) { 22 SkString str; 23 str.printf("%sSort [%d] failed %d %d", label, n, 24 array[j-1], array[j]); 25 reporter->reportFailed(str); 26 } 27 } 28} 29 30static void TestSort(skiatest::Reporter* reporter) { 31 int array[500]; 32 SkRandom rand; 33 34 for (int i = 0; i < 10000; i++) { 35 int count = rand.nextRangeU(1, SK_ARRAY_COUNT(array)); 36 37 rand_array(rand, array, count); 38 SkQSort(array, count, sizeof(int), compare_int); 39 check_sort(reporter, "Quick", array, count); 40 41 rand_array(rand, array, count); 42 SkTHeapSort<int>(array, count); 43 check_sort(reporter, "Heap", array, count); 44 } 45} 46 47// need tests for SkStrSearch 48 49#include "TestClassDef.h" 50DEFINE_TESTCLASS("Sort", SortTestClass, TestSort) 51