Add ElementMap conversion tests via new GraphIsomorphism
This commit is contained in:
@@ -8,6 +8,7 @@ macro_rules! graph_topology_addition_conversion_tests {
|
|||||||
($T:ty, $U:ty) => {
|
($T:ty, $U:ty) => {
|
||||||
$crate::graph_topology_addition_conversion_tests!(@wrap $T, $U,
|
$crate::graph_topology_addition_conversion_tests!(@wrap $T, $U,
|
||||||
convert_mutation_independent,
|
convert_mutation_independent,
|
||||||
|
convert_map_stale_source_map,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -30,3 +31,35 @@ where
|
|||||||
let (mut graph, iso) = G::convert(&source);
|
let (mut graph, iso) = G::convert(&source);
|
||||||
fixtures::assert_mutation_independent(&mut source, &mut graph, &vertices, |v| iso.vertex(v));
|
fixtures::assert_mutation_independent(&mut source, &mut graph, &vertices, |v| iso.vertex(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn convert_map_stale_source_map<G, H>()
|
||||||
|
where
|
||||||
|
G: GraphTopologyConversion + GraphTopologyAddition,
|
||||||
|
H: MakeTestGraph + GraphTopologyAddition,
|
||||||
|
{
|
||||||
|
let (mut source, [u, v], _) = H::single_edge();
|
||||||
|
let mut source_map = source.vertex_map(9);
|
||||||
|
source_map[u] = 1;
|
||||||
|
source_map[v] = 2;
|
||||||
|
let added = add_vertices_until_capacity_grows(&mut source);
|
||||||
|
let (_, iso) = G::convert(&source);
|
||||||
|
let map = iso.convert_vertex_map(&source_map);
|
||||||
|
assert_eq!(map[iso.vertex(u)], 1, "unexpected value for first vertex");
|
||||||
|
assert_eq!(map[iso.vertex(v)], 2, "unexpected value for second vertex");
|
||||||
|
for w in added {
|
||||||
|
assert_eq!(
|
||||||
|
map[iso.vertex(w)],
|
||||||
|
9,
|
||||||
|
"vertex not covered by the source map should hold the default"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_vertices_until_capacity_grows<G: GraphTopologyAddition>(graph: &mut G) -> Vec<G::Vertex> {
|
||||||
|
let capacity = graph.vertex_capacity();
|
||||||
|
let mut added = Vec::new();
|
||||||
|
while graph.vertex_capacity() == capacity {
|
||||||
|
added.push(graph.add_vertex());
|
||||||
|
}
|
||||||
|
added
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ macro_rules! graph_topology_conversion_tests {
|
|||||||
$crate::graph_topology_conversion_tests!(@wrap $T, $U,
|
$crate::graph_topology_conversion_tests!(@wrap $T, $U,
|
||||||
convert,
|
convert,
|
||||||
convert_empty,
|
convert_empty,
|
||||||
|
convert_vertex_map,
|
||||||
|
convert_edge_map,
|
||||||
|
convert_vertex_map_defaults,
|
||||||
|
convert_edge_map_defaults,
|
||||||
|
convert_map_empty,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,3 +66,89 @@ where
|
|||||||
|e| iso.edge(e),
|
|e| iso.edge(e),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn convert_vertex_map<G: GraphTopologyConversion, H: MakeTestGraph>()
|
||||||
|
where
|
||||||
|
H::Vertex: Debug,
|
||||||
|
{
|
||||||
|
let (source, vertices, _, _) = H::standard();
|
||||||
|
let (_, iso) = G::convert(&source);
|
||||||
|
let mut source_map = source.vertex_map(None);
|
||||||
|
for (i, &v) in vertices.iter().enumerate() {
|
||||||
|
source_map[v] = Some(i);
|
||||||
|
}
|
||||||
|
let map = iso.convert_vertex_map(&source_map);
|
||||||
|
for (i, &v) in vertices.iter().enumerate() {
|
||||||
|
assert_eq!(
|
||||||
|
map[iso.vertex(v)],
|
||||||
|
Some(i),
|
||||||
|
"unexpected converted value for vertex {v:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_edge_map<G: GraphTopologyConversion, H: MakeTestGraph>()
|
||||||
|
where
|
||||||
|
H::Edge: Debug,
|
||||||
|
{
|
||||||
|
let (source, _, edges, _) = H::standard();
|
||||||
|
let (_, iso) = G::convert(&source);
|
||||||
|
let mut source_map = source.edge_map(None);
|
||||||
|
for (i, &(e, _, _)) in edges.iter().enumerate() {
|
||||||
|
source_map[e] = Some(i);
|
||||||
|
}
|
||||||
|
let map = iso.convert_edge_map(&source_map);
|
||||||
|
for (i, &(e, _, _)) in edges.iter().enumerate() {
|
||||||
|
assert_eq!(
|
||||||
|
map[iso.edge(e)],
|
||||||
|
Some(i),
|
||||||
|
"unexpected converted value for edge {e:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_vertex_map_defaults<G: GraphTopologyConversion, H: MakeTestGraph>()
|
||||||
|
where
|
||||||
|
G::Vertex: Debug,
|
||||||
|
{
|
||||||
|
let (source, vertices, _, _) = H::standard();
|
||||||
|
let (graph, iso) = G::convert(&source);
|
||||||
|
|
||||||
|
for &v in &vertices {
|
||||||
|
let mut source_map = source.vertex_map(8);
|
||||||
|
source_map[v] = 1;
|
||||||
|
let map = iso.convert_vertex_map(&source_map);
|
||||||
|
let mapped = iso.vertex(v);
|
||||||
|
assert_eq!(map[mapped], 1, "unexpected value for set vertex {mapped:?}");
|
||||||
|
for u in graph.vertices().filter(|&x| x != mapped) {
|
||||||
|
assert_eq!(map[u], 8, "unset vertex {u:?} should hold the default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_edge_map_defaults<G: GraphTopologyConversion, H: MakeTestGraph>()
|
||||||
|
where
|
||||||
|
G::Edge: Debug,
|
||||||
|
{
|
||||||
|
let (source, _, edges, _) = H::standard();
|
||||||
|
let (graph, iso) = G::convert(&source);
|
||||||
|
|
||||||
|
for &(e, _, _) in &edges {
|
||||||
|
let mut source_map = source.edge_map(8);
|
||||||
|
source_map[e] = 1;
|
||||||
|
let map = iso.convert_edge_map(&source_map);
|
||||||
|
let mapped = iso.edge(e);
|
||||||
|
assert_eq!(map[mapped], 1, "unexpected value for set edge {mapped:?}");
|
||||||
|
for f in graph.edges().filter(|&x| x != mapped) {
|
||||||
|
assert_eq!(map[f], 8, "unset edge {f:?} should hold the default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_map_empty<G: GraphTopologyConversion, H: MakeTestGraph>() {
|
||||||
|
// Checks that converting maps of a graph without vertices and edges does not panic.
|
||||||
|
let source = H::empty();
|
||||||
|
let (_, iso) = G::convert(&source);
|
||||||
|
iso.convert_vertex_map(&source.vertex_map(0));
|
||||||
|
iso.convert_edge_map(&source.edge_map(0));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user