Add FrozenGraph tests

This commit is contained in:
2026-09-03 19:49:45 +02:00
parent 73af8a16ca
commit c25a8a4fc1
5 changed files with 172 additions and 2 deletions
+87 -2
View File
@@ -1,7 +1,9 @@
use crate::maps::ElementMap;
use crate::traits::{GraphTopology, GraphTopologyAddition, Incidence};
use std::fmt::Debug;
use crate::maps::ElementMap;
use crate::models::{AppendGraph, FrozenGraph};
use crate::traits::{GraphTopology, GraphTopologyAddition, Incidence};
pub trait MakeTestGraph: GraphTopology + Sized {
fn standard() -> (
Self,
@@ -165,6 +167,89 @@ impl<G: GraphTopologyAddition> MakeTestGraph for G {
}
}
impl MakeTestGraph for FrozenGraph {
fn standard() -> (
Self,
[Self::Vertex; 10],
[(Self::Edge, Self::Vertex, Self::Vertex); 18],
[Vec<Incidence<Self::Vertex, Self::Edge>>; 10],
) {
let (build, vertices, edges, incidences) = AppendGraph::standard();
let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&build);
(
graph,
vertices.map(|v| vertex_map[v]),
edges.map(|(e, u, v)| (edge_map[e], vertex_map[u], vertex_map[v])),
incidences.map(|vec| {
vec.iter()
.map(|i| Incidence {
vertex: vertex_map[i.vertex],
edge: edge_map[i.edge],
})
.collect()
}),
)
}
fn empty() -> Self {
FrozenGraph::from(&AppendGraph::empty())
}
fn single_vertex() -> (Self, Self::Vertex) {
let (build, v) = AppendGraph::single_vertex();
let (graph, vertex_map, _) = FrozenGraph::from_graph(&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);
(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);
(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);
(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);
(
graph,
vertices.map(|v| vertex_map[v]),
edges.map(|e| edge_map[e]),
)
}
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);
(
graph,
vertices.map(|v| vertex_map[v]),
edges.map(|e| edge_map[e]),
)
}
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);
(
graph,
vertices.map(|v| vertex_map[v]),
edges.map(|e| edge_map[e]),
)
}
}
pub fn assert_standard_unweighted_distances_v0<V, F>(actual_for: F, vertices: &[V])
where
V: Debug + Copy,