o
    GXhV`                     @   s  d dl mZmZ d dlmZmZ d dlmZ d dlZd dlZd dl	Z	d dlm
Z
mZmZmZ d dlZd dlZedZedZdd d	D Zd
d edfedfeefdefdefdefdefe efe dfe dfe dfe dfe e fde fde fde fde fee fedfedffD Zdd ee fedfedfedfedfeefe efdefdefdefdefeeffD ZG dd dejZG dd dejZedkre  dS dS )    )requires_IEEE_754cpython_only)parse_testfile	test_fileN)phasepolarrectpiinfnanc                 C   s    g | ]}d D ]}t ||qqS )               complex.0xy r   9/opt/python-3.10.19/usr/lib/python3.10/test/test_cmath.py
<listcomp>   s     r   r   c                 C      g | ]	\}}t ||qS r   r   r   r   r   r   r          r   ffffff@r   ffffffc                 C   r   r   r   r   r   r   r   r   %   r   c                   @   s  e Zd Zdd dD Zedd  edd  dd Zd	d
 Zdd Zdd Z		d<ddZ	dd Z
dd Zdd Zdd Zdd Zedd Zd d! Zd"d# Zed$d% Zd&d' Zd(d) Zed*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zed6d7 Zed8d9 Zed:d; ZdS )=
CMathTestsc                 C   s   g | ]}t t|qS r   )getattrcmath)r   Zfnamer   r   r   r   6   s    zCMathTests.<listcomp>)acosacoshasinasinhatanatanhcoscoshexploglog10sinsinhsqrttantanhc                 C   s   t | dS )Ny     @        r   r(   r   r   r   r   <lambda>;       zCMathTests.<lambda>c                 C   s   t d| S )Ny      ,@      ;r/   r0   r   r   r   r1   <   r2   c                 C   s   t tdd| _d S )Nzutf-8)encoding)openr   test_valuesselfr   r   r   setUp>   s   zCMathTests.setUpc                 C   s   | j   d S N)r5   closer6   r   r   r   tearDownA      zCMathTests.tearDownc                 C   s   	 d}t |st |rt |rt |rd S n||kr6|dkr$d S t d|t d|kr2d S |d7 }| ||| d S )Nz&floats {!r} and {!r} are not identicalr         ?z: zeros have different signs)mathisnancopysignfailformat)r7   r   r   msgr   r   r   assertFloatIdenticalD   s   zCMathTests.assertFloatIdenticalc                 C   s&   	 |  |j|j |  |j|j d S r9   )rD   realimag)r7   r   r   r   r   r   assertComplexIdentical[   s   z!CMathTests.assertComplexIdenticalV瞯<
       Nc                 C   s   	 t |rt |rd S | |pd| t |r-||kr"d S | |p+d|| |sH|sHt d|t d|krH| |pFd|| zt|| }W n	 tyY   Y nw |t||t| krgd S | |ppd|| d S )Nz{!r} should be nanz>finite result where infinity expected: expected {!r}, got {!r}r=   z,zero has wrong sign: expected {!r}, got {!r}z({!r} and {!r} are not sufficiently close)	r>   r?   rA   rB   isinfr@   absOverflowErrormax)r7   abZrel_errabs_errrC   Zabsolute_errorr   r   r   rAssertAlmostEquale   s4   






zCMathTests.rAssertAlmostEqualc                 C   sH   d}d}| j tj|ddtj|d | j tj|ddtj|d d S )NgiW
@g-DT!	@	   zcmath.pi is {}; should be {})ZplacesrC   zcmath.e is {}; should be {})assertAlmostEqualr   r	   rB   e)r7   Z
e_expectedZpi_expectedr   r   r   test_constants   s   
zCMathTests.test_constantsc                 C   s   |  tjjtj |  tjjd |  tjjd |  tjjtj | ttj	j |  tj	jd |  tj
jd | ttj
j |  ttjd |  ttjd |  ttj	d |  ttj
d d S )Nr   r
   infjr   nanj)assertEqualr   r
   rE   r>   rF   rV   
assertTruer?   r   rW   reprr6   r   r   r   test_infinity_and_nan_constants   s   z*CMathTests.test_infinity_and_nan_constantsc                    s,  ddddddd t  tg}G dd dt }G d	d
 d
}G dd dt G  fdddt }G  fddd}G dd dt }G dd d}G dd d}G dd d}	G fdddt }
G fddd}G fdddt }G fdd d }| jD ]}| ||| | ||| | ||
 | | || | | || | | || | | || |t|  | t||  | t||	  | t||  |D ]}| t||| | t||| q|  ||  |  ||  qd S )!Nyz@7Ă??g]ֆznot complex             @c                   @      e Zd Zdd Zdd ZdS )z.CMathTests.test_user_object.<locals>.MyComplexc                 S   
   || _ d S r9   valuer7   rb   r   r   r   __init__      
z7CMathTests.test_user_object.<locals>.MyComplex.__init__c                 S      | j S r9   ra   r6   r   r   r   __complex__      z:CMathTests.test_user_object.<locals>.MyComplex.__complex__N__name__
__module____qualname__rd   rg   r   r   r   r   	MyComplex       rm   c                   @   r_   )z0CMathTests.test_user_object.<locals>.MyComplexOSc                 S   r`   r9   ra   rc   r   r   r   rd      re   z9CMathTests.test_user_object.<locals>.MyComplexOS.__init__c                 S   rf   r9   ra   r6   r   r   r   rg      rh   z<CMathTests.test_user_object.<locals>.MyComplexOS.__complex__Nri   r   r   r   r   MyComplexOS   rn   ro   c                   @      e Zd ZdS )z2CMathTests.test_user_object.<locals>.SomeExceptionNrj   rk   rl   r   r   r   r   SomeException       rr   c                          e Zd Z fddZdS )z7CMathTests.test_user_object.<locals>.MyComplexExceptionc                        r9   r   r6   rr   r   r   rg         zCCMathTests.test_user_object.<locals>.MyComplexException.__complex__Nrj   rk   rl   rg   r   rv   r   r   MyComplexException       ry   c                       rt   )z9CMathTests.test_user_object.<locals>.MyComplexExceptionOSc                    ru   r9   r   r6   rv   r   r   rg      rw   zECMathTests.test_user_object.<locals>.MyComplexExceptionOS.__complex__Nrx   r   rv   r   r   MyComplexExceptionOS   rz   r{   c                   @   rp   )z;CMathTests.test_user_object.<locals>.NeitherComplexNorFloatNrq   r   r   r   r   NeitherComplexNorFloat   rs   r|   c                   @   rp   )z=CMathTests.test_user_object.<locals>.NeitherComplexNorFloatOSNrq   r   r   r   r   NeitherComplexNorFloatOS   rs   r}   c                   @   r_   )z*CMathTests.test_user_object.<locals>.Indexc                 S      dS N   r   r6   r   r   r   __int__       z2CMathTests.test_user_object.<locals>.Index.__int__c                 S   r~   r   r   r6   r   r   r   	__index__   r   z4CMathTests.test_user_object.<locals>.Index.__index__N)rj   rk   rl   r   r   r   r   r   r   Index   s    r   c                   @   s   e Zd Zdd ZdS )z*CMathTests.test_user_object.<locals>.MyIntc                 S   r~   r   r   r6   r   r   r   r      r   z2CMathTests.test_user_object.<locals>.MyInt.__int__N)rj   rk   rl   r   r   r   r   r   MyInt   s    r   c                       $   e Zd ZfddZ fddZdS )z4CMathTests.test_user_object.<locals>.FloatAndComplexc                        S r9   r   r6   flt_argr   r   	__float__   rw   z>CMathTests.test_user_object.<locals>.FloatAndComplex.__float__c                    r   r9   r   r6   cx_argr   r   rg      rw   z@CMathTests.test_user_object.<locals>.FloatAndComplex.__complex__Nrj   rk   rl   r   rg   r   r   r   r   r   FloatAndComplex       r   c                       r   )z6CMathTests.test_user_object.<locals>.FloatAndComplexOSc                    r   r9   r   r6   r   r   r   r      rw   z@CMathTests.test_user_object.<locals>.FloatAndComplexOS.__float__c                    r   r9   r   r6   r   r   r   rg      rw   zBCMathTests.test_user_object.<locals>.FloatAndComplexOS.__complex__Nr   r   r   r   r   FloatAndComplexOS   r   r   c                       rt   )z.CMathTests.test_user_object.<locals>.JustFloatc                    r   r9   r   r6   r   r   r   r      rw   z8CMathTests.test_user_object.<locals>.JustFloat.__float__Nrj   rk   rl   r   r   r   r   r   	JustFloat   rz   r   c                       rt   )z0CMathTests.test_user_object.<locals>.JustFloatOSc                    r   r9   r   r6   r   r   r   r      rw   z:CMathTests.test_user_object.<locals>.JustFloatOS.__float__Nr   r   r   r   r   JustFloatOS   rz   r   )objectNotImplemented	Exceptiontest_functionsrX   intassertRaises	TypeError)r7   Znon_complexesrm   ro   ry   r{   r|   r}   r   r   r   r   r   r   fZbad_complexr   )rr   r   r   r   test_user_object   sF   

