Skip to content

Commit 698e6c6

Browse files
committed
tests
1 parent 3f8dc5f commit 698e6c6

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

src/compas/datastructures/halfedge/halfedge.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,50 +260,50 @@ def get_any_face_vertex(self, fkey):
260260
"""
261261
return self.face_vertices(fkey)[0]
262262

263-
def vertex_sample(self, n=1):
263+
def vertex_sample(self, size=1):
264264
"""A random sample of the vertices.
265265
266266
Parameters
267267
----------
268-
n : int, optional
268+
size : int, optional
269269
The number of vertices in the random sample.
270270
271271
Returns
272272
-------
273273
list
274274
The identifiers of the vertices.
275275
"""
276-
return sample(list(self.vertices()), n)
276+
return sample(list(self.vertices()), size)
277277

278-
def edge_sample(self, n=1):
278+
def edge_sample(self, size=1):
279279
"""A random sample of the edges.
280280
281281
Parameters
282282
----------
283-
n : int, optional
283+
size : int, optional
284284
The number of edges in the random sample.
285285
286286
Returns
287287
-------
288288
list
289289
The identifiers of the edges.
290290
"""
291-
return sample(list(self.edges()), n)
291+
return sample(list(self.edges()), size)
292292

293-
def face_sample(self, n=1):
293+
def face_sample(self, size=1):
294294
"""A random sample of the faces.
295295
296296
Parameters
297297
----------
298-
n : int, optional
298+
size : int, optional
299299
The number of faces in the random sample.
300300
301301
Returns
302302
-------
303303
list
304304
The identifiers of the faces.
305305
"""
306-
return sample(list(self.faces()), n)
306+
return sample(list(self.faces()), size)
307307

308308
def key_index(self):
309309
"""Returns a dictionary that maps vertex dictionary keys to the

tests/compas/datastructures/test_graph.py

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

5454

55+
# ==============================================================================
56+
# Tests - Samples
57+
# ==============================================================================
58+
59+
60+
def test_node_sample(graph):
61+
for node in graph.node_sample():
62+
assert graph.has_node(node)
63+
for node in graph.node_sample(size=graph.number_of_nodes()):
64+
assert graph.has_node(node)
65+
66+
67+
def test_edge_sample(graph):
68+
for edge in graph.edge_sample():
69+
assert graph.has_edge(*edge)
70+
for edge in graph.edge_sample(size=graph.number_of_edges()):
71+
assert graph.has_edge(*edge)
72+
73+
5574
# ==============================================================================
5675
# Tests - Attributes
5776
# ==============================================================================

tests/compas/datastructures/test_halfedge.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ def test_json_schema(mesh):
6565
mesh.validate_json()
6666

6767

68+
# ==============================================================================
69+
# Tests - Samples
70+
# ==============================================================================
71+
72+
73+
def test_vertex_sample(mesh):
74+
for vertex in mesh.vertex_sample():
75+
assert mesh.has_vertex(vertex)
76+
for vertex in mesh.vertex_sample(size=mesh.number_of_vertices()):
77+
assert mesh.has_vertex(vertex)
78+
79+
80+
def test_edge_sample(mesh):
81+
for edge in mesh.edge_sample():
82+
assert mesh.has_edge(edge)
83+
for edge in mesh.edge_sample(size=mesh.number_of_edges()):
84+
assert mesh.has_edge(edge)
85+
86+
87+
def test_face_sample(mesh):
88+
for face in mesh.face_sample():
89+
assert mesh.has_face(face)
90+
for face in mesh.face_sample(size=mesh.number_of_faces()):
91+
assert mesh.has_face(face)
92+
93+
6894
# ==============================================================================
6995
# Tests - Vertex Attributes
7096
# ==============================================================================

0 commit comments

Comments
 (0)