Skip to content

Commit 6060e22

Browse files
committed
halfedge tests for default attributes
1 parent 1a720e6 commit 6060e22

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/compas/datastructures/test_graph.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_graph_json_schema(graph):
5252
graph.validate_json()
5353

5454

55+
# ==============================================================================
56+
# Tests - Attributes
57+
# ==============================================================================
58+
59+
5560
def test_default_node_attributes():
5661
graph = Graph(name='test', default_node_attributes={'a': 1, 'b': 2})
5762
for node in graph.nodes():
@@ -70,6 +75,11 @@ def test_default_edge_attributes():
7075
assert graph.edge_attribute(edge, name='a') == 3
7176

7277

78+
# ==============================================================================
79+
# Tests - Conversion
80+
# ==============================================================================
81+
82+
7383
def test_graph_networkx_conversion():
7484
if compas.IPY:
7585
return

tests/compas/datastructures/test_halfedge.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def test_json_schema(mesh):
7070
# ==============================================================================
7171

7272

73+
def test_default_vertex_attributes():
74+
he = HalfEdge(name='test', default_vertex_attributes={'a': 1, 'b': 2})
75+
for vertex in he.vertices():
76+
assert he.vertex_attribute(vertex, name='a') == 1
77+
assert he.vertex_attribute(vertex, name='b') == 2
78+
he.vertex_attribute(vertex, name='a', value=3)
79+
assert he.vertex_attribute(vertex, name='a') == 3
80+
81+
7382
def test_vertex_attributes_key_not_found(mesh):
7483
with pytest.raises(KeyError):
7584
mesh.vertex_attributes(mesh.number_of_vertices() + 1)
@@ -111,6 +120,16 @@ def test_del_vertex_attribute_in_view(mesh, vertex_key):
111120
# Tests - Face Attributes
112121
# ==============================================================================
113122

123+
124+
def test_default_face_attributes():
125+
he = HalfEdge(name='test', default_face_attributes={'a': 1, 'b': 2})
126+
for face in he.vertices():
127+
assert he.face_attribute(face, name='a') == 1
128+
assert he.face_attribute(face, name='b') == 2
129+
he.face_attribute(face, name='a', value=3)
130+
assert he.face_attribute(face, name='a') == 3
131+
132+
114133
def test_face_attributes_is_empty(mesh):
115134
assert mesh.face_attributes(mesh.get_any_face()) == {}
116135

@@ -151,6 +170,16 @@ def test_del_face_attribute_in_view(mesh, face_key):
151170
# Tests - Edge Attributes
152171
# ==============================================================================
153172

173+
174+
def test_default_edge_attributes():
175+
he = HalfEdge(name='test', default_edge_attributes={'a': 1, 'b': 2})
176+
for edge in he.vertices():
177+
assert he.edge_attribute(edge, name='a') == 1
178+
assert he.edge_attribute(edge, name='b') == 2
179+
he.edge_attribute(edge, name='a', value=3)
180+
assert he.edge_attribute(edge, name='a') == 3
181+
182+
154183
def test_edge_attributes_is_empty(mesh, edge_key):
155184
assert mesh.edge_attributes(edge_key) == {}
156185

0 commit comments

Comments
 (0)