zCMathTests.test_user_objectc                 C   sV   | j D ]}dD ]}| ||||  qq| j D ]}dD ]	}| t|| qqd S )N)r   r^   )rN   Zlong_string0Z1j )r   rX   r   r   r   )r7   r   argr   r   r   test_input_type  s   

zCMathTests.test_input_typec                 C   s  g d}|dd |D  g d }|dg dd |D  }dg| }dg| dd |D  }|||||||||||||d	}|  D ]'\}}tt|}	tt|}
|D ]}|
|}| |	||j | d|j qRqBd
D ]}|D ]}t||}| t|||j | d|j qpqld S )N)g{Gz?g?g?      ?g?gGz?c                 S      g | ]}| qS r   r   r   r   r   r   r   r   &      z6CMathTests.test_cmath_matches_math.<locals>.<listcomp>)r   r=         r=   c                 S   s   g | ]}d | qS )r=   r   r   r   r   r   r   *  s    r   c                 S   r   r   r   r   r   r   r   r   .  r   )r   r!   r#   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   )r   r^   g      $@)	itemsr   r>   r   rQ   rE   rX   rF   r(   )r7   r5   Zunit_intervalZpositiveZnonnegativeZ	real_liner   fnvaluesZfloat_fnZ
complex_fnvzbaser   r   r   test_cmath_matches_math  sH   


