-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_graph.py
More file actions
55 lines (38 loc) · 1.28 KB
/
test_graph.py
File metadata and controls
55 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import graph
from graph import GraphType
class UserType:
a = ''
def __init__(self, a):
self.a = a
graph_not_oriented = graph.Graph(GraphType.NOT_ORIENTED)
graph_oriented = graph.Graph(GraphType.ORIENTED)
test_data = ['a', 'b', 'c', 'd', 'e', 'g']
def test_add_vertexes():
for item in test_data:
graph_oriented.add_vertex(item)
graph_not_oriented.add_vertex(item)
def test_add_edges_oriented():
"""
a -> b -> c <-> e <- d
g
"""
graph_oriented.add_edge(('a', 'b'))
graph_oriented.add_edge(('b', 'c'))
graph_oriented.add_edge(('c', 'e'))
graph_oriented.add_edge(('d', 'e'))
def test_get_path_oriented():
assert graph_oriented.find_path('a', 'e') == ['a', 'b', 'c', 'e']
assert graph_oriented.find_path('a', 'd') == []
assert graph_oriented.find_path('d', 'e') == ['d', 'e']
def test_add_edges_not_oriented():
"""
a <-> b g
c <-> e <-> d
"""
graph_not_oriented.add_edge(('a', 'b'))
graph_not_oriented.add_edge(('c', 'e'))
graph_not_oriented.add_edge(('d', 'e'))
def test_get_path_not_oriented():
assert graph_not_oriented.find_path('a', 'g') == []
assert graph_not_oriented.find_path('c', 'd') == ['c', 'e', 'd']
assert graph_not_oriented.find_path('d', 'a') == []