Cosplay/nhf/parts/test.py

107 lines
4.2 KiB
Python
Raw Normal View History

2024-07-04 00:42:14 -07:00
import unittest
import cadquery as Cq
from nhf.checks import binary_intersection, pairwise_intersection
2024-07-04 01:16:01 -07:00
from nhf.parts import joints, handle, metric_threads
2024-07-04 00:42:14 -07:00
class TestJoints(unittest.TestCase):
def test_joint_hirth(self):
j = joints.HirthJoint()
obj = j.generate()
self.assertIsInstance(
obj.val().solids(), Cq.Solid,
msg="Hirth joint must be in one piece")
def test_joints_hirth_assembly(self):
for n_tooth in [16, 20, 24]:
with self.subTest(n_tooth=n_tooth):
j = joints.HirthJoint()
assembly = j.assembly()
isect = binary_intersection(assembly)
self.assertLess(isect.Volume(), 1e-6,
"Hirth joint assembly must not have intersection")
2024-07-06 23:53:57 -07:00
def torsion_joint_case(self, joint: joints.TorsionJoint, slot: int):
2024-07-07 12:15:47 -07:00
assert 0 <= slot and slot < joint.rider_n_slots
assembly = joint.rider_track_assembly(slot)
bbox = assembly.toCompound().BoundingBox()
self.assertAlmostEqual(bbox.zlen, joint.total_height)
2024-07-07 09:44:54 -07:00
self.assertAlmostEqual(bbox.xlen, joint.radius * 2)
self.assertAlmostEqual(bbox.ylen, joint.radius * 2)
self.assertEqual(pairwise_intersection(assembly), [])
2024-07-06 23:53:57 -07:00
def test_torsion_joint(self):
j = joints.TorsionJoint()
for slot in range(j.rider_n_slots):
with self.subTest(slot=slot, right_handed=False):
2024-07-06 23:53:57 -07:00
self.torsion_joint_case(j, slot)
def test_torsion_joint_right_handed(self):
2024-07-06 23:50:10 -07:00
j = joints.TorsionJoint(right_handed=True)
for slot in range(j.rider_n_slots):
with self.subTest(slot=slot, right_handed=True):
self.torsion_joint_case(j, slot)
2024-07-06 23:53:57 -07:00
def test_torsion_joint_covered(self):
j = joints.TorsionJoint(
spring_hole_cover_track=True,
spring_hole_cover_rider=True,
)
self.torsion_joint_case(j, 1)
2024-07-07 12:15:47 -07:00
def test_torsion_joint_slot(self):
j = joints.TorsionJoint(
rider_slot_begin=90,
)
self.torsion_joint_case(j, 1)
2024-07-06 23:53:57 -07:00
2024-07-04 00:42:14 -07:00
class TestHandle(unittest.TestCase):
2024-07-09 22:09:16 -07:00
def test_threaded_collision(self):
h = handle.Handle(mount=handle.ThreadedMount())
2024-07-07 21:45:10 -07:00
assembly = h.connector_insertion_assembly()
self.assertEqual(pairwise_intersection(assembly), [])
2024-07-09 22:09:16 -07:00
def test_threaded_assembly(self):
h = handle.Handle(mount=handle.ThreadedMount())
2024-07-04 00:42:14 -07:00
assembly = h.connector_insertion_assembly()
bbox = assembly.toCompound().BoundingBox()
self.assertAlmostEqual(bbox.xlen, h.diam)
self.assertAlmostEqual(bbox.ylen, h.diam)
2024-07-09 22:09:16 -07:00
def test_threaded_one_sided_insertion(self):
h = handle.Handle(mount=handle.ThreadedMount())
2024-07-04 00:42:14 -07:00
assembly = h.connector_one_side_insertion_assembly()
bbox = assembly.toCompound().BoundingBox()
self.assertAlmostEqual(bbox.xlen, h.diam)
self.assertAlmostEqual(bbox.ylen, h.diam)
2024-07-07 21:45:10 -07:00
self.assertEqual(pairwise_intersection(assembly), [])
2024-07-09 22:09:16 -07:00
def test_bayonet_collision(self):
h = handle.Handle(mount=handle.BayonetMount())
assembly = h.connector_insertion_assembly()
self.assertEqual(pairwise_intersection(assembly), [])
def test_bayonet_assembly(self):
h = handle.Handle(mount=handle.BayonetMount())
assembly = h.connector_insertion_assembly()
bbox = assembly.toCompound().BoundingBox()
self.assertAlmostEqual(bbox.xlen, h.diam)
self.assertAlmostEqual(bbox.ylen, h.diam)
2024-07-04 00:42:14 -07:00
2024-07-09 22:09:16 -07:00
def test_bayonet_one_sided_insertion(self):
h = handle.Handle(mount=handle.BayonetMount())
assembly = h.connector_one_side_insertion_assembly()
bbox = assembly.toCompound().BoundingBox()
self.assertAlmostEqual(bbox.xlen, h.diam)
self.assertAlmostEqual(bbox.ylen, h.diam)
self.assertEqual(pairwise_intersection(assembly), [])
2024-07-04 00:42:14 -07:00
class TestMetricThreads(unittest.TestCase):
def test_major_radius(self):
major = 3.0
2024-07-06 23:53:57 -07:00
t = metric_threads.external_metric_thread(major, 0.5, 4.0, z_start=-0.85, top_lead_in=True)
2024-07-04 00:42:14 -07:00
bbox = t.val().BoundingBox()
self.assertAlmostEqual(bbox.xlen, major, places=3)
self.assertAlmostEqual(bbox.ylen, major, places=3)
if __name__ == '__main__':
unittest.main()