Add ElementMap::reserve to replace ElementMap::expand, update tests
ElementMap tests are now self contained unit tests, without any graph context. The only exception is the repurposed test "reused_slot_returns_old_value", which is not suited for GraphTopologyDeletion, but actually specific for Graph.
This commit is contained in:
@@ -420,4 +420,27 @@ mod tests {
|
||||
graph.delete_edge(f);
|
||||
assert_eq!(graph.edge_count(), 0, "unexpected edge count after delete");
|
||||
}
|
||||
|
||||
#[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();
|
||||
assert_eq!(
|
||||
v1.arr_idx(),
|
||||
v2.arr_idx(),
|
||||
"precondition: new vertex {v1:?} should reuse slot of deleted vertex {v2:?}"
|
||||
);
|
||||
// ElementMap uses raw indices, not vertex identity. A new vertex v2 reusing the slot
|
||||
// of previously deleted v1 sees the old value. Callers must reinitialize stale slots
|
||||
// after deletion.
|
||||
assert_eq!(
|
||||
map[v2], 99,
|
||||
"new vertex reusing slot of deleted vertex should return old value"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user