graph_api_test/index/
vertex_range.rs1#[cfg(feature = "vertex-range-index")]
2use crate::{PersonMut, assert_elements_eq, populate_graph};
3#[cfg(feature = "vertex-range-index")]
4use graph_api_lib::VertexReferenceMut;
5
6use crate::{Edge, Vertex};
7use graph_api_lib::Graph;
8
9#[cfg(feature = "vertex-range-index")]
10pub fn test_index<T>(graph: &mut T)
11where
12 T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexRangeIndex,
13{
14 let refs = populate_graph(graph);
15 let collected = graph
17 .walk()
18 .vertices(Vertex::person_by_age_range(20..46))
19 .collect::<Vec<_>>();
20 assert_elements_eq!(graph, collected, vec![refs.bryn]);
21}
22
23#[cfg(not(feature = "vertex-range-index"))]
24pub fn test_index<T>(_graph: &mut T)
25where
26 T: Graph<Vertex = Vertex, Edge = Edge>,
27{
28}
29
30#[cfg(all(feature = "vertex-range-index", feature = "element-removal"))]
31pub fn test_index_remove<T>(graph: &mut T)
32where
33 T: Graph<Vertex = Vertex, Edge = Edge>
34 + graph_api_lib::SupportsVertexRangeIndex
35 + graph_api_lib::SupportsElementRemoval,
36{
37 let refs = populate_graph(graph);
38 graph.remove_vertex(refs.bryn).expect("person must exist");
40
41 assert_eq!(
43 graph
44 .walk()
45 .vertices(Vertex::person_by_age_range(20..46))
46 .count(),
47 0
48 );
49}
50
51#[cfg(not(all(feature = "element-removal", feature = "vertex-range-index")))]
52pub fn test_index_remove<T>(_graph: &mut T)
53where
54 T: Graph<Vertex = Vertex, Edge = Edge>,
55{
56}
57
58#[cfg(feature = "vertex-range-index")]
59pub fn test_index_update<T>(graph: &mut T)
60where
61 T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexRangeIndex,
62{
63 let refs = populate_graph(graph);
64 graph
65 .vertex_mut(refs.bryn)
66 .expect("person must exist")
67 .project_mut::<PersonMut<_, _>>()
68 .expect("person")
69 .set_age(100);
70
71 let collected = graph
73 .walk()
74 .vertices(Vertex::person_by_age_range(20..46))
75 .count();
76 assert_eq!(collected, 0);
77
78 let collected = graph
79 .walk()
80 .vertices(Vertex::person_by_age_range(100..106))
81 .collect::<Vec<_>>();
82 assert_elements_eq!(graph, collected, vec![refs.bryn]);
83}
84
85#[cfg(not(feature = "vertex-range-index"))]
86pub fn test_index_update<T>(_graph: &mut T)
87where
88 T: Graph<Vertex = Vertex, Edge = Edge>,
89{
90}