struct QCValue {
void (*showfn)(QCValue* val);
void (*freefn)(QCValue* val);
- int data[];
+ long data[];
};
typedef struct {
void qcinit(int seed) {
Seed = (seed ? seed : time(NULL));
- srand(Seed);
+ srandom(Seed);
}
void qcntrials(int ntrials) {
}
/************************************************/
-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) {
(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;
}