Update test assertions in main()

This commit is contained in:
2025-10-06 18:43:37 +02:00
parent 2a35c47ad4
commit 5bf723928b
+13 -16
View File
@@ -165,41 +165,38 @@ fn main() {
graph.add_edge(vertices[7], vertices[8]); graph.add_edge(vertices[7], vertices[8]);
graph.add_edge(vertices[7], vertices[9]); graph.add_edge(vertices[7], vertices[9]);
assert_eq!(graph.vertex_count(), 10, "vertex count"); assert_eq!(graph.vertex_count(), 10, "unexpected vertex count");
assert_eq!(graph.edge_count(), 14, "edge count"); assert_eq!(graph.edge_count(), 14, "unexpected edge count");
let expected_degrees = [1, 4, 4, 2, 4, 2, 3, 3, 2, 3]; let expected_degrees = [1, 4, 4, 2, 4, 2, 3, 3, 2, 3];
for i in 0..graph.vertex_count() { for i in 0..graph.vertex_count() {
assert_eq!( assert_eq!(
graph.degree(vertices[i]), graph.degree(vertices[i]),
expected_degrees[i], expected_degrees[i],
"degree of {:?}", "unexpected degree of {:?}",
vertices[i] vertices[i]
); );
} }
assert_eq!( assert!(
graph.are_adjacent(vertices[0], vertices[1]), graph.are_adjacent(vertices[0], vertices[1]),
true, "expected {:?} and {:?} to be adjacent",
"adjacency of {:?} and {:?}",
vertices[0], vertices[0],
vertices[1] vertices[1]
); );
assert_eq!( assert!(
graph.are_adjacent(vertices[9], vertices[5]), graph.are_adjacent(vertices[9], vertices[5]),
true, "expected {:?} and {:?} to be adjacent",
"adjacency of {:?} and {:?}",
vertices[0], vertices[0],
vertices[5] vertices[5]
); );
assert_eq!( assert!(
graph.are_adjacent(vertices[9], vertices[3]), !graph.are_adjacent(vertices[9], vertices[3]),
false, "unexpected adjacency of {:?} and {:?}",
"adjacency of {:?} and {:?}",
vertices[9], vertices[9],
vertices[3] vertices[3]
); );
for i in 0..vertices.len() { for i in 0..graph.vertex_count() {
let exp = match i { let exp = match i {
2 => continue, 2 => continue,
1 | 4 | 5 | 6 => true, 1 | 4 | 5 | 6 => true,
@@ -208,14 +205,14 @@ fn main() {
assert_eq!( assert_eq!(
graph.are_adjacent(vertices[2], vertices[i]), graph.are_adjacent(vertices[2], vertices[i]),
exp, exp,
"adjacency of {:?} and {:?}", "unexpected adjacency of {:?} and {:?}",
vertices[2], vertices[2],
vertices[i] vertices[i]
); );
assert_eq!( assert_eq!(
graph.are_adjacent(vertices[i], vertices[2]), graph.are_adjacent(vertices[i], vertices[2]),
exp, exp,
"adjacency of {:?} and {:?}", "unexpected adjacency of {:?} and {:?}",
vertices[i], vertices[i],
vertices[2] vertices[2]
); );