Change "neighbor" terminology to "adjacent vertex" throughout the code
This commit is contained in:
@@ -192,26 +192,26 @@ macro_rules! graph_topology_tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neighbors_empty() {
|
||||
fn adjacent_vertices_empty() {
|
||||
let mut graph = <$T>::new();
|
||||
let vertex = graph.add_vertex();
|
||||
assert_eq!(
|
||||
graph.neighbors(vertex).count(),
|
||||
graph.adjacent_vertices(vertex).count(),
|
||||
0,
|
||||
"neighbor iterator of vertex with degree 0 should have no elements"
|
||||
"adjacent vertex iterator of vertex with degree 0 should have no elements"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neighbors() {
|
||||
fn adjacent_vertices() {
|
||||
let (graph, vertices, _) = make_test_graph();
|
||||
// Checks neighbors of vertex 4.
|
||||
// Checks adjacency of vertex 4.
|
||||
assert_eq!(
|
||||
graph.neighbors(vertices[4]).count(),
|
||||
graph.adjacent_vertices(vertices[4]).count(),
|
||||
7,
|
||||
"unexpected neighbor count"
|
||||
"unexpected adjacency count"
|
||||
);
|
||||
let mut expected_neighbors = vec![
|
||||
let mut expected_adjacency = vec![
|
||||
vertices[1],
|
||||
vertices[2],
|
||||
vertices[2],
|
||||
@@ -220,21 +220,21 @@ macro_rules! graph_topology_tests {
|
||||
vertices[7],
|
||||
vertices[8],
|
||||
];
|
||||
for v in graph.neighbors(vertices[4]) {
|
||||
let i = expected_neighbors
|
||||
for v in graph.adjacent_vertices(vertices[4]) {
|
||||
let i = expected_adjacency
|
||||
.iter()
|
||||
.position(|w| *w == v)
|
||||
.expect(&format!(
|
||||
"unexpected neighbor {v:?} of {:?} from the iterator",
|
||||
"unexpected adjacent vertex {v:?} of {:?} from the iterator",
|
||||
vertices[4]
|
||||
));
|
||||
expected_neighbors.swap_remove(i);
|
||||
expected_adjacency.swap_remove(i);
|
||||
}
|
||||
assert_eq!(
|
||||
expected_neighbors.len(),
|
||||
expected_adjacency.len(),
|
||||
0,
|
||||
"expected neighbors {:?} of {:?} were not matched by the iterator",
|
||||
expected_neighbors,
|
||||
"expected adjacent vertices {:?} of {:?} were not matched by the iterator",
|
||||
expected_adjacency,
|
||||
vertices[4]
|
||||
);
|
||||
}
|
||||
@@ -276,18 +276,18 @@ macro_rules! graph_topology_tests {
|
||||
graph.are_adjacent(v, v),
|
||||
"vertex with loop edge should be adjacent to itself"
|
||||
);
|
||||
let mut neighbors = graph.neighbors(v);
|
||||
let mut iter = graph.adjacent_vertices(v);
|
||||
assert_eq!(iter.next(), Some(v), "vertex should be adjacent to itself");
|
||||
assert_eq!(
|
||||
neighbors.next(),
|
||||
iter.next(),
|
||||
Some(v),
|
||||
"vertex should be neighbor of itself"
|
||||
"vertex should be adjacent to itself twice"
|
||||
);
|
||||
assert_eq!(
|
||||
neighbors.next(),
|
||||
Some(v),
|
||||
"vertex should be neighbor of itself twice"
|
||||
iter.next(),
|
||||
None,
|
||||
"too many adjacent vertices from iterator"
|
||||
);
|
||||
assert_eq!(neighbors.next(), None, "too many neighbors from iterator");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -312,20 +312,20 @@ macro_rules! graph_topology_tests {
|
||||
"should be adjacent"
|
||||
);
|
||||
for i in 0..2 {
|
||||
let mut neighbors = graph.neighbors(vertices[i]);
|
||||
let mut iter = graph.adjacent_vertices(vertices[i]);
|
||||
for j in 0..k {
|
||||
assert_eq!(
|
||||
neighbors.next(),
|
||||
iter.next(),
|
||||
Some(vertices[1 - i]),
|
||||
"neighbor {j} of vertex {:?} should be {:?}",
|
||||
"adjacent vertex {j} of vertex {:?} should be {:?}",
|
||||
vertices[i],
|
||||
vertices[1 - i]
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
neighbors.next(),
|
||||
iter.next(),
|
||||
None,
|
||||
"too many neighbors of {:?} from iterator",
|
||||
"too many adjacent vertices of {:?} from iterator",
|
||||
vertices[i]
|
||||
);
|
||||
}
|
||||
@@ -439,7 +439,7 @@ macro_rules! graph_topology_deletion_tests {
|
||||
}
|
||||
for v in [vertices[1], vertices[4], vertices[5], vertices[6]] {
|
||||
assert!(
|
||||
!graph.neighbors(v).any(|u| u == vertices[2]),
|
||||
!graph.adjacent_vertices(v).any(|u| u == vertices[2]),
|
||||
"unexpected adjacency of {v:?} to deleted vertex {:?}",
|
||||
vertices[2]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user