MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_QueryGraphRemoveEntities

Function test_QueryGraphRemoveEntities

tests/unit/test_query_graph.c:218–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216
217
218void test_QueryGraphRemoveEntities() {
219 // create a triangle graph
220 // (A)->(B)->(C)->(A)
221 size_t node_cap = 3;
222 size_t edge_cap = 3;
223
224 // create nodes
225 const char *relation = "R";
226
227 QGNode *A = QGNode_New("A");
228 QGNode *B = QGNode_New("B");
229 QGNode *C = QGNode_New("C");
230
231 QGEdge *AB = QGEdge_New(relation, "AB");
232 QGEdge *BC = QGEdge_New(relation, "BC");
233 QGEdge *CA = QGEdge_New(relation, "CA");
234
235 QueryGraph *g = QueryGraph_New(node_cap, edge_cap);
236 QueryGraph_AddNode(g, A);
237 QueryGraph_AddNode(g, B);
238 QueryGraph_AddNode(g, C);
239
240 QueryGraph_ConnectNodes(g, A, B, AB);
241 QueryGraph_ConnectNodes(g, B, C, BC);
242 QueryGraph_ConnectNodes(g, C, A, CA);
243
244 // remove an edge
245 TEST_ASSERT(contains_edge(g, AB));
246 TEST_ASSERT(QueryGraph_GetEdgeByAlias(g, "AB") != NULL);
247
248 QueryGraph_RemoveEdge(g, AB);
249
250 TEST_ASSERT(!contains_edge(g, AB));
251 TEST_ASSERT(QueryGraph_GetEdgeByAlias(g, "AB") == NULL);
252
253 // remove node
254 TEST_ASSERT(contains_node(g, C));
255 TEST_ASSERT(QueryGraph_GetNodeByAlias(g, "C") != NULL);
256
257 QueryGraph_RemoveNode(g, C);
258
259 TEST_ASSERT(!contains_node(g, C));
260 TEST_ASSERT(QueryGraph_GetNodeByAlias(g, "C") == NULL);
261
262 // both CA BC edges should be removed
263 TEST_ASSERT(!contains_edge(g, CA));
264 TEST_ASSERT(QueryGraph_GetEdgeByAlias(g, "CA") == NULL);
265
266 TEST_ASSERT(!contains_edge(g, BC));
267 TEST_ASSERT(QueryGraph_GetEdgeByAlias(g, "BC") == NULL);
268
269 // assert entity count:
270 // nodes - A was removed
271 // edges - AB explicitly removed, BC and CA implicitly removed
272 TEST_ASSERT(QueryGraph_NodeCount(g) == 2);
273 TEST_ASSERT(QueryGraph_EdgeCount(g) == 0);
274
275 // assert remaining entities

Callers

nothing calls this directly

Calls 15

QGNode_NewFunction · 0.85
QGEdge_NewFunction · 0.85
QueryGraph_NewFunction · 0.85
QueryGraph_AddNodeFunction · 0.85
QueryGraph_ConnectNodesFunction · 0.85
contains_edgeFunction · 0.85
QueryGraph_RemoveEdgeFunction · 0.85
contains_nodeFunction · 0.85
QueryGraph_RemoveNodeFunction · 0.85
QueryGraph_NodeCountFunction · 0.85

Tested by

no test coverage detected