U
    L?hpa                     @   s   d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZ ddlmZ dd ZG dd	 d	ZG d
d dZG dd dZdS )z<Tests for the ``sympy.physics.mechanics.pathway.py`` module.    N)RationalSymbolcospisinsqrt)ForceLinearPathwayObstacleSetPathwayPathwayBasePointReferenceFrameWrappingCylinderWrappingGeometryBaseWrappingPathwayWrappingSpheredynamicsymbols)simplifyc                 C   s   dd | D S )Nc                 S   s    g | ]}| |j|j qS  )	__class__locationZvectorr   ).0loadr   r   \/var/www/html/venv/lib/python3.8/site-packages/sympy/physics/mechanics/tests/test_pathway.py
<listcomp>   s   z#_simplify_loads.<locals>.<listcomp>r   )loadsr   r   r   _simplify_loads   s    r   c                	   @   s  e Zd Zdd Zeejdededfi fgdd Z	eejdedfededed	fgd
d Z
eejddedfeddfgdd Zejdddd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdS ))TestLinearPathwayc                 C   s   t ttstd S N)
issubclassr	   r   AssertionErrorselfr   r   r   test_is_pathway_base_subclass&   s    z/TestLinearPathway.test_is_pathway_base_subclasszargs, kwargspApBc                 C   s   | \}}t | |}t|t s tt|ds.tt|jdks@t|jd |ksRt|jd |ksdtt|jd tsxt|jd jdkstt|jd tst|jd jdkstd S )Nattachments   r      r$   r%   )r	   
isinstancer    hasattrlenr&   r   name)argskwargsZpointAZpointBinstancer   r   r   test_valid_constructor)   s    
z(TestLinearPathway.test_valid_constructorr&   pZc              	   C   s"   t t t|  }W 5 Q R X d S r   )pytestraises
ValueErrorr	   r&   _r   r   r   )test_invalid_attachments_incorrect_number=   s    	z;TestLinearPathway.test_invalid_attachments_incorrect_numberNc              	   C   s"   t t t|  }W 5 Q R X d S r   )r2   r3   	TypeErrorr	   r5   r   r   r   "test_invalid_attachments_not_pointI   s    	z4TestLinearPathway.test_invalid_attachments_not_pointTZautousec                 C   s~   t d| _td| _td| _t| j| j| _td| _td| _	td| _
tdd| _tdd| _tdd| _td| _d S )	NNr$   r%   q1q2q3r(   F)r   r;   r   r$   r%   r	   pathwayr   r<   r=   r>   q1dq2dq3dr   r?   r!   r   r   r   _linear_pathway_fixtureU   s    





z)TestLinearPathway._linear_pathway_fixturec              	   C   sn   t | j| j}tt d |_W 5 Q R X tt d |jd< W 5 Q R X tt d |jd< W 5 Q R X d S Nr   r(   )r	   r$   r%   r2   r3   AttributeErrorr&   r8   r"   r/   r   r   r   test_properties_are_immutablec   s    z/TestLinearPathway.test_properties_are_immutablec                 C   s&   t | j| j}d}t||ks"td S )NzLinearPathway(pA, pB))r	   r$   r%   reprr    r"   r@   expectedr   r   r   	test_reprl   s    zTestLinearPathway.test_reprc                 C   s,   | j | jd| jj  | jjdks(td S Nr'   )r%   set_posr$   r;   xr@   lengthr    r!   r   r   r   test_static_pathway_lengthq   s    z,TestLinearPathway.test_static_pathway_lengthc                 C   s,   | j | jd| jj  | jjdks(td S Nr'   r   )r%   rN   r$   r;   rO   r@   extension_velocityr    r!   r   r   r   &test_static_pathway_extension_velocityu   s    z8TestLinearPathway.test_static_pathway_extension_velocityc                 C   s\   | j | jd| jj  | j| j | jj f| j | j| jj fg}| j| j|ksXtd S rM   )	r%   rN   r$   r;   rO   r?   r@   to_loadsr    r"   rK   r   r   r   test_static_pathway_to_loadsy   s
    z.TestLinearPathway.test_static_pathway_to_loadsc                 C   sD   | j | jd| j | jj  dt| jd  }| jj|ks@t	d S rM   )
