Extract asserts from Clone tests to be reusable
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::testing::fixtures;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
use crate::traits::GraphTopologyAddition;
|
||||
|
||||
@@ -6,7 +7,7 @@ use crate::traits::GraphTopologyAddition;
|
||||
macro_rules! graph_topology_addition_clone_tests {
|
||||
($T:ty) => {
|
||||
$crate::graph_topology_addition_clone_tests!(@wrap $T,
|
||||
clone_independent,
|
||||
clone_mutation_independent,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -20,37 +21,8 @@ macro_rules! graph_topology_addition_clone_tests {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn clone_independent<G: Clone + GraphTopologyAddition>() {
|
||||
let (mut graph, [u, v], _) = G::single_edge();
|
||||
pub fn clone_mutation_independent<G: Clone + GraphTopologyAddition>() {
|
||||
let (mut graph, vertices, _) = G::single_edge();
|
||||
let mut clone = graph.clone();
|
||||
|
||||
let w = clone.add_vertex();
|
||||
clone.add_edge(u, w);
|
||||
assert_eq!(clone.vertex_count(), 3, "precondition: vertex count of clone");
|
||||
assert_eq!(clone.edge_count(), 2, "precondition: edge count of clone");
|
||||
assert_eq!(
|
||||
graph.vertex_count(),
|
||||
2,
|
||||
"mutating the clone should not affect the vertex count of the original"
|
||||
);
|
||||
assert_eq!(
|
||||
graph.edge_count(),
|
||||
1,
|
||||
"mutating the clone should not affect the edge count of the original"
|
||||
);
|
||||
|
||||
let x = graph.add_vertex();
|
||||
graph.add_edge(v, x);
|
||||
assert_eq!(graph.vertex_count(), 3, "precondition: vertex count of original");
|
||||
assert_eq!(graph.edge_count(), 2, "precondition: edge count of original");
|
||||
assert_eq!(
|
||||
clone.vertex_count(),
|
||||
3,
|
||||
"mutating the original should not affect the vertex count of the clone"
|
||||
);
|
||||
assert_eq!(
|
||||
clone.edge_count(),
|
||||
2,
|
||||
"mutating the original should not affect the edge count of the clone"
|
||||
);
|
||||
fixtures::assert_mutation_independent(&mut graph, &mut clone, &vertices, |v| v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user