diff options
author | Andrew Shadura <andrew@shadura.me> | 2014-06-17 11:57:32 +0200 |
---|---|---|
committer | Andrew Shadura <andrew@shadura.me> | 2014-06-17 11:57:32 +0200 |
commit | d1e7e16224c881ee3093658fe4cbf14db244cec7 (patch) | |
tree | 8850e7a55b4b1589a7a08e2364e9c12dad31962c /src/examples/patriciatest2 | |
parent | 246fb6b81eef837f1269073255373bf0a3d5c27a (diff) |
Update to the latest upstream snapshot
Diffstat (limited to 'src/examples/patriciatest2')
-rw-r--r-- | src/examples/patriciatest2/patriciatest2.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/examples/patriciatest2/patriciatest2.c b/src/examples/patriciatest2/patriciatest2.c index d73b1ee..800c59e 100644 --- a/src/examples/patriciatest2/patriciatest2.c +++ b/src/examples/patriciatest2/patriciatest2.c @@ -37,17 +37,19 @@ int errors = 0; -void str_canon(char *key) +void +str_canon(char *key) { return; } -void statscb(const char *line, void *data) -{ -} +void +statscb(const char *line, void *data) +{ } /* assumes data is key */ -static void check_all_retrievable(mowgli_patricia_t *dtree) +static void +check_all_retrievable(mowgli_patricia_t *dtree) { mowgli_patricia_iteration_state_t state; void *elem, *elem2; @@ -57,24 +59,28 @@ static void check_all_retrievable(mowgli_patricia_t *dtree) n2 = mowgli_patricia_size(dtree); MOWGLI_PATRICIA_FOREACH(elem, &state, dtree) { - elem2 = mowgli_patricia_retrieve(dtree, (const char *)elem); + elem2 = mowgli_patricia_retrieve(dtree, (const char *) elem); + if (elem2 == NULL) { errors++; printf("failed to find element %s\n", - (const char *)elem); + (const char *) elem); } else if (strcmp(elem2, elem)) { printf("element %s != %s\n", - (const char *)elem, - (const char *)elem2); + (const char *) elem, + (const char *) elem2); errors++; } + n1++; + if (n1 > n2 * 2) break; } + if (n1 != n2) { errors++; @@ -82,17 +88,20 @@ static void check_all_retrievable(mowgli_patricia_t *dtree) } } -void test_patricia(void) +void +test_patricia(void) { mowgli_patricia_t *dtree; int i, j; char buf[100], *strings[TESTSIZE]; srandom(12346); + for (i = 0; i < TESTSIZE; i++) { for (j = 0; j < 40; j++) buf[j] = 'a' + random() % 26; + buf[20 + random() % 20] = '\0'; strings[i] = strdup(buf); } @@ -110,12 +119,14 @@ void test_patricia(void) for (i = 0; i < TESTSIZE / 2; i++) { mowgli_patricia_delete(dtree, strings[i]); + if (mowgli_patricia_retrieve(dtree, strings[i])) { printf("still retrievable after delete: %s\n", - strings[i]); + strings[i]); errors++; } + check_all_retrievable(dtree); } @@ -128,12 +139,14 @@ void test_patricia(void) for (i = 0; i < TESTSIZE; i++) { mowgli_patricia_delete(dtree, strings[i]); + if (mowgli_patricia_retrieve(dtree, strings[i])) { printf("still retrievable after delete: %s\n", - strings[i]); + strings[i]); errors++; } + check_all_retrievable(dtree); } @@ -143,7 +156,8 @@ void test_patricia(void) free(strings[i]); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { test_patricia(); |