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

Function test_getEdge

tests/unit/test_graph.c:354–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352}
353
354void test_getEdge() {
355 /* Create a graph with both nodes and edges.
356 * Make sure edge retrival works as expected:
357 * 1. try to get edges by ID
358 * 2. try to get edges connecting source to destination node
359 * 3. try to get none existing edges. */
360
361 Node n;
362 Edge e;
363 int relationCount = 4;
364 size_t nodeCount = 5;
365 size_t edgeCount = 5;
366 int relations[relationCount];
367
368 Graph *g = Graph_New(nodeCount, nodeCount);
369 Graph_AcquireWriteLock(g);
370 for(int i = 0; i < nodeCount; i++) {
371 n = GE_NEW_NODE();
372 Graph_CreateNode(g, &n, NULL, 0);
373 }
374 for(int i = 0; i < relationCount; i++) relations[i] = Graph_AddRelationType(g);
375
376 /* Connect nodes:
377 * 1. nodes (0-1) will be connected by relation 0.
378 * 2. nodes (0-1) will be connected by relation 1.
379 * 3. nodes (1-2) will be connected by relation 1.
380 * 4. nodes (2-3) will be connected by relation 2.
381 * 5. nodes (3-4) will be connected by relation 3. */
382
383 Graph_CreateEdge(g, 0, 1, relations[0], &e);
384 Graph_CreateEdge(g, 0, 1, relations[1], &e);
385 Graph_CreateEdge(g, 1, 2, relations[1], &e);
386 Graph_CreateEdge(g, 2, 3, relations[2], &e);
387 Graph_CreateEdge(g, 3, 4, relations[3], &e);
388
389 // Validations
390 // Try to get edges by ID
391 for(EdgeID i = 0; i < edgeCount; i++) {
392 Graph_GetEdge(g, i, &e);
393 TEST_ASSERT(e.attributes != NULL);
394 TEST_ASSERT(e.id == i);
395 }
396
397 // Try to get edges connecting source to destination node.
398 NodeID src;
399 NodeID dest;
400 int relation;
401 Edge *edges = (Edge *)array_new(Edge, 4);
402
403 /* Get all edges connecting node 0 to node 1,
404 * expecting 2 edges. */
405 src = 0;
406 dest = 1;
407 relation = GRAPH_NO_RELATION; // Relation agnostic.
408 Graph_GetEdgesConnectingNodes(g, src, dest, relation, &edges);
409 TEST_ASSERT(array_len(edges) == 2);
410 for(int i = 0; i < 2; i++) {
411 e = edges[i];

Callers

nothing calls this directly

Calls 14

Graph_NewFunction · 0.85
Graph_AcquireWriteLockFunction · 0.85
Graph_CreateNodeFunction · 0.85
Graph_AddRelationTypeFunction · 0.85
Graph_CreateEdgeFunction · 0.85
Graph_GetEdgeFunction · 0.85
array_lenFunction · 0.85
Edge_GetSrcNodeIDFunction · 0.85
Edge_GetDestNodeIDFunction · 0.85
Edge_GetRelationIDFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected