Archived
1
0
Fork 0

some cleanup and extended insertion in rbtree, updated rbtree test

This commit is contained in:
Henrik Hautakoski 2010-04-28 08:49:15 +02:00 committed by Henrik Hautakoski
parent 401b11fdcf
commit f630cbf979
8 changed files with 382 additions and 310 deletions

View file

@ -1,16 +1,51 @@
#include "unit.h"
#include <malloc.h>
#include <time.h>
int utest_string(const char *a, const char *b) {
while(*a == *b) {
if (*a == 0)
return 1;
a++;
b++;
}
return 0;
static inline char ranchr() {
char ch;
do {
ch = rand() % 0x7A;
} while(ch < 0x20);
return ch;
}
void utest_init_RNG() {
static unsigned char init = 0;
if (init)
return;
srand(time(NULL));
init = 1;
}
/*
* Helper function for generating random strings
*/
char* utest_ran_string(size_t size) {
int i, r;
char *str;
if (size < 1)
return NULL;
str = malloc(size+1);
if (str == NULL)
return NULL;
utest_init_RNG();
for(i=0; i < size; i++)
str[i] = ranchr();
str[i] = 0;
return str;
}