Add VertexMap tests for Graph (vertex deletion)
This commit is contained in:
+42
-1
@@ -51,7 +51,8 @@ impl<V: Copy, T: Clone> IndexMut<V> for VertexMap<V, T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::models::append_graph::AppendGraph;
|
use crate::models::append_graph::AppendGraph;
|
||||||
use crate::traits::GraphTopology;
|
use crate::models::graph::Graph;
|
||||||
|
use crate::traits::{GraphTopology, GraphTopologyDeletion};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn initial_values_are_default() {
|
fn initial_values_are_default() {
|
||||||
@@ -119,4 +120,44 @@ mod tests {
|
|||||||
map.sync(&graph);
|
map.sync(&graph);
|
||||||
assert_eq!(map[v], 5);
|
assert_eq!(map[v], 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn surviving_vertex_readable_after_delete() {
|
||||||
|
let mut graph = Graph::new();
|
||||||
|
let v1 = graph.add_vertex();
|
||||||
|
let v2 = graph.add_vertex();
|
||||||
|
let mut map = graph.vertex_map(0);
|
||||||
|
map[v1] = 1;
|
||||||
|
map[v2] = 2;
|
||||||
|
graph.delete_vertex(v2);
|
||||||
|
assert_eq!(map[v1], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn capacity_does_not_shrink_after_delete() {
|
||||||
|
let mut graph = Graph::new();
|
||||||
|
let v1 = graph.add_vertex();
|
||||||
|
let v2 = graph.add_vertex();
|
||||||
|
let mut map = graph.vertex_map(0);
|
||||||
|
let capacity_before = graph.vertex_capacity();
|
||||||
|
graph.delete_vertex(v2);
|
||||||
|
map.sync(&graph);
|
||||||
|
assert_eq!(map.data.len(), capacity_before);
|
||||||
|
assert_eq!(map[v1], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reused_slot_returns_old_value() {
|
||||||
|
let mut graph = Graph::new();
|
||||||
|
graph.add_vertex();
|
||||||
|
let v1 = graph.add_vertex();
|
||||||
|
let mut map = graph.vertex_map(0);
|
||||||
|
map[v1] = 99;
|
||||||
|
graph.delete_vertex(v1);
|
||||||
|
let v2 = graph.add_vertex();
|
||||||
|
// VertexMap uses raw indices, not vertex identity. A new vertex v2 reusing the slot of
|
||||||
|
// previously deleted vertex v1 sees the old value. Callers must reinitialize stale
|
||||||
|
// slots after deletion.
|
||||||
|
assert_eq!(map[v2], 99);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user