z"CMathTests.test_cmath_matches_mathc                 C   s  dh}d }t jdkr&t d }zttt|d}W n	 ty%   Y nw dd }dd }tt	D ]\}}}}	}
}}t
||	}t
|
|}|d urR|d	k rR||v rRq2|d
krY|}n|dkr`|}ntt|}d|v smd|v rz||}W n	 ty|   Y q2w | d||||	 d|v rz||}W n	 ty   Y q2w | d||||	 ||}d|v rt
t|j|j}t
t|j|j}d|v rt
|jt|j}t
|jt|j}|dv rd}nd}d||||	|j|j|j|j}| j|j|j||d | j|j|j|d q2d S )NZtan0064darwinr   .c                 S   s   	 t | j| jS r9   )r   r   rE   rF   r   r   r   r   rect_complex\  s   z5CMathTests.test_specific_values.<locals>.rect_complexc                 S   s   	 t t|  S r9   )r   r   r   r   r   r   polar_complexa  s   z6CMathTests.test_specific_values.<locals>.polar_complex)
   r]   r   r   zdivide-by-zeroinvalidz9ValueError not raised in test {}: {}(complex({!r}, {!r}))Zoverflowz<OverflowError not raised in test {}: {}(complex({!r}, {!r}))zignore-real-signzignore-imag-sign)r(   r)   rH   rI   z{}: {}(complex({!r}, {!r}))
Expected: complex({!r}, {!r})
Received: complex({!r}, {!r})
Received value insufficiently close to expected value.)rP   rC   )rC   )sysplatformZmac_vertuplemapr   split
ValueErrorr   r   r   r   r   rA   rB   rL   rK   rE   rF   rQ   )r7   ZSKIP_ON_TIGERZosx_versionZversion_txtr   r   idr   arZaiZereiflagsr   expectedfunctionactualZreal_abs_errZerror_messager   r   r   test_specific_valuesN  s   




zCMathTests.test_specific_valuesc                    s   fdd}|dd |dd |ddt f |d	dt d
 f |ddt  d
 f td}|t|d|df |t| d|t f |td||t d
 f |td| |t  d
 f |t|||t d f |t|| |t  d f |t| ||dt  d f |t| | |dt  d f td}|t|d||f |td|||f |t||||f |t||||f |t| |||f |t||||f |t|| ||f d S )Nc                    s,    | }t ||D ]
\}}|| q	d S r9   )ziprQ   )r   r   ZgotrT   gfuncr7   r   r   check  s   z%CMathTests.check_polar.<locals>.checkr   )r   r   r\   )r=   r   r=                 ?r   y             g      @r
   r      r]      r   )r	   floatr   )r7   r   r   r
   r   r   r   r   check_polar  s.   

 zCMathTests.check_polarc                 C   s   |  t d S r9   )r   r   r6   r   r   r   
test_polar  r<   zCMathTests.test_polarc                    s&   ddl m   fdd}| | d S )Nr   	set_errnoc                    s&    d z	t | W  d S  d w )N   r   )r   r   r   r   r   polar_with_errno_set  s   z9CMathTests.test_polar_errno.<locals>.polar_with_errno_set)Z	_testcapir   r   )r7   r   r   r   r   test_polar_errno  s   zCMathTests.test_polar_errnoc                 C   s  |  tdd |  tdd |  tdt |  tdt |  tdt  |  tdtd  |  td	t d  | ttddd | ttdd
d
 | ttd
dt | ttd
d
t  |  ttt d
t  |  ttt dt  |  ttt t dt  |  ttdt t d  |  ttd
t t d  |  ttdt t d  |  ttdt t d  |  tttt t d  | tttdd
 | tttd
d
 | tttdd | tttdd |  tttttd  |  ttdttd  |  ttdttd  |  ttd
ttd  |  ttdttd  |  ttt tdt  |  ttt dt |  ttt dt tD ]}| t	t| qtd S )Nr   r   r=   r   y      Yny      Ynr   r   y             r   r   g      r   r   g      ?)
rS   r   r	   rX   r   INFcomplex_nansrY   r>   r?   r7   r   r   r   r   
test_phase  sD   zCMathTests.test_phasec                 C   s~  t D ]
}| t|d qtD ]
}| t|t q| tttt t | t	tttd | t	tttd | t	tttd | t	tttd | ttttt | ttt tt | t	ttdt | t	ttdt | t	ttdt | t	ttdt | ttttt | t	tttt d S )Nr   r   r   r   )
complex_zerosrX   rK   complex_infinitiesr   r   NANrY   r>   r?   r   r   r   r   test_abs  s"   zCMathTests.test_absc                 C   s   |  tttdd d S )NgU)r   rL   rK   r   r6   r   r   r   test_abs_overflows  s   zCMathTests.test_abs_overflowsc                 C   sF   d}t |j|d  |kst |j|d  |kr!| ||f d S d S )NgHz>r   r\   )rK   rE   rF   rA   )r7   rN   rO   Zepsr   r   r   assertCEqual  s   ,zCMathTests.assertCEqualc                 C   sj   |  tddd |  tddd |  tdt d |  tdtd d |  tdt d d d S )	Nr   )r   r   r\   )r=   r   )r   r   r   )r   r=   )r   r   )r   r   r	   r6   r   r   r   	test_rect  s
   zCMathTests.test_rectc                 C   sb   t dddddt dt dg}|D ]}|D ]}t||}| t|t|o+t| qqd S )Nz-infr   r   r   r   r
   r   )r   r   rX   r   isfiniter>   )r7   Z	real_valsr   r   r   r   r   r   test_isfinite#  s   

zCMathTests.test_isfinitec                 C   s   |  td |  td |  tt | tt | tttd | ttdt | tttt | tttt | tttt d S Nr\   r   r   )assertFalser   r?   r   rY   r   r   r6   r   r   r   
test_isnan,     zCMathTests.test_isnanc                 C   s   |  td |  td |  tt | tt | tttd | ttdt | tttt | tttt | tttt d S r   )r   r   rJ   r   rY   r   r   r6   r   r   r   
test_isinf7  r   zCMathTests.test_isinfc                 C       t D ]}| t|| qd S r9   )r   rG   r   r.   r   r   r   r   testTanhSignB     zCMathTests.testTanhSignc                 C   r   r9   )r   rG   r   r#   r   r   r   r   testAtanSignK  r   zCMathTests.testAtanSignc                 C   r   r9   )r   rG   r   r$   r   r   r   r   testAtanhSignP  r   zCMathTests.testAtanhSign)rH   rI   N) rj   rk   rl   r   appendr8   r;   rD   rG   rQ   rU   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   4   sJ    

2b0
V
)
	

r   c                   @   s*   e Zd ZejZdd Zdd Zdd ZdS )IsCloseTestsc                 C   s   |  t | jdddd W d    n1 sw   Y  |  t | jdddd W d    n1 s5w   Y  |  t | jddddd W d    d S 1 sTw   Y  d S )Nr   rel_tolabs_tol)r   r   )r   r   iscloser6   r   r   r   test_reject_complex_tolerancesY  s   "z+IsCloseTests.test_reject_complex_tolerancesc                 C   s(   g d}| j |dd | j|dd d S )N))      ?      ?y    ?      ?)r   y      ?    ?)y            ?y          ?)y      ?      y      ?g-q=r   gvIh%<=)assertAllCloseassertAllNotClose)r7   Zcomplex_examplesr   r   r   test_complex_valuesc  s   z IsCloseTests.test_complex_valuesc                 C   sH   g d}| j |dd | j|dd | jdddd | jdddd d S )	N))y        MbP?r   )MbP?r   )MbP?MbP?r   )yMbPMbP?r   )MbP?MbPr   )yMbPMbPr   g~jtX?r   gMb@?r   r   gMb`?r   )r   r   ZassertIsCloseZassertIsNotClose)r7   Znear_zero_examplesr   r   r   test_complex_near_zeron  s
   z#IsCloseTests.test_complex_near_zeroN)rj   rk   rl   r   r   r   r   r   r   r   r   r   r   V  s
    
r   __main__)Ztest.supportr   r   Ztest.test_mathr   r   Z	test_mathZunittestr   r>   r   r   r   r	   r   r   r   r   r   r   r   r   ZTestCaser   r   rj   mainr   r   r   r   <module>   sp    
    &)