Prechádzať zdrojové kódy

Fix lookup count value for empty graph.

scossu 15 hodín pred
rodič
commit
d00c8d359a
2 zmenil súbory, kde vykonal 15 pridanie a 8 odobranie
  1. 1 2
      src/store_htable.c
  2. 14 6
      test/test_graph.c

+ 1 - 2
src/store_htable.c

@@ -295,9 +295,8 @@ htstore_lookup (
     it->store = store;
     it->rc = LSUP_END;
 
-    if (hashmap_count (store->keys) == 0) return it;
-
     if (ct) *ct = 0;
+    if (hashmap_count (store->keys) == 0) return it;
 
     it->luk[0] = LSUP_buffer_hash (ss);
     it->luk[1] = LSUP_buffer_hash (sp);

+ 14 - 6
test/test_graph.c

@@ -49,12 +49,11 @@ _graph_add (LSUP_StoreType type)
 
     LSUP_Graph *gr;
     LSUP_Store *store;
-    if (type == LSUP_STORE_HTABLE) {
-        gr = LSUP_graph_new (NULL, NULL, NULL);
-    } else {
-        store = LSUP_store_new (type, NULL, 0);
-        gr = LSUP_graph_new (store, NULL, NULL);
-    }
+
+    if (type = LSUP_STORE_HTABLE) store = NULL;
+    else store = LSUP_store_new (type, NULL, 0);
+
+    gr = LSUP_graph_new (store, NULL, NULL);
     ASSERT (gr != NULL, "Error creating graph!");
 
     size_t ct;
@@ -75,6 +74,15 @@ _graph_add (LSUP_StoreType type)
 
     free_triples (trp); // gr copied data.
 
+    // Check size again after freeing triples.
+    EXPECT_INT_EQ (LSUP_graph_size (gr), 8);
+
+    LSUP_Graph *gr2 = LSUP_graph_new (NULL, NULL, NULL);
+
+    // Test equality against empty graph.
+    ASSERT (!LSUP_graph_equals (gr, gr2), "Graphs should not be equal!");
+    ASSERT (!LSUP_graph_equals (gr2, gr), "Graphs should not be equal!");
+
     LSUP_graph_free (gr);
     if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);