test/testqsort.c
changeset 10415 53980a18cdde
parent 10110 3dd0469150ce
child 10737 3406a0f8b041
equal deleted inserted replaced
10414:92dc590a7116 10415:53980a18cdde
     8   Permission is granted to anyone to use this software for any purpose,
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    10   freely.
    11 */
    11 */
    12 
    12 
    13 #include <stdio.h>
    13 #include "SDL_test.h"
    14 #include <stdlib.h>
       
    15 
       
    16 #include "SDL.h"
       
    17 
    14 
    18 static int
    15 static int
    19 num_compare(const void *_a, const void *_b)
    16 num_compare(const void *_a, const void *_b)
    20 {
    17 {
    21     const int a = *((const int *) _a);
    18     const int a = *((const int *) _a);
    48 main(int argc, char *argv[])
    45 main(int argc, char *argv[])
    49 {
    46 {
    50     static int nums[1024 * 100];
    47     static int nums[1024 * 100];
    51     static const int itervals[] = { SDL_arraysize(nums), 12 };
    48     static const int itervals[] = { SDL_arraysize(nums), 12 };
    52     int iteration;
    49     int iteration;
       
    50     SDLTest_RandomContext rndctx;
       
    51 
       
    52     if (argc > 1)
       
    53     {
       
    54         int success;
       
    55         Uint64 seed = 0;
       
    56         if (argv[1][0] == '0' && argv[1][1] == 'x')
       
    57             success = SDL_sscanf(argv[1] + 2, "%llx", &seed);
       
    58         else
       
    59             success = SDL_sscanf(argv[1], "%llu", &seed);
       
    60         if (!success)
       
    61         {
       
    62             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
       
    63             return 1;
       
    64         }
       
    65         if (seed <= 0xffffffff)
       
    66         {
       
    67             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n");
       
    68             return 1;
       
    69         }
       
    70         SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
       
    71     }
       
    72     else
       
    73     {
       
    74         SDLTest_RandomInitTime(&rndctx);
       
    75     }
       
    76     SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
    53 
    77 
    54     for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) {
    78     for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) {
    55         const int arraylen = itervals[iteration];
    79         const int arraylen = itervals[iteration];
    56         int i;
    80         int i;
    57 
    81 
    70             nums[i] = (arraylen-1) - i;
    94             nums[i] = (arraylen-1) - i;
    71         }
    95         }
    72         test_sort("reverse sorted", nums, arraylen);
    96         test_sort("reverse sorted", nums, arraylen);
    73 
    97 
    74         for (i = 0; i < arraylen; i++) {
    98         for (i = 0; i < arraylen; i++) {
    75             nums[i] = random();
    99             nums[i] = SDLTest_RandomInt(&rndctx);
    76         }
   100         }
    77         test_sort("random sorted", nums, arraylen);
   101         test_sort("random sorted", nums, arraylen);
    78     }
   102     }
    79 
   103 
    80     return 0;
   104     return 0;