graph_api_test/steps/
mutate_context.rs1use crate::{Edge, Vertex, populate_graph};
2use graph_api_lib::{EdgeSearch, Graph};
3
4pub 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 let ctx = graph
13 .walk()
14 .vertices_by_id(vec![refs.bryn])
15 .push_context(|_, _| 0)
16 .mutate_context(|_, ctx| {
17 **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 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 **ctx += 1;
42 })
43 .map(|_, ctx| *ctx)
44 .last()
45 .expect("Expected to process at least one vertex");
46
47 assert_eq!(ctx, 2, "Should have processed two edges");
49}