Skip to content

Commit d02b691

Browse files
committed
Extend edge attribute test
1 parent a6d3fee commit d02b691

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

tests/test_attributes.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,51 @@ def test_node_access():
3232
graph.node_attrs[1].position
3333

3434

35-
def test_edge_access():
35+
@pytest.mark.parametrize("directed", [True, False])
36+
def test_edge_access(directed):
3637
graph = sg.SpatialGraph(
3738
ndims=3,
3839
node_dtype="uint64",
3940
node_attr_dtypes={"position": "double[3]"},
4041
edge_attr_dtypes={"score": "double"},
4142
position_attr="position",
43+
directed=directed,
4244
)
4345
graph.add_node(1, position=np.array([1.0, 1.0, 1.0]))
4446
graph.add_node(2, position=np.array([2.0, 2.0, 2.0]))
4547
graph.add_node(3, position=np.array([3.0, 3.0, 3.0]))
4648
graph.add_node(4, position=np.array([4.0, 4.0, 4.0]))
4749
graph.add_edge([1, 2], score=0.5)
4850
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)
5153

5254
edges = np.array([[1, 2], [2, 3]], dtype=np.uint64)
5355

5456
# 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+
)
5660
# 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+
)
5864
# 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+
)
6068
# 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+
)
6272
# 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+
)
6476
# 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+
)
6680

6781

6882
dtypes = ["float", "double", "int8", "uint8", "int16", "uint16"]

0 commit comments

Comments
 (0)