-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(algorithm): implement bellman-ford
- Loading branch information
1 parent
91f14ad
commit 7c360fa
Showing
7 changed files
with
474 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use graph_algorithms::{BellmanFordAlgorithm, GraphAlgorithm}; | ||
|
||
pub fn run() -> Vec<i32> { | ||
let mut algorithm = BellmanFordAlgorithm::new(); | ||
algorithm.add_edge(0, vec![(1, 4), (2, 3)]); | ||
algorithm.add_edge(1, vec![(2, 1), (3, 2)]); | ||
algorithm.add_edge(2, vec![(3, 5)]); | ||
|
||
algorithm.run(0).unwrap_or_default() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_algorithm_run() { | ||
assert_eq!(run(), vec![0, 4, 3, 6]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
use graph_algorithms::{Dijkstra, GraphAlgorithm}; | ||
use graph_algorithms::{DijkstraAlgorithm, GraphAlgorithm}; | ||
|
||
pub fn run() -> Vec<usize> { | ||
let mut dijkstra = Dijkstra::new(); | ||
dijkstra.set_nodes(vec![ | ||
let mut algorithm = DijkstraAlgorithm::new(); | ||
algorithm.set_nodes(vec![ | ||
(0, vec![(1, 1), (2, 4)]), | ||
(1, vec![(2, 2)]), | ||
(2, vec![]), | ||
]); | ||
|
||
dijkstra.run(0) | ||
algorithm.run(0).unwrap_or_default() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_dijkstra() { | ||
fn test_algorithm_run() { | ||
assert_eq!(run(), vec![0, 1, 3]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.