graph_api_test/index/
vertex_hash.rs
1#[cfg(feature = "vertex-hash-index")]
2use crate::{PersonMut, assert_elements_eq, populate_graph};
3#[cfg(feature = "vertex-hash-index")]
4use graph_api_lib::VertexReferenceMut;
5
6use crate::{Edge, Vertex};
7use graph_api_lib::Graph;
8
9#[cfg(feature = "vertex-hash-index")]
16pub fn test_index<T>(graph: &mut T)
17where
18 T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexHashIndex,
19{
20 let refs = populate_graph(graph);
21 let collected = graph
22 .walk()
23 .vertices(Vertex::person_by_name("Bryn"))
24 .collect::<Vec<_>>();
25 assert_elements_eq!(graph, collected, vec![refs.bryn]);
26}
27
28#[cfg(not(feature = "vertex-hash-index"))]
29pub fn test_index<T>(_graph: &mut T)
30where
31 T: Graph<Vertex = Vertex, Edge = Edge>,
32{
33}
34#[cfg(all(feature = "vertex-hash-index", feature = "element-removal"))]
41pub fn test_index_remove<T>(graph: &mut T)
42where
43 T: Graph<Vertex = Vertex, Edge = Edge>
44 + graph_api_lib::SupportsVertexHashIndex
45 + graph_api_lib::SupportsElementRemoval,
46{
47 let refs = populate_graph(graph);
48 graph.remove_vertex(refs.bryn);
49 assert_eq!(
50 graph
51 .walk()
52 .vertices(Vertex::person_by_name("Bryn"))
53 .count(),
54 0
55 );
56}
57
58#[cfg(not(all(feature = "vertex-hash-index", feature = "element-removal")))]
59pub fn test_index_remove<T>(_graph: &mut T)
60where
61 T: Graph<Vertex = Vertex, Edge = Edge>,
62{
63}
64
65#[cfg(feature = "vertex-hash-index")]
66pub fn test_index_update<T>(graph: &mut T)
67where
68 T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexHashIndex,
69{
70 let refs = populate_graph(graph);
71 graph
72 .vertex_mut(refs.bryn)
73 .expect("bryn must exist")
74 .project_mut::<PersonMut<_, _>>()
75 .expect("must be a person")
76 .set_name("Dyllan".to_string());
77 assert_eq!(
78 graph
79 .walk()
80 .vertices(Vertex::person_by_name("Bryn"))
81 .count(),
82 0
83 );
84 assert_eq!(
85 graph
86 .walk()
87 .vertices(Vertex::person_by_name("Dyllan"))
88 .count(),
89 1
90 );
91}
92
93#[cfg(not(feature = "vertex-hash-index"))]
94pub fn test_index_update<T>(_graph: &mut T)
95where
96 T: Graph<Vertex = Vertex, Edge = Edge>,
97{
98}