7
7
class TestCentrality :
8
8
feat = util .get_featurizer ()
9
9
# undirected graphs
10
- graph_types1 = ["Empty" , "Line" , "Ring" , "Hub_Spoke" , "Tree" ]
10
+ graph_types1 = [
11
+ "Empty" ,
12
+ "Line" ,
13
+ "Ring" ,
14
+ "Hub_Spoke" ,
15
+ "Tree" ,
16
+ ]
11
17
# directed graphs
12
18
graph_types2 = [
13
19
"Line_Directed" ,
@@ -21,16 +27,16 @@ class TestCentrality:
21
27
"Ring_Weighted" ,
22
28
"Hub_Spoke_Weighted" ,
23
29
"Tree_Weighted" ,
24
- "CompleteWeighted" ,
25
30
]
26
31
# weighted directed graphs
27
32
graph_types4 = [
28
33
"Line_Directed_Weighted" ,
29
34
"Ring_Directed_Weighted" ,
30
35
"Hub_Spoke_Directed_Weighted" ,
31
36
"Tree_Directed_Weighted" ,
32
- "CompleteUnweighted" ,
33
37
]
38
+ # Complete Graphs
39
+ graph_types5 = ["Complete" ]
34
40
35
41
@pytest .mark .parametrize ("test_name" , graph_types1 )
36
42
def test_degree_centrality1 (self , test_name ):
@@ -57,7 +63,7 @@ def test_degree_centrality1(self, test_name):
57
63
for b in baseline :
58
64
found = False
59
65
for r in result :
60
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
66
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
61
67
found = True
62
68
if not found :
63
69
pytest .fail ()
@@ -87,7 +93,7 @@ def test_degree_centrality2(self, test_name):
87
93
for b in baseline :
88
94
found = False
89
95
for r in result :
90
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
96
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
91
97
found = True
92
98
if not found :
93
99
pytest .fail ()
@@ -117,11 +123,35 @@ def test_degree_centrality3(self, test_name):
117
123
for b in baseline :
118
124
found = False
119
125
for r in result :
120
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
126
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
121
127
found = True
122
128
if not found :
123
129
pytest .fail ()
124
130
131
+ @pytest .mark .parametrize ("test_name" , graph_types5 )
132
+ def test_degree_centrality4 (self , test_name ):
133
+ params = {
134
+ "v_type_set" : ["V8" ],
135
+ "e_type_set" : [test_name ],
136
+ "reverse_e_type_set" : ["reverse_" + test_name ],
137
+ "in_degree" : False ,
138
+ "out_degree" : True ,
139
+ "print_results" : True ,
140
+ }
141
+ with open (
142
+ f"data/baseline/graph_algorithms_baselines/centrality/degree_centrality/{ test_name } .json"
143
+ ) as f :
144
+ baseline = json .load (f )
145
+
146
+ result = self .feat .runAlgorithm ("tg_degree_cent" , params = params )
147
+ result = sorted (result [0 ]["top_scores" ], key = lambda x : x ["Vertex_ID" ])
148
+ baseline = sorted (baseline [0 ]["top_scores" ], key = lambda x : x ["Vertex_ID" ])
149
+
150
+ for b in baseline :
151
+ for r in result :
152
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] != pytest .approx (b ["score" ]):
153
+ pytest .fail (f'{ r ["score" ]} != { b ["score" ]} ' )
154
+
125
155
@pytest .mark .parametrize ("test_name" , graph_types3 )
126
156
def test_weighted_degree_centrality1 (self , test_name ):
127
157
params = {
@@ -147,7 +177,7 @@ def test_weighted_degree_centrality1(self, test_name):
147
177
for b in baseline :
148
178
found = False
149
179
for r in result :
150
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
180
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
151
181
found = True
152
182
if not found :
153
183
pytest .fail ()
@@ -177,7 +207,7 @@ def test_weighted_degree_centrality2(self, test_name):
177
207
for b in baseline :
178
208
found = False
179
209
for r in result :
180
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
210
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
181
211
found = True
182
212
if not found :
183
213
pytest .fail ()
@@ -207,7 +237,7 @@ def test_weighted_degree_centrality3(self, test_name):
207
237
for b in baseline :
208
238
found = False
209
239
for r in result :
210
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
240
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
211
241
found = True
212
242
if not found :
213
243
pytest .fail ()
@@ -237,7 +267,7 @@ def test_closeness_centrality(self, test_name):
237
267
for b in baseline :
238
268
found = False
239
269
for r in result :
240
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
270
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
241
271
found = True
242
272
if not found :
243
273
pytest .fail ()
@@ -267,7 +297,7 @@ def test_closeness_centrality2(self, test_name):
267
297
for b in baseline :
268
298
found = False
269
299
for r in result :
270
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
300
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
271
301
found = True
272
302
if not found :
273
303
pytest .fail ()
@@ -297,7 +327,7 @@ def test_harmonic_centrality(self, test_name):
297
327
for b in baseline :
298
328
found = False
299
329
for r in result :
300
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
330
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
301
331
found = True
302
332
if not found :
303
333
pytest .fail ()
@@ -327,7 +357,7 @@ def test_harmonic_centrality2(self, test_name):
327
357
for b in baseline :
328
358
found = False
329
359
for r in result :
330
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
360
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
331
361
found = True
332
362
if not found :
333
363
pytest .fail ()
@@ -358,7 +388,7 @@ def test_article_rank(self, test_name):
358
388
for b in baseline :
359
389
found = False
360
390
for r in result :
361
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
391
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
362
392
found = True
363
393
if not found :
364
394
pytest .fail ()
@@ -390,7 +420,7 @@ def test_pagerank(self, test_name):
390
420
for b in baseline :
391
421
found = False
392
422
for r in result :
393
- if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == r ["score" ]:
423
+ if r ["Vertex_ID" ] == b ["Vertex_ID" ] and r ["score" ] == b ["score" ]:
394
424
found = True
395
425
if not found :
396
426
pytest .fail ()
0 commit comments