test_graph.c 1.1 KB

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