Skip to content

Commit f9a4ae6

Browse files
committed
Add a few unit tests
1 parent cd7dbfc commit f9a4ae6

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

src/compas/datastructures/assembly/assembly.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,21 @@ def parts(self):
130130
for node in self.graph.nodes():
131131
yield self.graph.node_attribute(node, 'part')
132132

133-
def connections(self):
134-
"""The connections between the parts."""
135-
return self.graph.edges()
133+
def connections(self, data=False):
134+
"""Iterate over the connections between the parts.
135+
136+
Parameters
137+
----------
138+
data : bool, optional
139+
If ``True``, yield both the identifier and the attributes of each connection.
140+
141+
Yields
142+
------
143+
tuple
144+
The next connection identifier (u, v), if ``data`` is ``False``.
145+
Otherwise, the next connector identifier and its attributes as a ((u, v), attr) tuple.
146+
"""
147+
return self.graph.edges(data)
136148

137149
def find(self, guid):
138150
"""Find a part in the assembly by its GUID.

src/compas/datastructures/assembly/part.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def frame(self, frame):
134134

135135
@property
136136
def geometry(self):
137-
# this is a temp solution
137+
# TODO: this is a temp solution
138+
# TODO: add memoization or some other kind of caching
138139
A = Mesh.from_shape(self.shape)
139140
for shape, operation in self.features:
140141
A.quads_to_triangles()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from compas.datastructures import Assembly, assembly
2+
from compas.datastructures import Part
3+
4+
5+
def test_init():
6+
assembly = Assembly(name='abc')
7+
assert assembly.name == 'abc'
8+
9+
assembly = Assembly(attr1='value', attr2=3.14)
10+
assert assembly.attributes['attr1'] == 'value'
11+
assert assembly.attributes['attr2'] == 3.14
12+
13+
14+
def test_add_parts():
15+
assembly = Assembly()
16+
17+
for _ in range(3):
18+
assembly.add_part(Part())
19+
20+
assert len(list(assembly.parts())) == 3
21+
22+
23+
def test_add_connections():
24+
assembly = Assembly()
25+
parts = [Part() for i in range(3)]
26+
27+
for part in parts:
28+
assembly.add_part(part)
29+
30+
assembly.add_connection(parts[0], parts[1])
31+
assembly.add_connection(parts[1], parts[2])
32+
assembly.add_connection(parts[2], parts[0])
33+
34+
assert list(assembly.connections()) == [(0, 1), (1, 2), (2, 0)]
35+
36+
37+
def test_find():
38+
assembly = Assembly()
39+
part = Part()
40+
assert assembly.find(part.guid) is None
41+
42+
assembly.add_part(part)
43+
assert assembly.find(part.guid) == part

0 commit comments

Comments
 (0)