1use crate::{Edge, Vertex, populate_graph};
2use graph_api_lib::{EdgeReference, EdgeSearch, Graph, VertexReference, VertexSearch};
34/// Test vertex fold operations
5pub fn test_vertices_fold<G>(graph: &mut G)
6where
7G: Graph<Vertex = Vertex, Edge = Edge>,
8{
9// Populate the graph with test data
10let _refs = populate_graph(graph);
1112// Calculate the sum of ages using fold
13let total_age = graph
14 .walk()
15 .vertices(VertexSearch::scan())
16 .fold(0, |total, vertex, _| {
17if let Vertex::Person { age, .. } = *vertex.weight() {
18 total + age
19 } else {
20 total
21 }
22 });
2324// Check that the total age is positive - should include Bryn and Julia
25assert_eq!(total_age, 93);
26}
2728/// Test edge fold operations
29pub fn test_edges_fold<G>(graph: &mut G)
30where
31G: Graph<Vertex = Vertex, Edge = Edge>,
32{
33// Populate the graph with test data
34let _refs = populate_graph(graph);
3536// Find the relationship year in the graph
37let knows_year = graph
38 .walk()
39 .vertices(VertexSearch::scan())
40 .edges(EdgeSearch::scan())
41 .fold(None, |result, edge, _| {
42if let Edge::Knows { since } = edge.weight() {
43Some(*since)
44 } else {
45 result
46 }
47 });
4849// There should be at least one relationship with a year
50assert!(knows_year.is_some());
51// The standard test data uses 1999
52assert_eq!(knows_year.unwrap(), 1999);
53}