graph_api_test/index/
vertex_range.rs1use crate::{Edge, PersonMut, Vertex, assert_elements_eq, populate_graph};
2use graph_api_lib::{Graph, SupportsVertexHashIndex, SupportsVertexRangeIndex, VertexReferenceMut};
3
4pub fn test_index<T>(graph: &mut T)
5where
6 T: Graph<Vertex = Vertex, Edge = Edge> + SupportsVertexRangeIndex + SupportsVertexHashIndex,
7{
8 let refs = populate_graph(graph);
9 let collected = graph
11 .walk()
12 .vertices(Vertex::person_by_age_range(20..46))
13 .collect::<Vec<_>>();
14 assert_elements_eq!(graph, collected, vec![refs.bryn]);
15
16 let collected = graph
17 .walk()
18 .vertices(Vertex::person_by_age(45))
19 .collect::<Vec<_>>();
20 assert_elements_eq!(graph, collected, vec![refs.bryn]);
21}
22
23pub fn test_index_remove<T>(graph: &mut T)
24where
25 T: Graph<Vertex = Vertex, Edge = Edge> + SupportsVertexRangeIndex,
26{
27 let refs = populate_graph(graph);
28 graph.remove_vertex(refs.bryn).expect("person must exist");
30
31 assert_eq!(
33 graph
34 .walk()
35 .vertices(Vertex::person_by_age_range(20..46))
36 .count(),
37 0
38 );
39}
40
41pub fn test_index_update<T>(graph: &mut T)
42where
43 T: Graph<Vertex = Vertex, Edge = Edge> + SupportsVertexRangeIndex,
44{
45 let refs = populate_graph(graph);
46 graph
47 .vertex_mut(refs.bryn)
48 .expect("person must exist")
49 .project_mut::<PersonMut<_, _>>()
50 .expect("person")
51 .set_age(100);
52
53 let collected = graph
55 .walk()
56 .vertices(Vertex::person_by_age_range(20..46))
57 .count();
58 assert_eq!(collected, 0);
59
60 let collected = graph
61 .walk()
62 .vertices(Vertex::person_by_age_range(100..106))
63 .collect::<Vec<_>>();
64 assert_elements_eq!(graph, collected, vec![refs.bryn]);
65}