1 /* Include the main header first, to test it works */
2 #include <ccan/sparse_bsearch/sparse_bsearch.h>
3 /* Include the C files directly. */
4 #include <ccan/sparse_bsearch/sparse_bsearch.c>
5 #include <ccan/tap/tap.h>
7 static int cmp(const unsigned int *a, const unsigned int *b)
12 static bool valid(const unsigned int *a)
19 unsigned int i, j, master[4] = { 1, 2, 3, 4 }, arr[4];
21 plan_tests((1 << 4) * 4+ (1 << 3) * 3);
23 /* We test all possibilities of an even and an odd array len. */
24 for (i = 0; i < (1 << 4); i++) {
25 /* Setup partial arr[] */
26 for (j = 0; j < 4; j++) {
33 for (j = 1; j <= 4; j++) {
35 ptr = sparse_bsearch(&j, arr, 4, cmp, valid);
37 ok1(ptr && *ptr == j);
43 for (i = 0; i < (1 << 3); i++) {
44 /* Setup partial arr[] */
45 for (j = 0; j < 3; j++) {
52 for (j = 1; j <= 3; j++) {
54 ptr = sparse_bsearch(&j, arr, 3, cmp, valid);
56 ok1(ptr && *ptr == j);
62 /* This exits depending on whether all tests passed */