Skip to content

Commit 0354f52

Browse files
committed
Add tests
1 parent 2cec911 commit 0354f52

File tree

5 files changed

+136
-9
lines changed

5 files changed

+136
-9
lines changed

src/classy_blocks/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from .base.transforms import Mirror, Rotation, Scaling, Translation
1+
from .base.transforms import Mirror, Rotation, Scaling, Shear, Translation
22
from .construct.assemblies.joints import LJoint, NJoint, TJoint
33
from .construct.curves.analytic import AnalyticCurve, CircleCurve, LineCurve
4+
from .construct.curves.curve import CurveBase
45
from .construct.curves.discrete import DiscreteCurve
56
from .construct.curves.interpolated import LinearInterpolatedCurve, SplineInterpolatedCurve
67
from .construct.edges import Angle, Arc, OnCurve, Origin, PolyLine, Project, Spline
@@ -41,7 +42,9 @@
4142
"Rotation",
4243
"Scaling",
4344
"Translation",
45+
"Shear",
4446
# curves
47+
"CurveBase",
4548
"DiscreteCurve",
4649
"LinearInterpolatedCurve",
4750
"SplineInterpolatedCurve",
@@ -56,6 +59,7 @@
5659
"PolyLine",
5760
"Project",
5861
"OnCurve",
62+
# Face
5963
"Face",
6064
# construct operations
6165
"Operation",
@@ -92,9 +96,10 @@
9296
"RevolvedStack",
9397
# The Mesh
9498
"Mesh",
95-
# Modification of assembled meshes
99+
# Modification
96100
"GeometricFinder",
97101
"RoundSolidFinder",
102+
"ViewpointReorienter",
98103
# Optimization: Clamps
99104
"ClampBase",
100105
"FreeClamp",
@@ -113,7 +118,6 @@
113118
"SketchOptimizer",
114119
"MeshSmoother",
115120
"SketchSmoother",
116-
"ViewpointReorienter",
117121
# Assemblies
118122
"NJoint",
119123
"TJoint",

src/classy_blocks/construct/assemblies/joints.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def __init__(self, start_point: PointType, center_point: PointType, radius_point
114114
def _get_angles(self, count: int) -> FloatListType:
115115
"""Returns angles at which CuspCylinders must be rotated"""
116116

117+
@property
118+
def center(self):
119+
# "center" is the start point
120+
return self.shapes[0].operations[0].top_face.points[0].position
121+
117122
def chop_axial(self, **kwargs):
118123
for asm in self.assemblies:
119124
asm.chop_axial(**kwargs)
@@ -139,10 +144,16 @@ def _get_angles(self, count):
139144

140145

141146
class TJoint(JointBase):
147+
def __init__(self, start_point: PointType, center_point: PointType, radius_point: PointType):
148+
super().__init__(start_point, center_point, radius_point)
149+
142150
def _get_angles(self, _):
143151
return [0, np.pi / 2, 3 * np.pi / 2]
144152

145153

146154
class LJoint(JointBase):
155+
def __init__(self, start_point: PointType, center_point: PointType, radius_point: PointType):
156+
super().__init__(start_point, center_point, radius_point)
157+
147158
def _get_angles(self, _):
148159
return [0, np.pi / 2]

tests/test_construct/test_assembly.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import unittest
2+
3+
import numpy as np
4+
from parameterized import parameterized
5+
6+
from classy_blocks.construct.assemblies.joints import JointBase, LJoint, NJoint, TJoint
7+
from classy_blocks.mesh import Mesh
8+
from classy_blocks.types import NPPointListType
9+
from classy_blocks.util import functions as f
10+
11+
12+
class AssemblyTests(unittest.TestCase):
13+
def setUp(self):
14+
self.center_point = [0, 0, 0]
15+
self.start_point = [0, -1, 0]
16+
self.radius_point = [0, -1, 0.3]
17+
18+
def fanout(self, count: int) -> NPPointListType:
19+
angles = np.linspace(0, 2 * np.pi, num=count, endpoint=False)
20+
21+
return np.array([f.rotate(self.start_point, angle, [0, 0, 1], self.center_point) for angle in angles])
22+
23+
def get_joint_points(self, joint: JointBase) -> NPPointListType:
24+
points = []
25+
26+
for i, shape in enumerate(joint.shapes):
27+
if i % 2 == 0:
28+
points.append(shape.operations[0].bottom_face.points[0].position)
29+
30+
return np.array(points)
31+
32+
def test_t_joint(self):
33+
joint = TJoint(self.start_point, self.center_point, self.radius_point)
34+
35+
joint_points = self.get_joint_points(joint)
36+
expected_points = np.take(self.fanout(4), (0, 1, 3), axis=0)
37+
38+
np.testing.assert_almost_equal(joint_points, expected_points)
39+
40+
def test_l_joint(self):
41+
joint = LJoint(self.start_point, self.center_point, self.radius_point)
42+
43+
joint_points = self.get_joint_points(joint)
44+
expected_points = np.take(self.fanout(4), (0, 1), axis=0)
45+
46+
np.testing.assert_almost_equal(joint_points, expected_points)
47+
48+
@parameterized.expand(((3,), (4,), (5,), (6,)))
49+
def test_n_joint(self, branches):
50+
joint = NJoint(self.start_point, self.center_point, self.radius_point, branches=branches)
51+
52+
joint_points = self.get_joint_points(joint)
53+
expected_points = self.fanout(branches)
54+
55+
np.testing.assert_almost_equal(joint_points, expected_points)
56+
57+
def test_operations(self):
58+
joint = NJoint(self.start_point, self.center_point, self.radius_point, branches=3)
59+
60+
self.assertEqual(len(joint.operations), 3 * 2 * 6)
61+
62+
def test_center(self):
63+
joint = NJoint(self.start_point, self.center_point, self.radius_point, branches=3)
64+
65+
np.testing.assert_equal(joint.center, self.center_point)
66+
67+
def test_chop(self):
68+
mesh = Mesh()
69+
joint = TJoint(self.start_point, self.center_point, self.radius_point)
70+
71+
cell_size = 0.1
72+
joint.chop_axial(start_size=cell_size)
73+
joint.chop_radial(start_size=cell_size)
74+
joint.chop_tangential(start_size=cell_size)
75+
76+
mesh.add(joint)
77+
mesh.assemble()
78+
mesh.block_list.propagate_gradings()
79+
80+
def test_set_patches(self):
81+
branches = 5
82+
83+
joint = NJoint(self.start_point, self.center_point, self.radius_point, branches)
84+
85+
joint.set_outer_patch("walls")
86+
87+
for i in range(branches):
88+
joint.set_hole_patch(i, f"outlet_{i}")

tests/test_construct/test_shape.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from classy_blocks.base.exceptions import CylinderCreationError, FrustumCreationError
6+
from classy_blocks.construct.edges import Line
67
from classy_blocks.construct.flat.face import Face
78
from classy_blocks.construct.flat.sketches.disk import Disk, OneCoreDisk
89
from classy_blocks.construct.shape import ExtrudedShape, LoftedShape, RevolvedShape, ShapeCreationError
@@ -290,6 +291,16 @@ def test_mirror(self):
290291
cyl_2.sketch_2.center - cyl_2.sketch_1.center, cyl_1.sketch_1.center - cyl_1.sketch_2.center
291292
)
292293

