]> git.mdlowis.com Git - projs/tide.git/commitdiff
added more generator functions
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 27 Feb 2019 20:47:47 +0000 (15:47 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 27 Feb 2019 20:47:47 +0000 (15:47 -0500)
tests/test_tide.c

index 33d3df152f2652beaeb4e54913d0cd5fca591927..96c25530c48c5c1f6d99512cce4f23ffb5b57c5c 100644 (file)
@@ -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;
 }