Checked for invalid Wedge inputs Issue #225

This commit is contained in:
gumyr 2023-08-18 10:26:30 -04:00
parent 3ef52ee5ff
commit 4589786d3f
2 changed files with 20 additions and 0 deletions

View file

@ -551,6 +551,9 @@ class Wedge(BasePartObject):
context: BuildPart = BuildPart._get_context(self)
validate_inputs(context, self)
if any([value <= 0 for value in [xsize, ysize, zsize]]):
raise ValueError("xsize, ysize & zsize must all be greater than zero")
self.xsize = xsize
self.ysize = ysize
self.zsize = zsize

View file

@ -55,6 +55,7 @@ class TestAlign(unittest.TestCase):
class TestMakeBrakeFormed(unittest.TestCase):
def test_make_brake_formed(self):
# TODO: Fix so this test doesn't raise a DeprecationWarning from NumPy
with BuildPart() as bp:
with BuildLine() as bl:
Polyline((0, 0), (5, 6), (10, 1))
@ -498,5 +499,21 @@ class TestTorus(unittest.TestCase):
self.assertAlmostEqual(test.part.volume, pi * 100 * 2 * pi * 100, 5)
class TestWedge(unittest.TestCase):
def test_simple_wedge(self):
wedge = Wedge(1, 1, 1, 0, 0, 2, 5)
self.assertAlmostEqual(wedge.volume, 4.833333333333334, 5)
def test_invalid_wedge(self):
with self.assertRaises(ValueError):
Wedge(0, 1, 1, 0, 0, 2, 5)
with self.assertRaises(ValueError):
Wedge(1, 0, 1, 0, 0, 2, 5)
with self.assertRaises(ValueError):
Wedge(1, 1, 0, 0, 0, 2, 5)
if __name__ == "__main__":
unittest.main()