|
@@ -0,0 +1,170 @@
|
|
1
|
+"""Tests decision"""
|
|
2
|
+import pytest
|
|
3
|
+import os
|
|
4
|
+import networkx as nx
|
|
5
|
+import statistics
|
|
6
|
+from .context import debruijn
|
|
7
|
+#from .context import debruijn_comp
|
|
8
|
+from debruijn import std
|
|
9
|
+from debruijn import path_average_weight
|
|
10
|
+from debruijn import remove_paths
|
|
11
|
+from debruijn import select_best_path
|
|
12
|
+from debruijn import solve_bubble
|
|
13
|
+from debruijn import simplify_bubbles
|
|
14
|
+from debruijn import solve_entry_tips
|
|
15
|
+from debruijn import solve_out_tips
|
|
16
|
+
|
|
17
|
+def test_std():
|
|
18
|
+ assert round(std([9, 5, 15, 20]), 1) == 6.6
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+def test_path_weight():
|
|
22
|
+ graph = nx.DiGraph()
|
|
23
|
+ graph.add_weighted_edges_from([(1, 2, 5), (3, 2, 10), (2, 4, 10), (4, 5, 3),
|
|
24
|
+ (5, 6, 10), (5, 7, 10)])
|
|
25
|
+ assert path_average_weight(graph, [1, 2, 4, 5] ) == 6.0
|
|
26
|
+
|
|
27
|
+def test_remove_paths():
|
|
28
|
+ graph_1 = nx.DiGraph()
|
|
29
|
+ graph_2 = nx.DiGraph()
|
|
30
|
+ graph_3 = nx.DiGraph()
|
|
31
|
+ graph_4 = nx.DiGraph()
|
|
32
|
+ graph_1.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
|
|
33
|
+ graph_2.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
|
|
34
|
+ graph_3.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
|
|
35
|
+ graph_4.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
|
|
36
|
+ graph_1 = remove_paths(graph_1, [(1,2)], True, False)
|
|
37
|
+ graph_2 = remove_paths(graph_2, [(5,7)], False, True)
|
|
38
|
+ graph_3 = remove_paths(graph_3, [(2,4,5)], False, False)
|
|
39
|
+ graph_4 = remove_paths(graph_4, [(2,4,5)], True, True)
|
|
40
|
+ assert (1,2) not in graph_1.edges()
|
|
41
|
+ assert (3,2) in graph_1.edges()
|
|
42
|
+ assert (5,7) not in graph_2.edges()
|
|
43
|
+ assert (5,6) in graph_2.edges()
|
|
44
|
+ assert 4 not in graph_3.nodes()
|
|
45
|
+ assert (2,4) not in graph_4.edges()
|
|
46
|
+ assert (4, 5) not in graph_4.edges()
|
|
47
|
+ assert 2 not in graph_4.nodes()
|
|
48
|
+ assert 4 not in graph_4.nodes()
|
|
49
|
+ assert 5 not in graph_4.nodes()
|
|
50
|
+
|
|
51
|
+def test_select_best_path():
|
|
52
|
+ graph_1 = nx.DiGraph()
|
|
53
|
+ graph_1.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
|
|
54
|
+ graph_1 = select_best_path(graph_1, [[1,2], [3,2]], [1, 1], [5, 10], delete_entry_node=True)
|
|
55
|
+ assert (1,2) not in graph_1.edges()
|
|
56
|
+ assert (3,2) in graph_1.edges()
|
|
57
|
+ assert 1 not in graph_1.nodes()
|
|
58
|
+ graph_2 = nx.DiGraph()
|
|
59
|
+ graph_2.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7) , (7, 8)])
|
|
60
|
+ graph_2 = select_best_path(graph_1, [[5, 6], [5, 7, 8]], [1, 2], [13, 10], delete_sink_node=True)
|
|
61
|
+ assert (5,7) not in graph_2.edges()
|
|
62
|
+ assert (7,8) not in graph_2.edges()
|
|
63
|
+ assert (5,6) in graph_2.edges()
|
|
64
|
+ assert 7 not in graph_2.nodes()
|
|
65
|
+ assert 8 not in graph_2.nodes()
|
|
66
|
+ #Select heavier
|
|
67
|
+ graph_3 = nx.DiGraph()
|
|
68
|
+ graph_3.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (2, 8), (8, 9),
|
|
69
|
+ (9, 5), (5, 6), (5, 7)])
|
|
70
|
+ graph_3 = select_best_path(graph_3, [[2, 4, 5], [2, 8, 9, 5]],
|
|
71
|
+ [1, 4], [13, 10])
|
|
72
|
+ assert (2,8) not in graph_3.edges()
|
|
73
|
+ assert (8,9) not in graph_3.edges()
|
|
74
|
+ assert (9,5) not in graph_3.edges()
|
|
75
|
+ assert (2,4) in graph_3.edges()
|
|
76
|
+ assert (4,5) in graph_3.edges()
|
|
77
|
+ assert 8 not in graph_3.nodes()
|
|
78
|
+ assert 9 not in graph_3.nodes()
|
|
79
|
+ assert 2 in graph_3.nodes()
|
|
80
|
+ assert 5 in graph_3.nodes()
|
|
81
|
+ # Select longest
|
|
82
|
+ graph_4 = nx.DiGraph()
|
|
83
|
+ graph_4.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (2, 8), (8, 9),
|
|
84
|
+ (9, 5), (5, 6), (5, 7)])
|
|
85
|
+ graph_4 = select_best_path(graph_4, [[2, 4, 5], [2, 8, 9, 5]],
|
|
86
|
+ [1, 4], [10, 10])
|
|
87
|
+ assert (2,4) not in graph_4.edges()
|
|
88
|
+ assert (4,5) not in graph_4.edges()
|
|
89
|
+ assert (2,8) in graph_4.edges()
|
|
90
|
+ assert (8,9) in graph_4.edges()
|
|
91
|
+ assert (9,5) in graph_4.edges()
|
|
92
|
+ # Select random
|
|
93
|
+ graph_5 = nx.DiGraph()
|
|
94
|
+ graph_5.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (2, 8), (8, 9),
|
|
95
|
+ (9, 5), (5, 6), (5, 7)])
|
|
96
|
+ graph_5 = select_best_path(graph_5, [[2, 4, 5], [2, 8, 9, 5]],
|
|
97
|
+ [1, 4], [10, 10])
|
|
98
|
+
|
|
99
|
+def test_solve_bubble():
|
|
100
|
+ graph_1 = nx.DiGraph()
|
|
101
|
+ graph_1.add_weighted_edges_from([(1, 2, 10), (3, 2, 10), (2, 4, 15),
|
|
102
|
+ (4, 5, 15), (2, 10,10), (10, 5,10),
|
|
103
|
+ (2, 8, 3), (8, 9, 3), (9, 5, 3),
|
|
104
|
+ (5, 6, 10), (5, 7, 10)])
|
|
105
|
+ graph_1 = solve_bubble(graph_1, 2, 5)
|
|
106
|
+ assert (2,8) not in graph_1.edges()
|
|
107
|
+ assert (8,9) not in graph_1.edges()
|
|
108
|
+ assert (9,5) not in graph_1.edges()
|
|
109
|
+ assert (2,10) not in graph_1.edges()
|
|
110
|
+ assert (10, 5) not in graph_1.edges()
|
|
111
|
+ assert (2,4) in graph_1.edges()
|
|
112
|
+ assert (4,5) in graph_1.edges()
|
|
113
|
+ assert 8 not in graph_1.nodes()
|
|
114
|
+ assert 9 not in graph_1.nodes()
|
|
115
|
+ assert 10 not in graph_1.nodes()
|
|
116
|
+ assert 2 in graph_1.nodes()
|
|
117
|
+ assert 5 in graph_1.nodes()
|
|
118
|
+ graph_2 = nx.DiGraph()
|
|
119
|
+ graph_2.add_weighted_edges_from([(1, 2, 10), (3, 2, 10), (2, 4, 10),
|
|
120
|
+ (4, 5, 10), (2, 10,10), (10, 5,10),
|
|
121
|
+ (2, 8, 10), (8, 9, 10), (9, 5, 10),
|
|
122
|
+ (5, 6, 10), (5, 7, 10)])
|
|
123
|
+ graph_2 = solve_bubble(graph_2, 2, 5)
|
|
124
|
+ assert (2,4) not in graph_2.edges()
|
|
125
|
+ assert (4,5) not in graph_2.edges()
|
|
126
|
+ assert (2,10) not in graph_1.edges()
|
|
127
|
+ assert (10, 5) not in graph_1.edges()
|
|
128
|
+ assert (2,8) in graph_2.edges()
|
|
129
|
+ assert (8,9) in graph_2.edges()
|
|
130
|
+ assert (9,5) in graph_2.edges()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+def test_simplify_bubbles():
|
|
134
|
+ graph_1 = nx.DiGraph()
|
|
135
|
+ graph_1.add_weighted_edges_from([(3, 2, 10), (2, 4, 15), (4, 5, 15),
|
|
136
|
+ (2, 10,10), (10, 5,10), (2, 8, 3),
|
|
137
|
+ (8, 9, 3), (9, 5, 3), (5, 6, 10),
|
|
138
|
+ (5, 7, 10)])
|
|
139
|
+ graph_1 = simplify_bubbles(graph_1)
|
|
140
|
+ assert (2,8) not in graph_1.edges()
|
|
141
|
+ assert (8,9) not in graph_1.edges()
|
|
142
|
+ assert (9,5) not in graph_1.edges()
|
|
143
|
+ assert (2,10) not in graph_1.edges()
|
|
144
|
+ assert (10, 5) not in graph_1.edges()
|
|
145
|
+
|
|
146
|
+def test_solve_entry_tips():
|
|
147
|
+ graph_1 = nx.DiGraph()
|
|
148
|
+ graph_1.add_weighted_edges_from([(1, 2, 10), (3, 2, 2), (2, 4, 15), (4, 5, 15)])
|
|
149
|
+ graph_1 = solve_entry_tips(graph_1, [1, 3])
|
|
150
|
+ assert (3, 2) not in graph_1.edges()
|
|
151
|
+ assert (1, 2) in graph_1.edges()
|
|
152
|
+ graph_2 = nx.DiGraph()
|
|
153
|
+ graph_2.add_weighted_edges_from([(1, 2, 2), (6, 3, 2), (3, 2, 2),
|
|
154
|
+ (2, 4, 15), (4, 5, 15)])
|
|
155
|
+ graph_2 = solve_entry_tips(graph_2, [1, 6])
|
|
156
|
+ assert (1, 2) not in graph_2.edges()
|
|
157
|
+ assert (6, 3) in graph_2.edges()
|
|
158
|
+ assert (3, 2) in graph_2.edges()
|
|
159
|
+
|
|
160
|
+def test_solve_out_tips():
|
|
161
|
+ graph_1 = nx.DiGraph()
|
|
162
|
+ graph_1.add_weighted_edges_from([(1, 2, 15), (2, 3, 15), (4, 5, 15), (4, 6, 2)])
|
|
163
|
+ graph_1 = solve_out_tips(graph_1, [5, 6])
|
|
164
|
+ assert (4, 6) not in graph_1.edges()
|
|
165
|
+ assert (4, 5) in graph_1.edges()
|
|
166
|
+ graph_2 = nx.DiGraph()
|
|
167
|
+ graph_2.add_weighted_edges_from([(1, 2, 15), (2, 3, 15), (4, 5, 2), (4, 6, 2) , (6, 7, 2)])
|
|
168
|
+ graph_2 = solve_out_tips(graph_2, [5, 7])
|
|
169
|
+ assert (4, 5) not in graph_2.edges()
|
|
170
|
+ assert (6, 7) in graph_2.edges()
|