Go to the source code of this file.
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 45 of file testqsort.c.
46{
47 static int nums[1024 * 100];
51
52 if (argc > 1)
53 {
54 int success;
56 if (argv[1][0] == '0' && argv[1][1] == 'x')
57 success =
SDL_sscanf(argv[1] + 2,
"%llx", &seed);
58 else
60 if (!success)
61 {
63 return 1;
64 }
65 if (seed <= 0xffffffff)
66 {
68 return 1;
69 }
70 SDLTest_RandomInit(&rndctx, (
unsigned int)(seed >> 32), (
unsigned int)(seed & 0xffffffff));
71 }
72 else
73 {
75 }
76 SDL_Log(
"Using random seed 0x%08x%08x\n", rndctx.
x, rndctx.
c);
77
81
82 for (
i = 0;
i < arraylen;
i++) {
84 }
85 test_sort(
"already sorted", nums, arraylen);
86
87 for (
i = 0;
i < arraylen;
i++) {
89 }
90 nums[arraylen-1] = -1;
91 test_sort(
"already sorted except last element", nums, arraylen);
92
93 for (
i = 0;
i < arraylen;
i++) {
94 nums[
i] = (arraylen-1) -
i;
95 }
96 test_sort(
"reverse sorted", nums, arraylen);
97
98 for (
i = 0;
i < arraylen;
i++) {
100 }
101 test_sort(
"random sorted", nums, arraylen);
102 }
103
104 return 0;
105}
@ SDL_LOG_CATEGORY_APPLICATION
#define SDL_arraysize(array)
#define SDLTest_RandomInt(c)
void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext)
Initialize random number generator based on current system time.
void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
Initialize random number generator with two integers.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
static void test_sort(const char *desc, int *nums, const int arraylen)
References SDLTest_RandomContext::c, i, iteration(), SDL_arraysize, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_sscanf, SDLTest_RandomInit(), SDLTest_RandomInitTime(), SDLTest_RandomInt, test_sort(), and SDLTest_RandomContext::x.
◆ num_compare()
static int num_compare |
( |
const void * |
_a, |
|
|
const void * |
_b |
|
) |
| |
|
static |
Definition at line 16 of file testqsort.c.
17{
18 const int a = *((
const int *) _a);
19 const int b = *((
const int *) _b);
20 return (
a <
b) ? -1 : ((
a >
b) ? 1 : 0);
21}
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
Referenced by test_sort().
◆ test_sort()
static void test_sort |
( |
const char * |
desc, |
|
|
int * |
nums, |
|
|
const int |
arraylen |
|
) |
| |
|
static |
Definition at line 24 of file testqsort.c.
25{
27 int prev;
28
29 SDL_Log(
"test: %s arraylen=%d", desc, arraylen);
30
32
33 prev = nums[0];
34 for (
i = 1;
i < arraylen;
i++) {
35 const int val = nums[
i];
38 return;
39 }
41 }
42}
static int num_compare(const void *_a, const void *_b)
References i, num_compare(), SDL_Log, and SDL_qsort.
Referenced by main().