r%   rN   r$   r<   r;   rO   r   r@   rP   r    rV   r   r   r   test_2D_pathway_length   s    z(TestLinearPathway.test_2D_pathway_lengthc                 C   sP   | j | jd| j | jj  dt| jd  | j | j }| jj	|ksLt
d S rM   )r%   rN   r$   r<   r;   rO   r   rA   r@   rS   r    rV   r   r   r   "test_2D_pathway_extension_velocity   s    z4TestLinearPathway.test_2D_pathway_extension_velocityc                 C   s   | j | jd| j | jj  | j| j | jt| jd   | jj f| j | j| jt| jd   | jj fg}| j	| j|kst
d S rM   )r%   rN   r$   r<   r;   rO   r?   r   r@   rU   r    rV   r   r   r   test_2D_pathway_to_loads   s
    (&z*TestLinearPathway.test_2D_pathway_to_loadsc                 C   s|   | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }t| jj| dksxtd S Nr'      r   )r%   rN   r$   r<   r;   rO   r=   yr>   zr   r   r@   rP   r    rV   r   r   r   test_3D_pathway_length   s    ,&z(TestLinearPathway.test_3D_pathway_lengthc                 C   s   | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }| j| j | | j| j |  d| j | j |  }t| jj| dkstd S r[   )r%   rN   r$   r<   r;   rO   r=   r]   r>   r^   r   rA   rB   rC   r   r@   rS   r    )r"   rP   rK   r   r   r   "test_3D_pathway_extension_velocity   s    ,&z4TestLinearPathway.test_3D_pathway_extension_velocityc                 C   s*  | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }| j | j | jj | | j| j | jj |  d| j | j | jj	 |  }| j| j | jj | | j| j | jj |  d| j | j | jj	 |  }| j|f| j |fg}| j| j|ks&td S )Nr'   r\   )r%   rN   r$   r<   r;   rO   r=   r]   r>   r^   r   r?   r@   rU   r    )r"   rP   pO_forceZpI_forcerK   r   r   r   test_3D_pathway_to_loads   s*    ,&z*TestLinearPathway.test_3D_pathway_to_loads)__name__
__module____qualname__r#   staticmethodr2   markparametrizer   r0   r7   r9   fixturerD   rH   rL   rQ   rT   rW   rX   rY   rZ   r_   r`   rb   r   r   r   r   r   $   sJ   



	r   c                
   @   s~  e Zd Zdd Zeejdddd dD fdd	d d
D fddd dD fddd dD fgdd Zeejde	dge	de	dggdd Z
eejdde	de	dfe	dde	dfe	de	ddfgdd Zdd Zeejddd dD d fd!d d
D d"fd#d dD d$fgd%d& Zejd'd(d)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 ZdS )7TestObstacleSetPathwayc                 C   s   t ttstd S r   )r   r
   r   r    r!   r   r   r   r#      s    z4TestObstacleSetPathway.test_is_pathway_base_subclassznum_attachments, attachments   c                 C   s   g | ]}t |qS r   r   r   r,   r   r   r   r      s     z!TestObstacleSetPathway.<listcomp>)pOr$   pIr\   c                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r      s     )rn   r$   r%   ro      c                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r      s     )rn   r$   r%   pCro      c                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r      s     )rn   r$   r%   rq   ZpDro   c                 C   sT   t | }t|t stt|ds$tt|j| ks6t|jD ]}t|ts<tq<d S )Nr&   )r
   r)   r    r*   r+   r&   r   )Znum_attachmentsr&   r/   
attachmentr   r   r   r0      s    
z-TestObstacleSetPathway.test_valid_constructorr&   rn   ro   c              	   C   s"   t t t|  }W 5 Q R X d S r   )r2   r3   r4   r
   r5   r   r   r   5test_invalid_constructor_attachments_incorrect_number   s    zLTestObstacleSetPathway.test_invalid_constructor_attachments_incorrect_numberNr$   c              	   C   s"   t t t|  }W 5 Q R X d S r   r2   r3   r8   r   r5   r   r   r   .test_invalid_constructor_attachments_not_point   s    
zETestObstacleSetPathway.test_invalid_constructor_attachments_not_pointc              	   C   s   t tdtdtd}tt d |_W 5 Q R X tt d |jd< W 5 Q R X tt d |jd< W 5 Q R X tt d |jd< W 5 Q R X d S )Nrn   r$   ro   r   r(   )r
   r   r2   r3   rF   r&   r8   r"   r@   r   r   r   rH      s    z4TestObstacleSetPathway.test_properties_are_immutablezattachments, expectedc                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r      s     zObstacleSetPathway(pO, pA, pI)c                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r      s     z"ObstacleSetPathway(pO, pA, pB, pI)c                 C   s   g | ]}t |qS r   rl   rm   r   r   r   r     s     z&ObstacleSetPathway(pO, pA, pB, pC, pI)c                 C   s   t |  }t||kstd S r   )r
   rI   r    )r&   rK   r@   r   r   r   rL      s    z TestObstacleSetPathway.test_reprTr:   c                 C   sV   t d| _td| _td| _td| _td| _td| _tdd| _	t
