Skip to content

Commit cefceb3

Browse files
committed
Renamed AlgorithmError to RunAlgorithmError to be in line with Rust API Guidelines C-WORD-ORDER
1 parent c6d4335 commit cefceb3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/algorithms.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ use crate::{Graph, Node, ShortestPathTree};
6464
/// # Ok(())
6565
/// # }
6666
/// ```
67-
pub fn dijkstra<T: Display + Clone + Eq + Hash>(graph: &mut Graph<T>, source_node_id: &T) -> Result<ShortestPathTree<T>, AlgorithmError> {
67+
pub fn dijkstra<T: Display + Clone + Eq + Hash>(graph: &mut Graph<T>, source_node_id: &T) -> Result<ShortestPathTree<T>, RunAlgorithmError> {
6868
graph.reset_nodes();
6969
let source_node = match graph.nodes.get(source_node_id) {
7070
Some(node) => node,
71-
None => return Err(AlgorithmError::SourceNodeMissing),
71+
None => return Err(RunAlgorithmError::SourceNodeMissing),
7272
};
7373
source_node.borrow_mut().distance = 0;
7474
let mut open_nodes: BinaryHeap<Rc<RefCell<Node<T>>>> = BinaryHeap::new();
@@ -185,12 +185,12 @@ fn calc_min_distance<T: Display + Eq + Clone>(node: &Rc<RefCell<Node<T>>>, weigh
185185
/// # Ok(())
186186
/// # }
187187
/// ```
188-
pub fn bellman_ford<T: Display + Eq + Clone + Hash>(graph: &mut Graph<T>, source_node_id: &T) -> Result<ShortestPathTree<T>, AlgorithmError> {
188+
pub fn bellman_ford<T: Display + Eq + Clone + Hash>(graph: &mut Graph<T>, source_node_id: &T) -> Result<ShortestPathTree<T>, RunAlgorithmError> {
189189
graph.reset_nodes();
190190

191191
let source_node = match graph.nodes.get(source_node_id) {
192192
Some(node) => node,
193-
None => return Err(AlgorithmError::SourceNodeMissing),
193+
None => return Err(RunAlgorithmError::SourceNodeMissing),
194194
};
195195
source_node.borrow_mut().distance = 0;
196196

@@ -229,7 +229,7 @@ pub fn bellman_ford<T: Display + Eq + Clone + Hash>(graph: &mut Graph<T>, source
229229

230230
let new_distance = node_ref.distance + edge.weight;
231231
if new_distance < target_node_ref.distance {
232-
return Err(AlgorithmError::NegativeCircleDetected);
232+
return Err(RunAlgorithmError::NegativeCircleDetected);
233233
}
234234
}
235235
}
@@ -239,7 +239,7 @@ pub fn bellman_ford<T: Display + Eq + Clone + Hash>(graph: &mut Graph<T>, source
239239

240240
/// Errors that can occur when algorithms are run.
241241
#[derive(Debug, PartialEq)]
242-
pub enum AlgorithmError {
242+
pub enum RunAlgorithmError {
243243
/// Indicates that the source node is not contained within the graph.
244244
SourceNodeMissing,
245245
/// Indicates that the graph contains a negative circle, which causes the algorithm to not work properly.
@@ -248,7 +248,7 @@ pub enum AlgorithmError {
248248

249249
#[cfg(test)]
250250
mod tests {
251-
use crate::{Graph, algorithms::{dijkstra, bellman_ford, AlgorithmError}, graph_1, graph_2};
251+
use crate::{Graph, algorithms::{dijkstra, bellman_ford, RunAlgorithmError}, graph_1, graph_2};
252252

253253
#[test]
254254
fn dijkstra_test_1() {
@@ -326,7 +326,7 @@ mod tests {
326326
let mut graph = graph_with_negative_edges();
327327
graph.add_double_edge(-10, &'a', &'d');
328328
let spt = bellman_ford(&mut graph, &'a');
329-
assert_eq!(spt, Err(AlgorithmError::NegativeCircleDetected));
329+
assert_eq!(spt, Err(RunAlgorithmError::NegativeCircleDetected));
330330
}
331331

332332
#[test]
@@ -335,7 +335,7 @@ mod tests {
335335
graph.add_double_edge(-10, &"Oslo", &"London");
336336
graph.add_double_edge(-10, &"New York", &"London");
337337
let spt = bellman_ford(&mut graph, &"Berlin");
338-
assert_eq!(spt, Err(AlgorithmError::NegativeCircleDetected));
338+
assert_eq!(spt, Err(RunAlgorithmError::NegativeCircleDetected));
339339
}
340340

341341
}

0 commit comments

Comments
 (0)