test/testqsort.c
changeset 10415 53980a18cdde
parent 10110 3dd0469150ce
child 10737 3406a0f8b041
     1.1 --- a/test/testqsort.c	Sat Oct 01 12:31:31 2016 -0700
     1.2 +++ b/test/testqsort.c	Sat Oct 01 12:33:26 2016 -0700
     1.3 @@ -10,10 +10,7 @@
     1.4    freely.
     1.5  */
     1.6  
     1.7 -#include <stdio.h>
     1.8 -#include <stdlib.h>
     1.9 -
    1.10 -#include "SDL.h"
    1.11 +#include "SDL_test.h"
    1.12  
    1.13  static int
    1.14  num_compare(const void *_a, const void *_b)
    1.15 @@ -50,6 +47,33 @@
    1.16      static int nums[1024 * 100];
    1.17      static const int itervals[] = { SDL_arraysize(nums), 12 };
    1.18      int iteration;
    1.19 +    SDLTest_RandomContext rndctx;
    1.20 +
    1.21 +    if (argc > 1)
    1.22 +    {
    1.23 +        int success;
    1.24 +        Uint64 seed = 0;
    1.25 +        if (argv[1][0] == '0' && argv[1][1] == 'x')
    1.26 +            success = SDL_sscanf(argv[1] + 2, "%llx", &seed);
    1.27 +        else
    1.28 +            success = SDL_sscanf(argv[1], "%llu", &seed);
    1.29 +        if (!success)
    1.30 +        {
    1.31 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
    1.32 +            return 1;
    1.33 +        }
    1.34 +        if (seed <= 0xffffffff)
    1.35 +        {
    1.36 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n");
    1.37 +            return 1;
    1.38 +        }
    1.39 +        SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
    1.40 +    }
    1.41 +    else
    1.42 +    {
    1.43 +        SDLTest_RandomInitTime(&rndctx);
    1.44 +    }
    1.45 +    SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
    1.46  
    1.47      for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) {
    1.48          const int arraylen = itervals[iteration];
    1.49 @@ -72,7 +96,7 @@
    1.50          test_sort("reverse sorted", nums, arraylen);
    1.51  
    1.52          for (i = 0; i < arraylen; i++) {
    1.53 -            nums[i] = random();
    1.54 +            nums[i] = SDLTest_RandomInt(&rndctx);
    1.55          }
    1.56          test_sort("random sorted", nums, arraylen);
    1.57      }