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

Function test_removeNodes

tests/unit/test_graph.c:259–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259void test_removeNodes() {
260 // Construct graph.
261 RG_Matrix M;
262 GrB_Index nnz;
263 Graph *g = Graph_New(32, 32);
264 Graph_AcquireWriteLock(g);
265
266 // Create 3 nodes.
267 Node node;
268 Edge edge;
269
270 for(int i = 0; i < 3; i++) {
271 node = GE_NEW_NODE();
272 Graph_CreateNode(g, &node, NULL, 0);
273 }
274 int r = Graph_AddRelationType(g);
275
276 /* Connections:
277 * 0 connected to 1.
278 * 1 connected to 0.
279 * 1 connected to 2. */
280
281 // connect 0 to 1.
282 Graph_CreateEdge(g, 0, 1, r, &edge);
283
284 // Connect 1 to 0.
285 Graph_CreateEdge(g, 1, 0, r, &edge);
286
287 // Connect 1 to 2.
288 Graph_CreateEdge(g, 1, 2, r, &edge);
289
290 // Validate graph creation.
291 TEST_ASSERT(Graph_NodeCount(g) == 3);
292 M = Graph_GetRelationMatrix(g, r, false);
293 RG_Matrix_nvals(&nnz, M);
294 TEST_ASSERT(nnz == 3);
295
296 M = Graph_GetAdjacencyMatrix(g, false);
297 RG_Matrix_nvals(&nnz, M);
298 TEST_ASSERT(nnz == 3);
299
300 Edge *edges = (Edge *)array_new(Edge, 3);
301
302 //--------------------------------------------------------------------------
303 // Delete node 0
304 //--------------------------------------------------------------------------
305
306 // First node should have 2 edges.
307 Graph_GetNode(g, 0, &node);
308 Graph_GetNodeEdges(g, &node, GRAPH_EDGE_DIR_BOTH, GRAPH_NO_RELATION, &edges);
309 uint edge_count = array_len(edges);
310 TEST_ASSERT(edge_count == 2);
311
312 Graph_DeleteEdges(g, edges, edge_count);
313 Graph_GetNode(g, 0, &node);
314 Graph_DeleteNodes(g, &node, 1);
315
316 Graph_ReleaseLock(g);

Callers

nothing calls this directly

Calls 15

Graph_NewFunction · 0.85
Graph_AcquireWriteLockFunction · 0.85
Graph_CreateNodeFunction · 0.85
Graph_AddRelationTypeFunction · 0.85
Graph_CreateEdgeFunction · 0.85
Graph_NodeCountFunction · 0.85
Graph_GetRelationMatrixFunction · 0.85
RG_Matrix_nvalsFunction · 0.85
Graph_GetAdjacencyMatrixFunction · 0.85
Graph_GetNodeFunction · 0.85
Graph_GetNodeEdgesFunction · 0.85
array_lenFunction · 0.85

Tested by

no test coverage detected