Skip to content

Commit

Permalink
Added dijkstra test and missing link from documentation (keon#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaos Karampinas authored and keon committed Oct 17, 2019
1 parent b6dbcfb commit 0e427dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ If you want to uninstall algorithms, it is as simple as:
- [find_all_cliques](algorithms/graph/find_all_cliques.py)
- [find_path](algorithms/graph/find_path.py)
- [graph](algorithms/graph/graph.py)
- [dijkstra](algorithms/graph/dijkstra.py)
- [markov_chain](algorithms/graph/markov_chain.py)
- [minimum_spanning_tree](algorithms/graph/minimum_spanning_tree.py)
- [satisfiability](algorithms/graph/satisfiability.py)
Expand Down
2 changes: 1 addition & 1 deletion algorithms/graph/dijkstra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Dijkstra's single source shortest path algorithm

class Graph():
class Dijkstra():

def __init__(self, vertices):
self.vertices = vertices
Expand Down
18 changes: 18 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from algorithms.graph import Tarjan
from algorithms.graph import check_bipartite
from algorithms.graph.dijkstra import Dijkstra

import unittest

Expand Down Expand Up @@ -57,3 +58,20 @@ def test_check_bipartite(self):

adj_list_3 = [[0, 1, 0, 0], [1, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0]]
self.assertEqual(False, check_bipartite(adj_list_3))

class TestDijkstra(unittest.TestCase):

def test_dijkstra(self):
g = Dijkstra(9)
g.graph = [[0, 4, 0, 0, 0, 0, 0, 8, 0],
[4, 0, 8, 0, 0, 0, 0, 11, 0],
[0, 8, 0, 7, 0, 4, 0, 0, 2],
[0, 0, 7, 0, 9, 14, 0, 0, 0],
[0, 0, 0, 9, 0, 10, 0, 0, 0],
[0, 0, 4, 14, 10, 0, 2, 0, 0],
[0, 0, 0, 0, 0, 2, 0, 1, 6],
[8, 11, 0, 0, 0, 0, 1, 0, 7],
[0, 0, 2, 0, 0, 0, 6, 7, 0]
];

self.assertEqual(g.dijkstra(0), [0, 4, 12, 19, 21, 11, 9, 8, 14]);

0 comments on commit 0e427dd

Please sign in to comment.