1use crate::{Edge, Vertex, populate_graph};
2use graph_api_lib::{EdgeSearch, Graph};
34// 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
7T: Graph<Vertex = Vertex, Edge = Edge>,
8{
9let refs = populate_graph(graph);
1011// Use mutate_context to verify the callback is run for each element
12let 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");
2324assert_eq!(ctx, 1, "Should have processed one vertex");
25}
2627pub fn test_edge_mutate_context<T>(graph: &mut T)
28where
29T: Graph<Vertex = Vertex, Edge = Edge>,
30{
31let refs = populate_graph(graph);
3233// Use mutate_context to verify the callback is run for each element
34let 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");
4647// Verify we processed at least one element
48assert_eq!(ctx, 2, "Should have processed two edges");
49}