run.c 859 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. static int test_cmp(const int *key, const int *elt)
  6. {
  7. if (*key < *elt)
  8. return -1;
  9. else if (*key > *elt)
  10. return 1;
  11. return 0;
  12. }
  13. int main(void)
  14. {
  15. const int arr[] = { INT_MIN, 0, 1, 2, 3, 4, 5, 6, INT_MAX };
  16. unsigned int start, num, i, total = 0;
  17. int key;
  18. plan_tests(285);
  19. for (start = 0; start < ARRAY_SIZE(arr); start++) {
  20. for (num = 0; num < ARRAY_SIZE(arr) - start; num++) {
  21. key = 7;
  22. ok1(asearch(&key, &arr[start], num, test_cmp) == NULL);
  23. total++;
  24. for (i = start; i < start+num; i++) {
  25. const int *ret;
  26. key = arr[i];
  27. ret = asearch(&key, &arr[start], num, test_cmp);
  28. ok1(ret);
  29. ok1(ret && *ret == key);
  30. total++;
  31. }
  32. }
  33. }
  34. diag("Tested %u searches\n", total);
  35. return exit_status();
  36. }