From: Michael D. Lowis Date: Wed, 27 Feb 2019 20:47:47 +0000 (-0500) Subject: added more generator functions X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=29ffa3c7dd63c4c6c14bc535ad3023d1c84bf594;p=projs%2Ftide.git added more generator functions --- diff --git a/tests/test_tide.c b/tests/test_tide.c index 33d3df1..96c2553 100644 --- a/tests/test_tide.c +++ b/tests/test_tide.c @@ -7,7 +7,7 @@ typedef struct QCValue QCValue; struct QCValue { void (*showfn)(QCValue* val); void (*freefn)(QCValue* val); - int data[]; + long data[]; }; typedef struct { @@ -24,7 +24,7 @@ int Seed = 0, NTrials = 10000; void qcinit(int seed) { Seed = (seed ? seed : time(NULL)); - srand(Seed); + srandom(Seed); } void qcntrials(int ntrials) { @@ -94,21 +94,54 @@ QCValue* qcalloc(size_t sz, void* data) { } /************************************************/ -void ShowInt(QCValue* val) { - printf("%d\n", (val->data[0])); + +void ShowLong(QCValue* val) { + printf("%ld\n", (val->data[0])); +} + +void ShowBool(QCValue* val) { + printf("%s\n", (val->data[0] ? "true" : "false")); } -int randint(int from, int to) { - return ((rand() % (to - from)) + from); +void ShowChar(QCValue* val) { + printf("'%c'\n", (char)(val->data[0])); } -QCValue* GenInt(void) { - int ival = rand(); - QCValue* value = qcalloc(sizeof(int), &ival); - value->showfn = ShowInt; +QCValue* GenLongR(long from, long to) { + long val = ((random() % (to - from + 1)) + from); + QCValue* value = qcalloc(sizeof(long), &val); + value->showfn = ShowLong; return value; } +QCValue* GenLong(void) { + return GenLongR(0, RAND_MAX); +} + +QCValue* GenU8(void) { + return GenLongR(0, UINT8_MAX); +} + +QCValue* GenU16(void) { + return GenLongR(0, UINT16_MAX); +} + +QCValue* GenU32(void) { + return GenLongR(0, UINT32_MAX); +} + +QCValue* GenBool(void) { + QCValue* val = GenLongR(0, 1); + val->showfn = ShowBool; + return val; +} + +QCValue* GenChar(void) { + QCValue* val = GenU8(); + val->showfn = ShowChar; + return val; +} + /************************************************/ void tide_init(void) { @@ -135,7 +168,7 @@ int main(int argc, char** argv) { (void)argc, (void)argv, (void)usage; qcinit(0); - qcheck("all numbers are divisible by 2", divisible_by_two, 1, GenInt); + qcheck("all numbers are divisible by 2", divisible_by_two, 1, GenLong); return 0; }