@@ -32,37 +32,51 @@ def test_node_access():
32
32
graph.node_attrs[1].position
33
33
34
34
35
- def test_edge_access():
35
+ @pytest.mark.parametrize("directed", [True, False])
36
+ def test_edge_access(directed):
36
37
graph = sg.SpatialGraph(
37
38
ndims=3,
38
39
node_dtype="uint64",
39
40
node_attr_dtypes={"position": "double[3]"},
40
41
edge_attr_dtypes={"score": "double"},
41
42
position_attr="position",
43
+ directed=directed,
42
44
)
43
45
graph.add_node(1, position=np.array([1.0, 1.0, 1.0]))
44
46
graph.add_node(2, position=np.array([2.0, 2.0, 2.0]))
45
47
graph.add_node(3, position=np.array([3.0, 3.0, 3.0]))
46
48
graph.add_node(4, position=np.array([4.0, 4.0, 4.0]))
47
49
graph.add_edge([1, 2], score=0.5)
48
50
graph.add_edge([2, 3], score=0.4)
49
- graph.add_edge([2, 4 ], score=0.3)
50
- graph.add_edge([3, 4 ], score=0.2)
51
+ graph.add_edge([4, 2 ], score=0.3)
52
+ graph.add_edge([4, 3 ], score=0.2)
51
53
52
54
edges = np.array([[1, 2], [2, 3]], dtype=np.uint64)
53
55
54
56
# attribute of all edges
55
- graph.edge_attrs.score
57
+ np.testing.assert_equal(
58
+ np.sort(graph.edge_attrs.score), np.array([0.2, 0.3, 0.4, 0.5], dtype="double")
59
+ )
56
60
# attribute of edges as ndarray
57
- graph.edge_attrs[edges].score
61
+ np.testing.assert_equal(
62
+ graph.edge_attrs[edges].score, np.array([0.5, 0.4], dtype="double")
63
+ )
58
64
# attribute of edges as list
59
- graph.edge_attrs[[[1, 2], [2, 3]]].score
65
+ np.testing.assert_equal(
66
+ graph.edge_attrs[[[1, 2], [2, 3]]].score, np.array([0.5, 0.4], dtype="double")
67
+ )
60
68
# attribute of edges as tuple
61
- graph.edge_attrs[[(1, 2), (2, 3)]].score
69
+ np.testing.assert_equal(
70
+ graph.edge_attrs[[(1, 2), (2, 3)]].score, np.array([0.5, 0.4], dtype="double")
71
+ )
62
72
# attribute of single edge as numpy array
63
- graph.edge_attrs[edges[0]].score
73
+ np.testing.assert_equal(
74
+ graph.edge_attrs[edges[0]].score, np.array([0.5], dtype="double")
75
+ )
64
76
# attribute of single edge as python tuple
65
- graph.edge_attrs[(1, 2)].score
77
+ np.testing.assert_equal(
78
+ graph.edge_attrs[(1, 2)].score, np.array([0.5], dtype="double")
79
+ )
66
80
67
81
68
82
dtypes = ["float", "double", "int8", "uint8", "int16", "uint16"]
0 commit comments