Skip to content

Commit f2b9d8c

Browse files
committed
tests
1 parent 483c182 commit f2b9d8c

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/compas/datastructures/volmesh/core/halfface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def edge_attribute(self, edge, name, value=None):
900900
u, v = edge
901901
if u not in self._plane or v not in self._plane[u]:
902902
raise KeyError(edge)
903-
key = ",".join(map(str, sorted(edge)))
903+
key = str(tuple(sorted(edge)))
904904
if value is not None:
905905
if key not in self._edge_data:
906906
self._edge_data[key] = {}
@@ -934,7 +934,7 @@ def unset_edge_attribute(self, edge, name):
934934
u, v = edge
935935
if u not in self._plane or v not in self._plane[u]:
936936
raise KeyError(edge)
937-
key = ",".join(map(str, sorted(edge)))
937+
key = str(tuple(sorted(edge)))
938938
if key in self._edge_data and name in self._edge_data[key]:
939939
del self._edge_data[key][name]
940940

@@ -967,7 +967,7 @@ def edge_attributes(self, edge, names=None, values=None):
967967
u, v = edge
968968
if u not in self._plane or v not in self._plane[u]:
969969
raise KeyError(edge)
970-
key = ",".join(map(str, sorted(edge)))
970+
key = str(tuple(sorted(edge)))
971971
if values:
972972
for name, value in zip(names, values):
973973
if key not in self._edge_data:

tests/compas/datastructures/test_graph.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ def graph():
2323
# ==============================================================================
2424

2525

26+
# def test_edgedata_directionality(graph):
27+
# graph.update_default_edge_attributes({'index': 0})
28+
# for index, (u, v) in enumerate(graph.edges()):
29+
# graph.edge_attribute((u, v), 'index', index)
30+
# assert all(graph.edge_attribute((u, v), 'index') != graph.edge_attribute((v, u), 'index') for u, v in graph.edges())
31+
32+
33+
def test_edgedata_io(graph):
34+
graph.update_default_edge_attributes({'index': 0})
35+
for index, (u, v) in enumerate(graph.edges()):
36+
graph.edge_attribute((u, v), 'index', index)
37+
other = Graph.from_data(graph.data)
38+
assert all(other.edge_attribute(edge, 'index') == index for index, edge in enumerate(other.edges()))
39+
40+
2641
def test_data_schema(graph):
2742
if compas.IPY:
2843
return

tests/compas/datastructures/test_halfedge.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def edge_key():
4040
# ==============================================================================
4141

4242

43+
def test_edgedata_nondirectionality(mesh):
44+
mesh.update_default_edge_attributes({'index': 0})
45+
for index, (u, v) in enumerate(mesh.edges()):
46+
mesh.edge_attribute((u, v), 'index', index)
47+
assert all(mesh.edge_attribute((u, v), 'index') == mesh.edge_attribute((v, u), 'index') for u, v in mesh.edges())
48+
49+
50+
def test_edgedata_io(mesh):
51+
mesh.update_default_edge_attributes({'index': 0})
52+
for index, (u, v) in enumerate(mesh.edges()):
53+
mesh.edge_attribute((u, v), 'index', index)
54+
other = HalfEdge.from_data(mesh.data)
55+
assert all(other.edge_attribute(edge, 'index') == index for index, edge in enumerate(other.edges()))
56+
57+
4358
def test_data_schema(mesh):
4459
if not compas.IPY:
4560
mesh.validate_data()

0 commit comments

Comments
 (0)