Reformat code with rustfmt

This commit is contained in:
2025-10-06 10:59:49 +02:00
parent e518d72a9e
commit 04c9150172
+45 -14
View File
@@ -66,9 +66,11 @@ impl Graph {
fn add_incidence(&mut self, v1: Vertex, v2: Vertex) { fn add_incidence(&mut self, v1: Vertex, v2: Vertex) {
self.incidence_vertices.push(v2); self.incidence_vertices.push(v2);
self.next_incidences.push(self.incidence_headers[v1.0].first_incidence.take()); self.next_incidences
.push(self.incidence_headers[v1.0].first_incidence.take());
self.incidence_headers[v1.0].incidence_count += 1; self.incidence_headers[v1.0].incidence_count += 1;
self.incidence_headers[v1.0].first_incidence = Some(Incidence(self.incidence_vertices.len() - 1)); self.incidence_headers[v1.0].first_incidence =
Some(Incidence(self.incidence_vertices.len() - 1));
} }
} }
@@ -100,16 +102,35 @@ fn main() {
assert_eq!(graph.edge_count(), 14, "edge count"); assert_eq!(graph.edge_count(), 14, "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!(graph.degree(vertices[i]), expected_degrees[i], assert_eq!(
"degree of {:?}", vertices[i]); graph.degree(vertices[i]),
expected_degrees[i],
"degree of {:?}",
vertices[i]
);
} }
assert_eq!(graph.are_adjacent(vertices[0], vertices[1]), true, assert_eq!(
"adjacency of {:?} and {:?}", vertices[0], vertices[1]); graph.are_adjacent(vertices[0], vertices[1]),
assert_eq!(graph.are_adjacent(vertices[9], vertices[5]), true, true,
"adjacency of {:?} and {:?}", vertices[0], vertices[5]); "adjacency of {:?} and {:?}",
assert_eq!(graph.are_adjacent(vertices[9], vertices[3]), false, vertices[0],
"adjacency of {:?} and {:?}", vertices[9], vertices[3]); vertices[1]
);
assert_eq!(
graph.are_adjacent(vertices[9], vertices[5]),
true,
"adjacency of {:?} and {:?}",
vertices[0],
vertices[5]
);
assert_eq!(
graph.are_adjacent(vertices[9], vertices[3]),
false,
"adjacency of {:?} and {:?}",
vertices[9],
vertices[3]
);
for i in 0..vertices.len() { for i in 0..vertices.len() {
let exp = match i { let exp = match i {
@@ -117,10 +138,20 @@ fn main() {
1 | 4 | 5 | 6 => true, 1 | 4 | 5 | 6 => true,
_ => false, _ => false,
}; };
assert_eq!(graph.are_adjacent(vertices[2], vertices[i]), exp, assert_eq!(
"adjacency of {:?} and {:?}", vertices[2], vertices[i]); graph.are_adjacent(vertices[2], vertices[i]),
assert_eq!(graph.are_adjacent(vertices[i], vertices[2]), exp, exp,
"adjacency of {:?} and {:?}", vertices[i], vertices[2]); "adjacency of {:?} and {:?}",
vertices[2],
vertices[i]
);
assert_eq!(
graph.are_adjacent(vertices[i], vertices[2]),
exp,
"adjacency of {:?} and {:?}",
vertices[i],
vertices[2]
);
} }
// TODO: test Dijkstra's algorithm starting at 0 and at another vertex. // TODO: test Dijkstra's algorithm starting at 0 and at another vertex.