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
+67
View File
@@ -248,3 +248,70 @@ impl GraphTopology for FrozenGraph {
}
}
}
#[cfg(test)]
mod trait_tests {
use super::FrozenGraph;
crate::graph_topology_tests!(FrozenGraph);
}
#[cfg(test)]
mod tests {
use super::*;
use crate::testing::fixtures::MakeTestGraph;
use crate::traits::GraphTopology;
#[test]
fn incident_vertices_opposite_handle() {
let (graph, [v0, v1], e) = FrozenGraph::single_edge();
let f = Edge(graph.incidences[e.0].opposite);
let (u0, u1) = graph.incident_vertices(f);
assert!(
(u0 == v0 && u1 == v1) || (u0 == v1 && u1 == v0),
"unexpected incident vertices {u0:?} and {u1:?} for edge {f:?}"
);
}
#[test]
fn csr_sentinel_and_offsets_standard() {
let (graph, ..) = FrozenGraph::standard();
assert_eq!(
*graph.vertices.last().unwrap(),
graph.incidences.len(),
"sentinel should equal total number of incidences"
);
assert!(
graph.vertices.windows(2).all(|w| w[0] <= w[1]),
"incidence offsets of vertices should be monotonically non-decreasing"
);
}
#[test]
fn csr_sentinel_and_offsets_empty() {
let graph = FrozenGraph::empty();
assert_eq!(
graph.vertices,
vec![0],
"empty graph should have a single sentinel entry of 0"
);
assert!(
graph.incidences.is_empty(),
"empty graph should have no incidences"
);
}
#[test]
fn opposite_symmetry() {
let (graph, ..) = FrozenGraph::standard();
for i in 0..graph.incidences.len() {
let opp = graph.incidences[i].opposite;
assert_ne!(opp, i, "incidence should not equal its own opposite");
assert_eq!(
graph.incidences[opp].opposite, i,
"opposite of opposite of incidence should equal the incidence"
);
}
}
}