]> git.ozlabs.org Git - ccan/blob - ccan/asearch/test/run.c
tdb2: rename the tools to tdb2torture, tdb2tool and mktdb2
[ccan] / ccan / asearch / test / run.c
1 #include <ccan/asearch/asearch.h>
2 #include <ccan/array_size/array_size.h>
3 #include <ccan/tap/tap.h>
4 #include <limits.h>
5
6 static int test_cmp(const int *key, const int *elt)
7 {
8         if (*key < *elt)
9                 return -1;
10         else if (*key > *elt)
11                 return 1;
12         return 0;
13 }
14
15 int main(void)
16 {
17         const int arr[] = { INT_MIN, 0, 1, 2, 3, 4, 5, 6, INT_MAX };
18         unsigned int start, num, i, total = 0;
19         int key;
20
21         plan_tests(285);
22
23         for (start = 0; start < ARRAY_SIZE(arr); start++) {
24                 for (num = 0; num < ARRAY_SIZE(arr) - start; num++) {
25                         key = 7;
26                         ok1(asearch(&key, &arr[start], num, test_cmp) == NULL);
27                         total++;
28                         for (i = start; i < start+num; i++) {
29                                 const int *ret;
30                                 key = arr[i];
31                                 ret = asearch(&key, &arr[start], num, test_cmp);
32                                 ok1(ret);
33                                 ok1(ret && *ret == key);
34                                 total++;
35                         }
36                 }
37         }
38         diag("Tested %u searches\n", total);
39         return exit_status();
40 }