test_graph.c 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "test.h"
  2. #include "graph.h"
  3. #include "assets.h"
  4. static int test_graph_heap()
  5. {
  6. LSUP_Graph *gr = LSUP_graph_new(10, "urn:gr:1", LSUP_STORE_MEM);
  7. ASSERT(strcmp(LSUP_graph_uri(gr)->data, "urn:gr:1") == 0, "Graph URI mismatch!");
  8. EXPECT_INT_EQ(LSUP_graph_size(gr), 0);
  9. LSUP_graph_free(gr);
  10. return 0;
  11. }
  12. static int test_graph_add()
  13. {
  14. LSUP_Triple *trp = create_triples();
  15. LSUP_Graph *gr = LSUP_graph_new(NUM_TRP + 2, "urn:gr:2", LSUP_STORE_MEM);
  16. LSUP_graph_add(gr, trp, NUM_TRP);
  17. for (int i = 0; i < sizeof(trp); i++) {
  18. printf("checking triple #%d... ", i);
  19. ASSERT(LSUP_graph_contains(gr, trp + i), "Triple not in graph!");
  20. printf("OK.\n");
  21. }
  22. free_triples(trp); // gr copied data.
  23. EXPECT_INT_EQ(LSUP_graph_size(gr), 8);
  24. LSUP_graph_free(gr);
  25. return 0;
  26. }
  27. int graph_tests()
  28. {
  29. RUN(test_graph_heap);
  30. RUN(test_graph_add);
  31. return 0;
  32. }