graph_api_test/steps/
mutate_context.rs

1use crate::{Edge, Vertex, populate_graph};
2use graph_api_lib::{EdgeSearch, Graph};
3
4// Note: Here we're simply testing that the mutate_context step exists and is called for each element
5pub fn test_vertex_mutate_context<T>(graph: &mut T)
6where
7    T: Graph<Vertex = Vertex, Edge = Edge>,
8{
9    let refs = populate_graph(graph);
10
11    // Use mutate_context to verify the callback is run for each element
12    let ctx = graph
13        .walk()
14        .vertices_by_id(vec![refs.bryn])
15        .push_context(|_, _| 0)
16        .mutate_context(|_, ctx| {
17            // Just track that the callback was called
18            **ctx += 1;
19        })
20        .map(|_, ctx| *ctx)
21        .next()
22        .expect("Expected to process at least one vertex");
23
24    assert_eq!(ctx, 1, "Should have processed one vertex");
25}
26
27pub fn test_edge_mutate_context<T>(graph: &mut T)
28where
29    T: Graph<Vertex = Vertex, Edge = Edge>,
30{
31    let refs = populate_graph(graph);
32
33    // Use mutate_context to verify the callback is run for each element
34    let ctx = graph
35        .walk()
36        .vertices_by_id(vec![refs.bryn])
37        .push_context(|_, _| 0)
38        .edges(EdgeSearch::scan().outgoing())
39        .mutate_context(|_, ctx| {
40            // Just track that the callback was called
41            **ctx += 1;
42        })
43        .map(|_, ctx| *ctx)
44        .last()
45        .expect("Expected to process at least one vertex");
46
47    // Verify we processed at least one element
48    assert_eq!(ctx, 2, "Should have processed two edges");
49}