Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed unit float and unit double generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Aug 17, 2011
1 parent a90354b commit bfdebcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
Expand Up @@ -562,13 +562,13 @@ RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDoma
float
RandomUnitFloat()
{
return (float) utl_randomInt(&rndContext) / UINT_MAX;
return (float) RandomUint32() / UINT_MAX;
}

double
RandomUnitDouble()
{
return (double) RandomUint64() / LLONG_MAX;
return (RandomUint64() >> 11) * (1.0/9007199254740992.0);
}

float
Expand Down Expand Up @@ -599,7 +599,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
return NULL;
}

int size = (abs(RandomSint32()) % (maxSize + 1)) + 1;
int size = (RandomUint32() % (maxSize + 1)) + 1;
char *string = SDL_malloc(size * sizeof(char));

int counter = 0;
Expand Down
8 changes: 6 additions & 2 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
Expand Up @@ -111,17 +111,21 @@ Sint64 RandomSint64();
float RandomUnitFloat();

/*!
* Returns random double in range [0.0 - 1.0] (inclusive)
* Returns random double in range [0.0 - 1.0[ (note: zero included, 1 is not!)
*/
double RandomUnitDouble();

/*!
* Returns random float
* Returns random float.
*
* Note: NOT implemented.
*/
float RandomFloat();

/*!
* Returns random double
*
* Note: NOT implemented.
*/
double RandomDouble();

Expand Down
3 changes: 3 additions & 0 deletions test/test-automation/tests/testdummy/testdummy.c
Expand Up @@ -103,6 +103,9 @@ test_dummy1(void *arg)

//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));

for(; 1 ; )
printf("%f\n", RandomUnitFloat());

for(; 0 ; )
printf("%d\n", RandomSint16());

Expand Down

0 comments on commit bfdebcc

Please sign in to comment.