d| _d S )	Nr;   rn   ro   r$   r%   qr(   r?   )r   r;   r   rn   ro   r$   r%   r   ry   qdr   r?   r!   r   r   r   _obstacle_set_pathway_fixture  s    





z4TestObstacleSetPathway._obstacle_set_pathway_fixturec                 C   sp   | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}|j
ddtd  ksltd S )Nr(   r'   )r$   rN   rn   r;   rO   r%   r]   ro   r^   r
   rP   r   r    rx   r   r   r   rQ     s
    z1TestObstacleSetPathway.test_static_pathway_lengthc                 C   sd   | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}|j
dks`td S Nr   )r$   rN   rn   r;   rO   r%   r]   ro   r^   r
   rS   r    rx   r   r   r   rT     s
    z=TestObstacleSetPathway.test_static_pathway_extension_velocityc              
   C   s:  | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}t
| j| j | jj t
| j | j| jj t
| j | jtd d | jj| jj  t
| j| jtd d | jj| jj  t
| j| jtd d | jj| jj  t
| j| jtd d | jj| jj  g}|| j|ks6td S rM   )r$   rN   rn   r;   rO   r%   r]   ro   r^   r
   r   r?   r   rU   r    rJ   r   r   r   rW   &  s    ((((z3TestObstacleSetPathway.test_static_pathway_to_loadsc                 C   s   | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}dtd tddt| j   }|j|  dkstd S Nr(   r'   r   )r$   rN   rn   r;   rO   r]   r%   r   ry   r   ro   r
   r   rP   r   r    rJ   r   r   r   rX   5  s     & &"z-TestObstacleSetPathway.test_2D_pathway_lengthc                 C   s   | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}tdt	| j | j  dtt| jd   }|j|  dkstd S r}   )r$   rN   rn   r;   rO   r]   r%   r   ry   r   ro   r
   r   rz   rS   r   r    rJ   r   r   r   rY   A  s     & &0z9TestObstacleSetPathway.test_2D_pathway_extension_velocityc              	   C   s  | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}tdd | jj| jj  }tdt| j d  d | jj tdt	| j dtt| jd   | jj  }t| jtd  | jj t	| jtd  | jj  }t| j| j| t| j | j | t| j | j| t| j| j | t| j| j| t| j
| j | g}t|| j|kstd S )Nr(   r'   r\   )r$   rN   rn   r;   rO   r]   r%   r   ry   r   ro   r
   r   r   r   r?   r   rU   r    )r"   r@   ZpO_pA_force_vecZpA_pB_force_vecZpB_pI_force_vecrK   r   r   r   rZ   M  s0     & &".4z/TestObstacleSetPathway.test_2D_pathway_to_loads)rc   rd   re   r#   rf   r2   rg   rh   r0   r   rt   rv   rH   rL   ri   r{   rQ   rT   rW   rX   rY   rZ   r   r   r   r   rj      sd   	


rj   c                   @   s@  e Zd Zdd Zejdddd Zdd Zej	d	e
d
fe
d
e
de
dfgdd Zeej	d	de
dfe
d
dfgdd Zdd Zej	dededededjgdd Zdd Zdd Zdd Zed d! Zej	d"d#d$ed% fd$ed%d% ed% d% d&fd'e d( fd#ed)d%ed'd% d&fed' fgd*d+ Zej	d"d#d$ed)d%e fd#d,efd,d#efd$ed%d% ed% d% d&fd-e d( fd#ed)d%ed'd% d&fed' fd$ed%ed)d% ed% ed)d% d)fed)ed-d(e d%  fd#ed)d%ed'ed)d% d)fed)ed)d'e d%  fgd.d/ Zej	d0d1d$ed%ed)d% ed% ed)d% d&ffd#ed)d%ed'ed)d% d&ffgd2d3 Zej	d0d1d4d5d$ed%d% ed% d% d&ffd#ed)d%ed'd% d&ffd$ed%ed)d% ed% d% d)ffd#ed)d%ed'd% d)ffgd6d7 Zej	d8d9d$ed%d% ed% d% d&fd#ed%d% ed%d% d&fd:ed%d%  ed% d% d&ffd#ed)d%ed'd% d&fd$ed'd% ed)d% d&fed' d% ed)d%d) d&fffd;d< Zej	d8d9d=d>d$ed%d% ed% d% d&fd,ed% d% ed% d% d&fd)ed%d%  ed%d% d&ffd#ed)d%ed'd% d&fd$ed'd% ed)d% d&fed' d% ed)d%d) d&ffd#ed%d% ed%d% d&fd$ed%d% ed% d% d&fed% d% ed%d% d) d&ffd?d$ed%d% ed% d% d)fd@e edAdBed%    d&d(edAdBed%    fd@ed% e d%edAdBed%     d@ed% e d%edAdBed%     dCedAdBed%    fd-ed%d%  e d%edAdBed%     d-ed% e d%edAdBed%     d&fffdDdE Z dFdG Z!dHdI Z"dJdK Z#dS )LTestWrappingPathwayc                 C   s   t ttstd S r   )r   r   r   r    r!   r   r   r   r#   i  s    z1TestWrappingPathway.test_is_pathway_base_subclassTr:   c                 C   s   t d| _t d| _tddd| _t d| _td| _| jj| _	t
| j| j| _t| j| j| j	| _t| j| j| j| _td| _d S )	Nr$   r%   rT)Zpositivern   r;   r?   )r   r$   r%   r   r   rn   r   r;   r^   Zaxr   spherer   cylinderr   r@   r?   r!   r   r   r   _wrapping_pathway_fixturel  s    




z-TestWrappingPathway._wrapping_pathway_fixturec                 C   s   t | j| j| j}t|t s tt|ds.tt|jdks@tt|jd t	sTt|jd | jkshtt|jd t	s|t|jd | jkstt|dstt|j
tst|j
| jkstd S )Nr&   r'   r   r(   geometry)r   r$   r%   r   r)   r    r*   r+   r&   r   r   r   rG   r   r   r   r0   y  s    z*TestWrappingPathway.test_valid_constructorr&   r$   r%   r1   c              	   C   s*   t t t|| jf }W 5 Q R X d S r   )r2   r3   r8   r   r   )r"   r&   r6   r   r   r   rt     s    zITestWrappingPathway.test_invalid_constructor_attachments_incorrect_numberNc              	   C   s"   t t t|  }W 5 Q R X d S r   ru   r5   r   r   r   rv     s    	zBTestWrappingPathway.test_invalid_constructor_attachments_not_pointc              	   C   s(   t t t| j| j}W 5 Q R X d S r   r2   r3   r8   r   r$   r%   )r"   r6   r   r   r   1test_invalid_constructor_geometry_is_not_supplied  s    zETestWrappingPathway.test_invalid_constructor_geometry_is_not_suppliedr   r   ry   r;   c              	   C   s*   t t t| j| j|}W 5 Q R X d S r   r   )r"   r   r6   r   r   r   "test_invalid_geometry_not_geometry  s    
z6TestWrappingPathway.test_invalid_geometry_not_geometryc              	   C   sL   t t | j| jjd< W 5 Q R X t t | j| jjd< W 5 Q R X d S rE   )r2   r3   r8   r%   r@   r&   r$   r!   r   r   r   &test_attachments_property_is_immutable  s    z:TestWrappingPathway.test_attachments_property_is_immutablec              	   C   s"   t t d | j_W 5 Q R X d S r   )r2   r3   rF   r@   r   r!   r   r   r   #test_geometry_property_is_immutable  s    z7TestWrappingPathway.test_geometry_property_is_immutablec                 C   s$   d| j d}t| j|ks td S )Nz!WrappingPathway(pA, pB, geometry=))r   rI   r@   r    rV   r   r   r   rL     s    zTestWrappingPathway.test_reprc                 C   s   t dd t| |D S )Nc                 s   s   | ]\}}|| V  qd S r   r   r   magunitr   r   r   	<genexpr>  s     z9TestWrappingPathway._expand_pos_to_vec.<locals>.<genexpr>)sumzip)posframer   r   r   _expand_pos_to_vec  s    z&TestWrappingPathway._expand_pos_to_veczpA_vec, pB_vec, factorr(   r   r   r   r(   r   r'   r   rk   r\   r(   c                 C   s~   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|| j }t	|j
| dksztd S r|   )r   r;   r$   rN   rn   r   r%   r   r   r   rP   r    r"   pA_vecpB_vecfactorr@   rK   r   r   r   $test_static_pathway_on_sphere_length  s    	
z8TestWrappingPathway.test_static_pathway_on_sphere_lengthrw   r   r   rp   c                 C   s   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|t	| jd  }t
|j| dkstd S rR   )r   r;   r$   rN   rn   r   r%   r   r   r   r   rP   r    r   r   r   r   &test_static_pathway_on_cylinder_length  s    z:TestWrappingPathway.test_static_pathway_on_cylinder_lengthzpA_vec, pB_vec)r   r   c                 C   sl   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|j	dksht
d S r|   )r   r;   r$   rN   rn   r   r%   r   r   rS   r    r"   r   r   r@   r   r   r   0test_static_pathway_on_sphere_extension_velocity  s    	zDTestWrappingPathway.test_static_pathway_on_sphere_extension_velocity)r   r   )r   r   c                 C   sl   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|j	dksht
d S r|   )r   r;   r$   rN   rn   r   r%   r   r   rS   r    r   r   r   r   2test_static_pathway_on_cylinder_extension_velocity  s    zFTestWrappingPathway.test_static_pathway_on_cylinder_extension_velocityzApA_vec, pB_vec, pA_vec_expected, pB_vec_expected, pO_vec_expected)r   r   r   r   )rw   rw   r   rw   c              	   C   s>  |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}t	dd t
|| jD }t	dd t
|| jD }t	dd t
|| jD }t| j| j| jd t| jd   | t| j| j| jd t| jd   | t| j| j| jd t| jd   | g}|| j|ks:td S )Nc                 s   s   | ]\}}|| V  qd S r   r   r   r   r   r   r   7  s    zMTestWrappingPathway.test_static_pathway_on_sphere_to_loads.<locals>.<genexpr>c                 s   s   | ]\}}|| V  qd S r   r   r   r   r   r   r   :  s    c                 s   s   | ]\}}|| V  qd S r   r   r   r   r   r   r   =  s    rk   rr   )r   r;   r$   rN   rn   r   r%   r   r   r   r   r   r?   r   rU   r    )r"   r   r   pA_vec_expectedpB_vec_expectedpO_vec_expectedr@   rK   r   r   r   &test_static_pathway_on_sphere_to_loads  s&    


(((z:TestWrappingPathway.test_static_pathway_on_sphere_to_loads)r   r   r   r   )r   r   )r   r   r   rw   r   r   )r   r'   r   )r   )r   r(   r(   )r   r   r(   )r   r   rw   )r   r   r         c                 C   s   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}| j	|  || j }| j	|  || j }| j	|  || j }	t
| j|t
| j|t
| j|	g}
t|| j	|
kstd S r   )r   r;   r$   rN   rn   r   r%   r   r   r?   r   r   rU   r    )r"   r   r   r   r   r   r@   ZpA_force_expectedZpB_force_expectedZpO_force_expectedrK   r   r   r   (test_static_pathway_on_cylinder_to_loadsG  s&    5





z<TestWrappingPathway.test_static_pathway_on_cylinder_to_loadsc                 C   s   t d}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | jt|d  }t| jj| dkstd S )Nry   r'   r   )r   r   r;   rO   r   r   r]   r$   rN   rn   r%   r   r   r@   rP   r    )r"   ry   pA_pospB_posrK   r   r   r   "test_2D_pathway_on_cylinder_length  s    &z6TestWrappingPathway.test_2D_pathway_on_cylinder_lengthc                 C   s   t d}t dd}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | jt|d |  | }t| jj| dkstd S )Nry   r(   r'   r   )r   r   r;   rO   r   r   r]   r$   rN   rn   r%   r   r   r@   rS   r    )r"   ry   rz   r   r   rK   r   r   r   .test_2D_pathway_on_cylinder_extension_velocity  s    
&zBTestWrappingPathway.test_2D_pathway_on_cylinder_extension_velocityc           	      C   s   t d}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | j| jj }| jt|| jj t|| jj   }| jt| | jj t|d | jj   }t| j|t| j
|t| j	|g}t| j| j}||kstd S )Nry   r(   )r   r   r;   rO   r   r   r]   r$   rN   rn   r%   r?   r   r   r@   rU   r    )	r"   ry   r   r   ZpA_forceZpB_forcera   rK   r   r   r   r   $test_2D_pathway_on_cylinder_to_loads  s    &&,


z8TestWrappingPathway.test_2D_pathway_on_cylinder_to_loads)$rc   rd   re   r#   r2   ri   r   r0   rg   rh   r   rt   rf   rv   r   r   r   r   rO   r   r   r   rL   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r~   g  s  




	

( 
	( &
	* 
$

4&&*&-
	
r~   )__doc__r2   Zsympyr   r   r   r   r   r   Zsympy.physics.mechanicsr   r	   r
   r   r   r   r   r   r   r   r   Zsympy.simplify.simplifyr   r   r   rj   r~   r   r   r   r   <module>   s    4  )