test.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "Neighborhood.h"
  4. #include "MaxHeap.h"
  5. #ifdef DoTest
  6. void printHeap(const MaxHeap * heap) {
  7. pyWord p;
  8. printf("%u / %u\n", (unsigned int)heap->size, (unsigned int)heap->maxItems);
  9. for(p = 0; p < heap->size; p ++) {
  10. printf("[%u] %u -> %lf\n", (unsigned int) p, (unsigned int)heap->indices[p], heap->distances[p]);
  11. }
  12. }
  13. int main(void) {
  14. #define testcases 5
  15. pyReal distances[testcases];
  16. pyWord idxs[testcases];
  17. MaxHeap heap = {
  18. .distances = distances,
  19. .indices = idxs,
  20. .maxItems = testcases,
  21. .size = 1
  22. };
  23. distances[0] = 0.0;
  24. idxs[0] = 999;
  25. printHeap(&heap);
  26. maxHeap_insert(&heap, 6, 6.0);
  27. maxHeap_insert(&heap, 1, 1.0);
  28. maxHeap_insert(&heap, 4, 4.0);
  29. maxHeap_insert(&heap, 3, 3.0);
  30. maxHeap_insert(&heap, 2, 2.0);
  31. maxHeap_insert(&heap, 5, 5.0);
  32. printHeap(&heap);
  33. #define nPoints 9
  34. #define nbhSize 5
  35. pyWord nbh[nPoints * nbhSize];
  36. pyReal points[2 * nPoints];
  37. int x, y, p;
  38. p = 0;
  39. for(y = 0; y < 3 ; y ++) {
  40. for(x = 0; x < 3 ; x ++) {
  41. points[p] = x;
  42. points[p + 1] = y;
  43. printf("%d: (%d,%d)\n", p/2, x, y);
  44. p += 2;
  45. }
  46. }
  47. Neighborhood(nbhSize, nPoints, 2, points, nbh);
  48. for(y = 0; y < nPoints; y++) {
  49. pyWord * p = &nbh[y * nbhSize];
  50. printf("%d [%d,%d] ", y, y % 3, y / 3);
  51. for(x = 0; x < nbhSize ; x ++) {
  52. printf(" (%u|%u,%u)", (unsigned int)p[x], (unsigned int)(p[x] % 3), (unsigned int)(p[x] / 3));
  53. }
  54. printf("\n");
  55. }
  56. }
  57. #endif