294+
def test_remove_inner_edges(self):
295+
cylinder = self.cylinder
296+
cylinder.remove_inner_edges()
297+
298+
for operation in cylinder.core:
299+
for edge in operation.bottom_face.edges:
300+
self.assertIsInstance(edge, Line)
301+
for edge in operation.top_face.edges:
302+
self.assertIsInstance(edge, Line)
303+
293304

294305
class LoftedShapeTests(unittest.TestCase):
295306
@property

tests/test_util/test_imports.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ def test_import_transforms(self):
1111
_ = cb.Rotation
1212
_ = cb.Scaling
1313
_ = cb.Mirror
14+
_ = cb.Shear
1415

1516
def test_import_curves(self):
17+
_ = cb.CurveBase
1618
_ = cb.DiscreteCurve
1719
_ = cb.LinearInterpolatedCurve
1820
_ = cb.SplineInterpolatedCurve
1921
_ = cb.AnalyticCurve
2022
_ = cb.LineCurve
2123
_ = cb.CircleCurve
2224

23-
def test_import_flat(self):
24-
_ = cb.Face
25-
2625
def test_import_edges(self):
2726
_ = cb.Arc
2827
_ = cb.Angle
@@ -32,6 +31,9 @@ def test_import_edges(self):
3231
_ = cb.Project
3332
_ = cb.OnCurve
3433

34+
def test_import_flat(self):
35+
_ = cb.Face
36+
3537
def test_import_operations(self):
3638
_ = cb.Loft
3739
_ = cb.Box
@@ -43,8 +45,6 @@ def test_import_operations(self):
4345
def test_import_sketches(self):
4446
_ = cb.MappedSketch
4547
_ = cb.Grid
46-
_ = cb.Oval
47-
_ = cb.Grid
4848
_ = cb.OneCoreDisk
4949
_ = cb.FourCoreDisk
5050
_ = cb.HalfDisk
@@ -57,10 +57,14 @@ def test_import_stacks(self):
5757
_ = cb.RevolvedStack
5858

5959
def test_import_shapes(self):
60+
_ = cb.Shape
61+
_ = cb.ExtrudedShape
62+
_ = cb.LoftedShape
63+
_ = cb.RevolvedShape
6064
_ = cb.Elbow
6165
_ = cb.Frustum
62-
_ = cb.SemiCylinder
6366
_ = cb.Cylinder
67+
_ = cb.SemiCylinder
6468
_ = cb.ExtrudedRing
6569
_ = cb.RevolvedRing
6670
_ = cb.Hemisphere
@@ -84,6 +88,15 @@ def test_import_links(self):
8488
_ = cb.LinkBase
8589
_ = cb.TranslationLink
8690
_ = cb.RotationLink
91+
_ = cb.SymmetryLink
8792

8893
def test_import_optimizer(self):
8994
_ = cb.MeshOptimizer
95+
_ = cb.SketchOptimizer
96+
_ = cb.MeshSmoother
97+
_ = cb.SketchSmoother
98+
99+
def test_import_assemblies(self):
100+
_ = cb.NJoint
101+
_ = cb.TJoint
102+
_ = cb.LJoint

0 commit comments

Comments
 (0)