2
0

test_bubbles.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "describe.h"
  2. #define PAR_BUBBLES_IMPLEMENTATION
  3. #include "par_bubbles.h"
  4. static par_bubbles_t* bubbles;
  5. #define NRADIUSES 100
  6. static double radiuses[NRADIUSES];
  7. #define NNODES 252
  8. static int hierarchy[NNODES] = {
  9. 0, 0, 1, 2, 2, 2, 2, 1, 7, 7, 7, 7,
  10. 7, 1, 13, 0, 15, 15, 15, 18, 18, 18, 18, 18,
  11. 18, 18, 18, 18, 15, 15, 15, 15, 15, 15, 15, 15,
  12. 15, 0, 37, 38, 38, 38, 38, 38, 37, 37, 37, 37,
  13. 37, 37, 0, 50, 50, 50, 50, 0, 55, 0, 57, 57,
  14. 57, 57, 57, 57, 57, 57, 0, 66, 66, 66, 66, 66,
  15. 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
  16. 66, 66, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
  17. 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
  18. 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 66, 66,
  19. 66, 66, 66, 66, 66, 66, 66, 66, 0, 128, 128, 128,
  20. 128, 128, 128, 128, 128, 128, 128, 0, 139, 139, 139, 139,
  21. 139, 139, 139, 146, 146, 139, 139, 139, 139, 152, 152, 152,
  22. 139, 139, 139, 158, 158, 158, 158, 139, 139, 139, 139, 139,
  23. 0, 168, 169, 169, 169, 169, 169, 168, 175, 175, 175, 175,
  24. 175, 175, 175, 175, 175, 175, 175, 168, 187, 187, 187, 187,
  25. 187, 187, 193, 193, 193, 193, 187, 187, 187, 168, 201, 201,
  26. 201, 201, 168, 206, 206, 206, 168, 210, 211, 211, 211, 210,
  27. 215, 215, 215, 215, 215, 210, 221, 221, 221, 210, 210, 226,
  28. 226, 226, 210, 230, 230, 230, 230, 230, 230, 230, 230, 230,
  29. 230, 230, 230, 230, 230, 230, 210, 210, 210, 210, 210, 168,
  30. };
  31. int main()
  32. {
  33. for (int i = 0; i < NRADIUSES; i++) {
  34. radiuses[i] = 1 + rand() % 10;
  35. }
  36. describe("par_bubbles_pack") {
  37. it("should pass a simple smoke test") {
  38. bubbles = par_bubbles_pack(radiuses, NRADIUSES);
  39. assert_ok(bubbles);
  40. assert_equal(bubbles->count, (int) NRADIUSES);
  41. par_bubbles_export(bubbles, "build/test_bubbles_pack.svg");
  42. par_bubbles_free_result(bubbles);
  43. }
  44. it("should handle a small number of nodes") {
  45. bubbles = par_bubbles_pack(radiuses, 0);
  46. par_bubbles_export(bubbles, "build/test_bubbles_pack0.svg");
  47. par_bubbles_free_result(bubbles);
  48. bubbles = par_bubbles_pack(radiuses, 1);
  49. par_bubbles_export(bubbles, "build/test_bubbles_pack1.svg");
  50. par_bubbles_free_result(bubbles);
  51. bubbles = par_bubbles_pack(radiuses, 2);
  52. par_bubbles_export(bubbles, "build/test_bubbles_pack2.svg");
  53. par_bubbles_free_result(bubbles);
  54. bubbles = par_bubbles_pack(radiuses, 3);
  55. par_bubbles_export(bubbles, "build/test_bubbles_pack3.svg");
  56. par_bubbles_free_result(bubbles);
  57. }
  58. it("should work with small hierarchy") {
  59. static int hierarchy[10] = {
  60. 0, 0, 0, 0, 1, 1, 2,
  61. 5, 5, 5,
  62. };
  63. bubbles = par_bubbles_hpack_circle(hierarchy, 10, 100);
  64. par_bubbles_export(bubbles, "build/test_bubbles_hpack_circle1.svg");
  65. par_bubbles_free_result(bubbles);
  66. }
  67. it("should work with big hierarchy") {
  68. bubbles = par_bubbles_hpack_circle(hierarchy, NNODES, 100);
  69. par_bubbles_export(bubbles, "build/test_bubbles_hpack_circle2.svg");
  70. par_bubbles_free_result(bubbles);
  71. }
  72. }
  73. return assert_failures();
  74. }