Phi2-Fine-Tuning
/
phivenv
/Lib
/site-packages
/sympy
/physics
/mechanics
/tests
/test_wrapping_geometry.py
| """Tests for the ``sympy.physics.mechanics.wrapping_geometry.py`` module.""" | |
| import pytest | |
| from sympy import ( | |
| Integer, | |
| Rational, | |
| S, | |
| Symbol, | |
| acos, | |
| cos, | |
| pi, | |
| sin, | |
| sqrt, | |
| ) | |
| from sympy.core.relational import Eq | |
| from sympy.physics.mechanics import ( | |
| Point, | |
| ReferenceFrame, | |
| WrappingCylinder, | |
| WrappingSphere, | |
| dynamicsymbols, | |
| ) | |
| from sympy.simplify.simplify import simplify | |
| r = Symbol('r', positive=True) | |
| x = Symbol('x') | |
| q = dynamicsymbols('q') | |
| N = ReferenceFrame('N') | |
| class TestWrappingSphere: | |
| def test_valid_constructor(): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| assert isinstance(sphere, WrappingSphere) | |
| assert hasattr(sphere, 'radius') | |
| assert sphere.radius == r | |
| assert hasattr(sphere, 'point') | |
| assert sphere.point == pO | |
| def test_geodesic_length_point_not_on_surface_invalid(position): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position) | |
| error_msg = r'point .* does not lie on the surface of' | |
| with pytest.raises(ValueError, match=error_msg): | |
| sphere.geodesic_length(p1, p2) | |
| def test_geodesic_length(position_1, position_2, expected): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position_1) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position_2) | |
| assert simplify(Eq(sphere.geodesic_length(p1, p2), expected)) | |
| def test_geodesic_end_vectors(position_1, position_2, vector_1, vector_2): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position_1) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position_2) | |
| expected = (vector_1, vector_2) | |
| assert sphere.geodesic_end_vectors(p1, p2) == expected | |
| def test_geodesic_end_vectors_invalid_coincident(position): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position) | |
| with pytest.raises(ValueError): | |
| _ = sphere.geodesic_end_vectors(p1, p2) | |
| def test_geodesic_end_vectors_invalid_diametrically_opposite( | |
| position_1, | |
| position_2, | |
| ): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| sphere = WrappingSphere(r, pO) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position_1) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position_2) | |
| with pytest.raises(ValueError): | |
| _ = sphere.geodesic_end_vectors(p1, p2) | |
| class TestWrappingCylinder: | |
| def test_valid_constructor(): | |
| N = ReferenceFrame('N') | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, N.x) | |
| assert isinstance(cylinder, WrappingCylinder) | |
| assert hasattr(cylinder, 'radius') | |
| assert cylinder.radius == r | |
| assert hasattr(cylinder, 'point') | |
| assert cylinder.point == pO | |
| assert hasattr(cylinder, 'axis') | |
| assert cylinder.axis == N.x | |
| def test_point_is_on_surface(position, expected): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, N.x) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position) | |
| assert cylinder.point_on_surface(p1) is expected | |
| def test_geodesic_length_point_not_on_surface_invalid(position): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, N.x) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position) | |
| error_msg = r'point .* does not lie on the surface of' | |
| with pytest.raises(ValueError, match=error_msg): | |
| cylinder.geodesic_length(p1, p2) | |
| def test_geodesic_length(axis, position_1, position_2, expected): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, axis) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position_1) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position_2) | |
| assert simplify(Eq(cylinder.geodesic_length(p1, p2), expected)) | |
| def test_geodesic_end_vectors( | |
| axis, | |
| position_1, | |
| position_2, | |
| vector_1, | |
| vector_2, | |
| ): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, axis) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position_1) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position_2) | |
| expected = (vector_1, vector_2) | |
| end_vectors = tuple( | |
| end_vector.simplify() | |
| for end_vector in cylinder.geodesic_end_vectors(p1, p2) | |
| ) | |
| assert end_vectors == expected | |
| def test_geodesic_end_vectors_invalid_coincident(axis, position): | |
| r = Symbol('r', positive=True) | |
| pO = Point('pO') | |
| cylinder = WrappingCylinder(r, pO, axis) | |
| p1 = Point('p1') | |
| p1.set_pos(pO, position) | |
| p2 = Point('p2') | |
| p2.set_pos(pO, position) | |
| with pytest.raises(ValueError): | |
| _ = cylinder.geodesic_end_vectors(p1, p2) | |