Add GraphTopologyConversion tests related to addition and deletion
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::testing::fixtures;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
use crate::traits::{GraphTopologyConversion, GraphTopologyDeletion};
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! graph_topology_deletion_conversion_tests {
|
||||
($T:ty, $U:ty) => {
|
||||
$crate::graph_topology_deletion_conversion_tests!(@wrap $T, $U,
|
||||
convert_after_deletion,
|
||||
);
|
||||
};
|
||||
|
||||
(@wrap $T:ty, $U:ty, $($name:ident),* $(,)?) => {
|
||||
$(
|
||||
#[test]
|
||||
fn $name() {
|
||||
$crate::testing::graph_topology_deletion_conversion_testing::$name::<$T, $U>();
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
pub fn convert_after_deletion<G, H>()
|
||||
where
|
||||
G: GraphTopologyConversion,
|
||||
H: MakeTestGraph + GraphTopologyDeletion,
|
||||
G::Vertex: Debug,
|
||||
G::Edge: Debug,
|
||||
H::Vertex: Debug,
|
||||
H::Edge: Debug,
|
||||
{
|
||||
let (mut source, vertices, edges, _) = H::standard();
|
||||
|
||||
// Deletes a vertex together with its incident edges, which leaves gaps in the source's slots.
|
||||
let del = vertices[2];
|
||||
source.delete_vertex(del);
|
||||
let vertices: Vec<_> = vertices.into_iter().filter(|&v| v != del).collect();
|
||||
let edges: Vec<_> = edges
|
||||
.into_iter()
|
||||
.filter(|&(_, u, v)| u != del && v != del)
|
||||
.collect();
|
||||
|
||||
let (graph, iso) = G::convert(&source);
|
||||
fixtures::assert_isomorphic(
|
||||
&source,
|
||||
&graph,
|
||||
&vertices,
|
||||
|v| iso.vertex(v),
|
||||
&edges,
|
||||
|e| iso.edge(e),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user