@@ -12,28 +12,33 @@ def test_load_graph(g: DiGraph):
12
12
13
13
14
14
def test_to_undirected (g : DiGraph , ug : Graph ):
15
- g = g .to_undirected ()
15
+ undirected = g .to_undirected ()
16
16
17
- for n in range (g .node_count ()):
18
- assert set (g .copy_neighbors (n )) == set (ug .copy_neighbors (n ))
17
+ for n in range (undirected .node_count ()):
18
+ assert set (undirected .copy_neighbors (n )) == set (ug .copy_neighbors (n ))
19
19
20
20
21
21
def test_to_undirected_with_layout ():
22
22
g = DiGraph .from_numpy (
23
23
np .array ([[0 , 1 ], [0 , 1 ], [0 , 2 ], [1 , 2 ], [2 , 1 ], [0 , 3 ]], dtype = np .uint32 )
24
24
)
25
25
26
+ def compare_unsorted (expect , actual ):
27
+ sorted = expect .copy ()
28
+ sorted .sort ()
29
+ return np .array_equal (sorted , actual )
30
+
26
31
ug = g .to_undirected ()
27
- assert np . array_equal (ug .neighbors (0 ), [1 , 1 , 2 , 3 ])
28
- assert np . array_equal (ug .neighbors (1 ), [2 , 0 , 0 , 2 ])
29
- assert np . array_equal (ug .neighbors (2 ), [1 , 0 , 1 ])
30
- assert np . array_equal (ug .neighbors (3 ), [0 ])
32
+ assert compare_unsorted (ug .neighbors (0 ), [1 , 1 , 2 , 3 ])
33
+ assert compare_unsorted (ug .neighbors (1 ), [0 , 0 , 2 , 2 ])
34
+ assert compare_unsorted (ug .neighbors (2 ), [0 , 1 , 1 ])
35
+ assert compare_unsorted (ug .neighbors (3 ), [0 ])
31
36
32
37
ug = g .to_undirected (Layout .Unsorted )
33
- assert np . array_equal (ug .neighbors (0 ), [1 , 1 , 2 , 3 ])
34
- assert np . array_equal (ug .neighbors (1 ), [2 , 0 , 0 , 2 ])
35
- assert np . array_equal (ug .neighbors (2 ), [1 , 0 , 1 ])
36
- assert np . array_equal (ug .neighbors (3 ), [0 ])
38
+ assert compare_unsorted (ug .neighbors (0 ), [1 , 1 , 2 , 3 ])
39
+ assert compare_unsorted (ug .neighbors (1 ), [0 , 0 , 2 , 2 ])
40
+ assert compare_unsorted (ug .neighbors (2 ), [0 , 1 , 1 ])
41
+ assert compare_unsorted (ug .neighbors (3 ), [0 ])
37
42
38
43
ug = g .to_undirected (Layout .Sorted )
39
44
assert np .array_equal (ug .neighbors (0 ), [1 , 1 , 2 , 3 ])
0 commit comments