From 8db14879e45a023a99cfeeebcc8649dadadb7695 Mon Sep 17 00:00:00 2001 From: cord Date: Fri, 20 Jun 2025 12:28:32 -0600 Subject: [PATCH 1/3] expanding test coverage for designer/selection.py, designer/part.py, math\bbox.py, math\matrix.py, math\vector.py --- tests/integration/test_design.py | 36 +++++++++++++- tests/test_math.py | 83 +++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_design.py b/tests/integration/test_design.py index 8befe74266..abe8f0cfd5 100644 --- a/tests/integration/test_design.py +++ b/tests/integration/test_design.py @@ -37,8 +37,9 @@ SharedTopologyType, SurfaceType, ) -from ansys.geometry.core.designer.body import CollisionType, FillStyle +from ansys.geometry.core.designer.body import CollisionType, FillStyle, MasterBody from ansys.geometry.core.designer.face import FaceLoopType +from ansys.geometry.core.designer.part import MasterComponent, Part from ansys.geometry.core.errors import GeometryExitedError from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType from ansys.geometry.core.math import ( @@ -55,6 +56,7 @@ ) from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance from ansys.geometry.core.misc.auxiliary import DEFAULT_COLOR +from ansys.geometry.core.modeler import Modeler from ansys.geometry.core.parameters.parameter import ParameterType, ParameterUpdateStatus from ansys.geometry.core.shapes import ( Circle, @@ -76,6 +78,38 @@ from .conftest import FILES_DIR +def test_design_selection(modeler: Modeler): + """Test to validate the designer selection for edges and __repr__ method.""" + sketch = Sketch() + sketch.box(Point2D([0, 0]), 10, 10) + design = modeler.create_design("Box") + body = design.extrude_sketch("Box", sketch, Quantity(2, UNITS.m)) + ns_edge = design.create_named_selection("The Edges", body.edges[0:2]) + assert ns_edge.edges[0].start == Point3D([-5, -5, 2]) + assert ns_edge.edges[0].end == Point3D([5, -5, 2]) + assert ns_edge.edges[1].start == Point3D([-5, -5, 0]) + assert ns_edge.edges[1].end == Point3D([-5, -5, 2]) + assert ns_edge.__repr__()[0:54] == "ansys.geometry.core.designer.selection.NamedSelection " + + +def test_design_part(modeler: Modeler): + """Test to validate the designer part id, name, and setter for components and bodies.""" + body1 = MasterBody(id="body1", name="First Only Body", grpc_client=modeler.client) + body2 = MasterBody(id="body2", name="Second Body in Component", grpc_client=modeler.client) + bodies = [body1] + part = Part(id="IDPart", name="NamePart", components=[], bodies=bodies) + masterPart = MasterComponent(id="PartMaster", name="Part Master", part=part) + assert masterPart.id == "PartMaster" + assert masterPart.name == "Part Master" + assert masterPart.__repr__()[0:50] == "MasterComponent(id=PartMaster, name=Part Master, t" + assert part.id == "IDPart" + assert part.name == "NamePart" + part.components = [body2] + assert part.components[0].name == "Second Body in Component" + part.bodies = body1 + assert part.bodies.name == "First Only Body" + + def test_design_extrusion_and_material_assignment(modeler: Modeler): """Test to validate the extrusion of a simple circle as a cylinder and the assignment of materials to it. diff --git a/tests/test_math.py b/tests/test_math.py index 8180d2c2a7..fcc965831c 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -50,11 +50,39 @@ Vector3D, get_two_circle_intersections, ) +from ansys.geometry.core.math.misc import intersect_interval from ansys.geometry.core.misc import UNITS DOUBLE_EPS = np.finfo(float).eps +def test_intersect_interval(): + first_interval_min = 10 + first_interval_max = 1 + second_interval_min = 5 + second_interval_max = 2 + + intersect, intersection_min, intersection_max = intersect_interval( + first_interval_min, second_interval_min, first_interval_max, second_interval_max + ) + assert intersect is False + assert intersection_min == 0 + assert intersection_max == 0 + + # 132 + first_interval_min = 10 + first_interval_max = 15 + second_interval_min = 5 + second_interval_max = 20 + + intersect, intersection_min, intersection_max = intersect_interval( + first_interval_min, second_interval_min, first_interval_max, second_interval_max + ) + assert intersect is True + assert intersection_min == 10 + assert intersection_max == 15 + + def test_point(): """Simple test to create ``Point2D`` and ``Point3D``.""" # Test the default Point3D @@ -392,6 +420,11 @@ def test_vector3d(): assert UNITVECTOR3D_X.is_opposite(Vector3D([-1, 0, 0])) assert not UNITVECTOR3D_X.is_opposite(UNITVECTOR3D_X) + # Testing it fails for zero 2D vectors + vector1 = Vector3D([0, 0, 0]) + vector2 = Vector3D([0, 0, 0]) + assert vector1.is_parallel_to(vector2) is False + def test_vector2d(): """Simple test to create ``Vector2D``.""" @@ -478,6 +511,11 @@ def test_vector2d(): assert UNITVECTOR2D_X.is_opposite(Vector2D([-1, 0])) assert not UNITVECTOR2D_X.is_opposite(UNITVECTOR2D_X) + # Testing it fails for zero 2D vectors + vector1 = Vector2D([0, 0]) + vector2 = Vector2D([0, 0]) + assert vector1.is_parallel_to(vector2) is False + def test_unitvector3d(): """Simple test to create a ``UnitVector3D``.""" @@ -646,6 +684,12 @@ def test_rotate_vector(): # Assert that the result matches the expected vector assert np.allclose(result_vector, expected_vector) + # Testing that the vector cannot be zero + vector1 = Vector3D([0, 0, 0]) + vector2 = Vector3D([0, 0, 0]) + with pytest.raises(Exception, match="Invalid vector operation: rotation axis cannot be zero."): + vector1.rotate_vector(vector2, np.pi) + def test_matrix(): """Simple test to create a ``Matrix``.""" @@ -679,6 +723,18 @@ def test_matrix(): with pytest.raises(ValueError, match="Matrix should only be a 2D array."): Matrix([None, None, None, None, None]) + # 221 checking if the 2nd row is part of identify matrix + matrix = Matrix44([[1, 0, 0, 5], [1, 1, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]]) + assert matrix.is_translation() is False + + # 227 checking if the 3rd row is part of identify matrix + matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.5, 2], [0, 0, 0, 1]]) + assert matrix.is_translation() is False + + # 229 - not sure if this needed since it should be covered in 227 + matrix = Matrix44([[1, 0, 0, 5], [0, 1, 0, 3], [0, 0, 0.8, 2], [0, 0, 0, 1]]) + assert matrix.is_translation() is False + def test_matrix_errors(): """Testing multiple ``Matrix`` errors.""" @@ -706,6 +762,15 @@ def test_matrix_errors(): ): m_1 * m_2 + # Error if x and y vectors are not orthongonal for rotation + matrix = Matrix44([[1, 0, 0, 5], [1, 0, 0, 3], [0, 0, 1, 2], [0, 0, 0, 1]]) + with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."): + matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([1, 0, 0])) + + # Error if x and z and y and z are not orthongonal for rotation + with pytest.raises(ValueError, match="The provided direction vectors are not orthogonal."): + matrix.create_rotation(Vector3D([1, 0, 0]), Vector3D([0, 1, 0]), Vector3D([1, 1, 0])) + def test_matrix_33(): """Simple test to create a ``Matrix33``.""" @@ -1335,9 +1400,13 @@ def test_bounding_box2d_no_intersection(): box1 = BoundingBox2D(0, 1, 0, 1) box2 = BoundingBox2D(2, 3, 0, 1) - # Get intersection and check + # Get intersection for x and check intersection = BoundingBox2D.intersect_bboxes(box1, box2) assert intersection is None + # Get intersection for y and check + boxFirst = BoundingBox2D(0, 5, 0, 5) + boxSecond = BoundingBox2D(3, 8, 6, 8) + assert BoundingBox2D.intersect_bboxes(boxFirst, boxSecond) == None def test_bounding_box_evaluates_bounds_comparisons(): @@ -1373,6 +1442,16 @@ def test_bounding_box_no_intersection(): box1 = BoundingBox(Point3D([0, 0, 0]), Point3D([1, 1, 0])) box2 = BoundingBox(Point3D([2, 0, 0]), Point3D([3, 1, 0])) - # Get intersection and check + # Get intersection for x and check intersection = BoundingBox.intersect_bboxes(box1, box2) assert intersection is None + + # Get intersection for y and check + firstBoxBounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 1, 1]), Point3D([0, 0, 0])) + secondBoxBounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) + assert BoundingBox.intersect_bboxes(firstBoxBounding, secondBoxBounding) == None + + # Get intersection for z and check + firstBoxBounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 2, 1]), Point3D([0, 0, 0])) + secondBoxBounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) + assert BoundingBox.intersect_bboxes(firstBoxBounding, secondBoxBounding) == None From 901f76234b180cf19f60997cb8ed3bab3039ae60 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:36:15 +0000 Subject: [PATCH 2/3] chore: adding changelog file 2061.test.md [dependabot-skip] --- doc/changelog.d/2061.test.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/2061.test.md diff --git a/doc/changelog.d/2061.test.md b/doc/changelog.d/2061.test.md new file mode 100644 index 0000000000..24a0a2575c --- /dev/null +++ b/doc/changelog.d/2061.test.md @@ -0,0 +1 @@ +Expanding test coverage for designer and math \ No newline at end of file From 202ca5c4113c94ca72f674c751db32e57e7ddd80 Mon Sep 17 00:00:00 2001 From: cord Date: Fri, 20 Jun 2025 13:03:00 -0600 Subject: [PATCH 3/3] correcting names and is none --- tests/integration/test_design.py | 9 ++++----- tests/test_math.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/integration/test_design.py b/tests/integration/test_design.py index abe8f0cfd5..a168b0967f 100644 --- a/tests/integration/test_design.py +++ b/tests/integration/test_design.py @@ -56,7 +56,6 @@ ) from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance from ansys.geometry.core.misc.auxiliary import DEFAULT_COLOR -from ansys.geometry.core.modeler import Modeler from ansys.geometry.core.parameters.parameter import ParameterType, ParameterUpdateStatus from ansys.geometry.core.shapes import ( Circle, @@ -98,10 +97,10 @@ def test_design_part(modeler: Modeler): body2 = MasterBody(id="body2", name="Second Body in Component", grpc_client=modeler.client) bodies = [body1] part = Part(id="IDPart", name="NamePart", components=[], bodies=bodies) - masterPart = MasterComponent(id="PartMaster", name="Part Master", part=part) - assert masterPart.id == "PartMaster" - assert masterPart.name == "Part Master" - assert masterPart.__repr__()[0:50] == "MasterComponent(id=PartMaster, name=Part Master, t" + masterpart = MasterComponent(id="PartMaster", name="Part Master", part=part) + assert masterpart.id == "PartMaster" + assert masterpart.name == "Part Master" + assert masterpart.__repr__()[0:50] == "MasterComponent(id=PartMaster, name=Part Master, t" assert part.id == "IDPart" assert part.name == "NamePart" part.components = [body2] diff --git a/tests/test_math.py b/tests/test_math.py index fcc965831c..b2c1952ca6 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -1404,9 +1404,9 @@ def test_bounding_box2d_no_intersection(): intersection = BoundingBox2D.intersect_bboxes(box1, box2) assert intersection is None # Get intersection for y and check - boxFirst = BoundingBox2D(0, 5, 0, 5) - boxSecond = BoundingBox2D(3, 8, 6, 8) - assert BoundingBox2D.intersect_bboxes(boxFirst, boxSecond) == None + boxfirst = BoundingBox2D(0, 5, 0, 5) + boxsecond = BoundingBox2D(3, 8, 6, 8) + assert BoundingBox2D.intersect_bboxes(boxfirst, boxsecond) is None def test_bounding_box_evaluates_bounds_comparisons(): @@ -1447,11 +1447,11 @@ def test_bounding_box_no_intersection(): assert intersection is None # Get intersection for y and check - firstBoxBounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 1, 1]), Point3D([0, 0, 0])) - secondBoxBounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) - assert BoundingBox.intersect_bboxes(firstBoxBounding, secondBoxBounding) == None + firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 1, 1]), Point3D([0, 0, 0])) + secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) + assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None # Get intersection for z and check - firstBoxBounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 2, 1]), Point3D([0, 0, 0])) - secondBoxBounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) - assert BoundingBox.intersect_bboxes(firstBoxBounding, secondBoxBounding) == None + firstboxbounding = BoundingBox(Point3D([-1, -1, -1]), Point3D([2, 2, 1]), Point3D([0, 0, 0])) + secondboxbounding = BoundingBox(Point3D([2, 2, 2]), Point3D([3, 3, 3]), Point3D([4, 4, 4])) + assert BoundingBox.intersect_bboxes(firstboxbounding, secondboxbounding) is None