Renamed FromGraph to GraphTopologyConversion to align with existing traits and separate from From trait
This commit is contained in:
@@ -2,7 +2,7 @@ use std::fmt::Debug;
|
||||
|
||||
use crate::maps::ElementMap;
|
||||
use crate::models::{AppendGraph, FrozenGraph};
|
||||
use crate::traits::{FromGraph, GraphTopology, GraphTopologyAddition, Incidence};
|
||||
use crate::traits::{GraphTopology, GraphTopologyAddition, GraphTopologyConversion, Incidence};
|
||||
|
||||
pub trait MakeTestGraph: GraphTopology + Sized {
|
||||
fn standard() -> (
|
||||
@@ -175,7 +175,7 @@ impl MakeTestGraph for FrozenGraph {
|
||||
[Vec<Incidence<Self::Vertex, Self::Edge>>; 10],
|
||||
) {
|
||||
let (build, vertices, edges, incidences) = AppendGraph::standard();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(
|
||||
graph,
|
||||
vertices.map(|v| vertex_map[v]),
|
||||
@@ -197,31 +197,31 @@ impl MakeTestGraph for FrozenGraph {
|
||||
|
||||
fn single_vertex() -> (Self, Self::Vertex) {
|
||||
let (build, v) = AppendGraph::single_vertex();
|
||||
let (graph, vertex_map, _) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, _) = FrozenGraph::convert(&build);
|
||||
(graph, vertex_map[v])
|
||||
}
|
||||
|
||||
fn single_edge() -> (Self, [Self::Vertex; 2], Self::Edge) {
|
||||
let (build, vertices, e) = AppendGraph::single_edge();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(graph, vertices.map(|v| vertex_map[v]), edge_map[e])
|
||||
}
|
||||
|
||||
fn disconnected() -> (Self, [Self::Vertex; 3]) {
|
||||
let (build, vertices) = AppendGraph::disconnected();
|
||||
let (graph, vertex_map, _) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, _) = FrozenGraph::convert(&build);
|
||||
(graph, vertices.map(|v| vertex_map[v]))
|
||||
}
|
||||
|
||||
fn loop_edge() -> (Self, Self::Vertex, Self::Edge) {
|
||||
let (build, v, e) = AppendGraph::loop_edge();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(graph, vertex_map[v], edge_map[e])
|
||||
}
|
||||
|
||||
fn multiple_edges<const K: usize>() -> (Self, [Self::Vertex; 2], [Self::Edge; K]) {
|
||||
let (build, vertices, edges) = AppendGraph::multiple_edges();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(
|
||||
graph,
|
||||
vertices.map(|v| vertex_map[v]),
|
||||
@@ -231,7 +231,7 @@ impl MakeTestGraph for FrozenGraph {
|
||||
|
||||
fn two_edge_path() -> (Self, [Self::Vertex; 3], [Self::Edge; 2]) {
|
||||
let (build, vertices, edges) = AppendGraph::two_edge_path();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(
|
||||
graph,
|
||||
vertices.map(|v| vertex_map[v]),
|
||||
@@ -241,7 +241,7 @@ impl MakeTestGraph for FrozenGraph {
|
||||
|
||||
fn two_edge_path_with_loops() -> (Self, [Self::Vertex; 3], [Self::Edge; 4]) {
|
||||
let (build, vertices, edges) = AppendGraph::two_edge_path_with_loops();
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
|
||||
let (graph, vertex_map, edge_map) = FrozenGraph::convert(&build);
|
||||
(
|
||||
graph,
|
||||
vertices.map(|v| vertex_map[v]),
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::testing::fixtures;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
use crate::traits::{FromGraph, GraphTopology};
|
||||
use crate::traits::GraphTopology;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! graph_topology_from_graph_tests {
|
||||
macro_rules! from_tests {
|
||||
($T:ty, $U:ty) => {
|
||||
$crate::graph_topology_from_graph_tests!(@wrap $T, $U,
|
||||
$crate::from_tests!(@wrap $T, $U,
|
||||
from,
|
||||
from_graph,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -18,7 +14,7 @@ macro_rules! graph_topology_from_graph_tests {
|
||||
$(
|
||||
#[test]
|
||||
fn $name() {
|
||||
$crate::testing::graph_topology_from_graph_testing::$name::<$T, $U>();
|
||||
$crate::testing::from_testing::$name::<$T, $U>();
|
||||
}
|
||||
)*
|
||||
};
|
||||
@@ -40,22 +36,3 @@ where
|
||||
actual.sort();
|
||||
assert_eq!(actual, expected, "degree sequence should match");
|
||||
}
|
||||
|
||||
pub fn from_graph<G: FromGraph, H: MakeTestGraph>()
|
||||
where
|
||||
G::Vertex: Debug,
|
||||
G::Edge: Debug,
|
||||
H::Vertex: Debug,
|
||||
H::Edge: Debug,
|
||||
{
|
||||
let (source, vertices, edges, _) = H::standard();
|
||||
let (graph, vertex_map, edge_map) = G::from_graph(&source);
|
||||
fixtures::assert_isomorphic(
|
||||
&source,
|
||||
&graph,
|
||||
&vertices,
|
||||
|v| vertex_map[v],
|
||||
&edges,
|
||||
|e| edge_map[e],
|
||||
);
|
||||
}
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
use crate::testing::fixtures;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
use crate::traits::{FromGraph, GraphTopologyAddition};
|
||||
use crate::traits::{GraphTopologyAddition, GraphTopologyConversion};
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! graph_topology_addition_from_graph_tests {
|
||||
macro_rules! graph_topology_addition_conversion_tests {
|
||||
($T:ty, $U:ty) => {
|
||||
$crate::graph_topology_addition_from_graph_tests!(@wrap $T, $U,
|
||||
from_graph_mutation_independent,
|
||||
$crate::graph_topology_addition_conversion_tests!(@wrap $T, $U,
|
||||
convert_mutation_independent,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -15,18 +15,18 @@ macro_rules! graph_topology_addition_from_graph_tests {
|
||||
$(
|
||||
#[test]
|
||||
fn $name() {
|
||||
$crate::testing::graph_topology_addition_from_graph_testing::$name::<$T, $U>();
|
||||
$crate::testing::graph_topology_addition_conversion_testing::$name::<$T, $U>();
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
pub fn from_graph_mutation_independent<G, H>()
|
||||
pub fn convert_mutation_independent<G, H>()
|
||||
where
|
||||
G: FromGraph + GraphTopologyAddition,
|
||||
G: GraphTopologyConversion + GraphTopologyAddition,
|
||||
H: MakeTestGraph + GraphTopologyAddition,
|
||||
{
|
||||
let (mut source, vertices, _) = H::single_edge();
|
||||
let (mut graph, vertex_map, _) = G::from_graph(&source);
|
||||
let (mut graph, vertex_map, _) = G::convert(&source);
|
||||
fixtures::assert_mutation_independent(&mut source, &mut graph, &vertices, |v| vertex_map[v]);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::testing::fixtures;
|
||||
use crate::testing::fixtures::MakeTestGraph;
|
||||
use crate::traits::GraphTopologyConversion;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! graph_topology_conversion_tests {
|
||||
($T:ty, $U:ty) => {
|
||||
$crate::graph_topology_conversion_tests!(@wrap $T, $U,
|
||||
convert,
|
||||
);
|
||||
};
|
||||
|
||||
(@wrap $T:ty, $U:ty, $($name:ident),* $(,)?) => {
|
||||
$(
|
||||
#[test]
|
||||
fn $name() {
|
||||
$crate::testing::graph_topology_conversion_testing::$name::<$T, $U>();
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
pub fn convert<G: GraphTopologyConversion, H: MakeTestGraph>()
|
||||
where
|
||||
G::Vertex: Debug,
|
||||
G::Edge: Debug,
|
||||
H::Vertex: Debug,
|
||||
H::Edge: Debug,
|
||||
{
|
||||
let (source, vertices, edges, _) = H::standard();
|
||||
let (graph, vertex_map, edge_map) = G::convert(&source);
|
||||
fixtures::assert_isomorphic(
|
||||
&source,
|
||||
&graph,
|
||||
&vertices,
|
||||
|v| vertex_map[v],
|
||||
&edges,
|
||||
|e| edge_map[e],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user