Completed
Push — master ( 72947f...dc545e )
by Xianshun
01:51
created

BreadthFirstSearchUnitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_dfs() 0 9 4
1
import unittest
2
3
from pyalgs.algorithms.graphs.search import DepthFirstSearch, BreadthFirstSearch
4
from tests.algorithms.graphs.util import create_graph
5
6
7
class DepthFirstSearchUnitTest(unittest.TestCase):
8
    def test_dfs(self):
9
        g = create_graph()
10
        s = 0
11
        dfs = DepthFirstSearch(g, s)
12
13
        for v in range(1, g.vertex_count()):
14
            if dfs.hasPathTo(v):
15
                print(str(s) + ' is connected to ' + str(v))
16
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
17
18
19
class BreadthFirstSearchUnitTest(unittest.TestCase):
20
    def test_dfs(self):
21
        g = create_graph()
22
        s = 0
23
        dfs = BreadthFirstSearch(g, s)
24
25
        for v in range(1, g.vertex_count()):
26
            if dfs.hasPathTo(v):
27
                print(str(s) + ' is connected to ' + str(v))
28
                print('path is ' + ' => '.join([str(i) for i in dfs.pathTo(v)]))
29
30
31
if __name__ == '__main__':
32
    unittest.main()
33