Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_fractions.cpython-310.pyc
o

�9j�v�@s�dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZm
Z
ddlmZmZejZGdd�de�ZGd	d
�d
e�ZGdd�dej�Zd
d�ZGdd�dej�Zedkrme��dSdS)zTests for Lib/fractions.py.�)�Decimal)�requires_IEEE_754N)�copy�deepcopy)�dumps�loadsc@s\eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZeZ
dS)�
DummyFloatz8Dummy float class for testing comparisons with FractionscCst|t�s	td��||_dS)Nz-DummyFloat can only be initialized from float)�
isinstance�float�	TypeError�value��selfr�r�*/usr/lib/python3.10/test/test_fractions.py�__init__s

zDummyFloat.__init__cCs:t|tj�r|t�|j�|�St|t�r||j|j�StS�N)r	�numbers�Rational�F�
from_floatrr�NotImplemented)r�other�oprrr�_richcmps

zDummyFloat._richcmpcC�|�|tj�Sr)r�operator�eq�rrrrr�__eq__!�zDummyFloat.__eq__cCrr)rr�lerrrr�__le__"r zDummyFloat.__le__cCrr)rr�ltrrrr�__lt__#r zDummyFloat.__lt__cCrr)rr�gerrrr�__ge__$r zDummyFloat.__ge__cCrr)rr�gtrrrr�__gt__%r zDummyFloat.__gt__cC�Jd��)NFz/__float__ should not be invoked for comparisonsr�rrrr�	__float__(�zDummyFloat.__float__cCr))NFz-__sub__ should not be invoked for comparisonsrrrrr�__sub__,r,zDummyFloat.__sub__N)�__name__�
__module__�__qualname__�__doc__rrrr"r$r&r(r+r-�__rsub__rrrrrsrc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
DummyRationalzATest comparison of Fraction with a naive rational implementation.cCs$t�||�}|||_|||_dSr)�math�gcd�num�den)rr6r7�grrrr4s
zDummyRational.__init__cCs(t|tj�r|j|jko|j|jkStSr)r	�	fractions�Fractionr6�
_numeratorr7�_denominatorrrrrrr9s

�zDummyRational.__eq__cCs|j|j|j|jkSr�r6r<r7r;rrrrr$@�zDummyRational.__lt__cCs|j|j|j|jkSrr=rrrrr(Cr>zDummyRational.__gt__cCs|j|j|j|jkSrr=rrrrr"Fr>zDummyRational.__le__cCs|j|j|j|jkSrr=rrrrr&Ir>zDummyRational.__ge__cCr))NFz__float__ should not be invokedrr*rrrr+Nr,zDummyRational.__float__N)r.r/r0r1rrr$r(r"r&r+rrrrr31sr3c@seZdZdZdS)�
DummyFractionz6Dummy Fraction subclass for copy and deepcopy testing.N)r.r/r0r1rrrrr?Qsr?cCs|j|jfSr)�	numerator�denominator)�rrrr�_componentsUsrCc@s eZdZdd�Zdd�Zdd�Zdd�Zed	d
��Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dES)F�FractionTestcCs$|�t|�t|��|�||�dS)z4Asserts that both the types and values are the same.N)�assertEqual�type�r�expected�actualrrr�assertTypedEquals[szFractionTest.assertTypedEqualscCs0|�||�|�ttt|��ttt|���dS)zBAsserts that both the types and values in the tuples are the same.N)�assertTupleEqual�assertListEqual�list�maprFrGrrr�assertTypedTupleEquals`s$z#FractionTest.assertTypedTupleEqualsc
Os^z	||i|��Wn|y$}z|�|t|��WYd}~dSd}~ww|�d|j�dS)z@Asserts that callable(*args, **kwargs) raises exc_type(message).Nz
%s not raised)rE�str�failr.)r�exc_type�message�callable�args�kwargs�errr�assertRaisesMessagees��z FractionTest.assertRaisesMessagec	Cs�|�dtt���|�dttd���|�dtttdd����|�dttdd���|�dttdd���|�d	ttd
d
���|�dttdd
���|�dttdd���|�dttd���|�dtttdd�d���|�dttdtdd����|�dtttdd�tdd����|�tdtdd�|�ttd�|�ttd d�|�ttdd!�|�ttdd"�|�ttddd�dS)#N�r�)�rZr[�r[�r])���rZr^rZ)rZrZ���)rZ���
)r[�rc)�m+?�RrZrd)r]�M�)���rar`����	)i�	i�	��c�qzFraction(12, 0)�ry�?@�3/2yy�?)rErCrrX�ZeroDivisionError�assertRaisesrr*rrr�testInitos("�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)rar`�@rY��)��L�33fl皙�����?�nan�inf�-inf)rErCrrp�
ValueErrorr
�
OverflowErrorr*rrr�testInitFromFloat�s
�zFractionTest.testInitFromFloatcCs�|�dtttd����|�dtttd����|�dtttd����|�tttd��|�tttd��|�tttd	��|�tttd
��dS)N)rfrbz1.1)r[��z3.5e-2rYz.000e20rv�snanrwrx)rErCrrrpryrzr*rrr�testInitFromDecimal�s���z FractionTest.testInitFromDecimalcCs�|�dttd���|�dttd���|�dttd���|�dttd���|�dttd	���|�d
ttd���|�dttd
���|�dttd���|�dttd���|�dttd���|�dttd���|�dttd���|�dttd���|�dttd���|�tdtd�|�tdtd�|�tdtd �|�td!td"�|�td#td$�|�td%td&�|�td'td(�|�td)td*�|�td+td,�|�td-td.�dS)/N)rarZ�5)r]r`rnz 
  +3/2)���r`z-3/2  )�
r`z    013/02 
  )�raz 3.2 )i�raz -3.2 )r�rZz -3. )r]raz .6 )rZi5z32.e-5)i@BrZz1E+06)i���rZz-1.23e4rYz .0e+0	z-0.000e0zFraction(3, 0)z3/0z"Invalid literal for Fraction: '3/'z3/z"Invalid literal for Fraction: '/2'z/2z$Invalid literal for Fraction: '3 /2'z3 /2z$Invalid literal for Fraction: '3/+2'z3/+2z%Invalid literal for Fraction: '+ 3/2'z+ 3/2z#Invalid literal for Fraction: '3a2'�3a2z%Invalid literal for Fraction: '3/7.2'z3/7.2z%Invalid literal for Fraction: '3.2/7'z3.2/7z!Invalid literal for Fraction: '.'�.)rErCrrXroryr*rrr�testFromString�sl����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)Nr[r]r`rcr\r@rmrA��)r�r`)
rrrErCrp�AttributeError�setattrr;r<�assertNotEqual�rrBrrr�
testImmutable�s
zFractionTest.testImmutablecCs*|�ttjd�|�dtt�d���d}|�|dftt�|���|�dtt�d���|�dtt�d���|�d	tt�d
���|�dtt�d���|�td
�tt�d���|�dtt�d���|�dtt�d���d}||}|�tdtj|�|�tdtj|�|�t	dtj|�dS)N�@@)rbrZrbl�{�C	rZrYrs�$@)���r`g�)ll+?�RrZ�J��-�Drd)rtl g������	@g��(cannot convert Infinity to integer ratio�#cannot convert NaN to integer ratio)
rprrrrErCr
rXrzry)r�bigintrwrvrrr�
testFromFloat�s:�����zFractionTest.testFromFloatcCs|�ttjd�|�tdd�t�d��|�td�t�td���|�tdd�t�td���|�tdd�t�td	���|�td
�t�td���|�dtdd�t�td
���|�tdtjtd��|�tdtjtd��|�tdtjtd��|�tdtjtd��dS)Nr�rbrZrz-0raz0.5i�z5e-3i��5e3l�7�3M�e'z 0.999999999999999999999999999999r�rwrxr�rvr})	rprr�from_decimalrErrXrzryr*rrr�testFromDecimals2�
�
�
�
�zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr�r�)r`r]���)r_r]i����rrY)rEr�as_integer_ratior*rrr�test_as_integer_ratiosz"FractionTest.test_as_integer_ratiocCs�td�}|�|�d�tdd��|�|�d�tdd��|�|�d�tdd��|�|�d�tdd��|�td	d
��d�td��|�td	d
��d
�tdd
��|�td��d�td��dD]
}|�tdtd�j|�qadS)Nz3.1415926535897932i'rkrli�����piM�j��r|�drZ�e�fr)rr^z$max_denominator should be at least 1)rrE�limit_denominatorrXry)r�rpi�irrr�testLimitDenominators
��z!FractionTest.testLimitDenominatorcCsr|�dt�tdd���|�dt�tdd���|�dt�tdd���|�dt�tdd���|�dt�tdd���|�dttdd���|�dttdd���|�dttd	d���|�dttd
d���|�dttdd���|�dt	tdd���|�d
t	tdd���|�dt
tdd���|�tt
td��|�
dt
ttd�td����|�dttdd���dS)Nr^i����rbrZrfr_rhrr������FTr]r`ru��22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222227gUUUUUU�?��33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331��������?)rJr4�truncr�floor�ceil�int�roundrE�boolr
rprz�assertAlmostEqual�complexr*rrr�testConversions-s$�zFractionTest.testConversionscCsrtjGdd�d��}tj�|�|d�}t|�}|�|j|�|�t|�d�|d�}t|�}|�t|�d�dS)Nc@s8eZdZdZdd�Zdd�Zedd��Zdd	�ZeZ	d
S)z=FractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValuerZcSs
||_dSr)rr
rrrrL�
zFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__init__cSs
t|j�Sr)r�rr*rrr�__bool__Or�zFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__bool__cSs|Srrr*rrrr@RszGFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.numeratorcSstd��)Nz&Avoid comparisons in Fraction.__bool__)�AssertionErrorrrrrrWr,zDFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__eq__N)
r.r/r0rArr��propertyr@rr$rrrr�CustomValueHs
r�rZTrF)	�	functools�total_orderingrr�registerr�assertIsr@r�)rr�r@rBrrr�testBoolGuarateesBoolReturnEsz(FractionTest.testBoolGuarateesBoolReturncCs�|�td�ttd�d��|�td�ttd�d��|�td�ttd�d��|�tdd�ttd	d
�d��|�tdd�ttdd
�d��dS)
Ni8���ij���r_i�����r^rbr�r�rZi��)rJrr�r*rrr�	testRoundis
"zFractionTest.testRoundcCs�|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�tdd�tdd�tdd	��|�tdd	�tdd�tdd��|�td
d�tdd	�tdd��|�dtd
d�tdd��|�dtdd�td��|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�td�tdd�fttdd�tdd���|�td�tdd�fttdd�tdd���|�tdd�tdd�td��|�tdd�tdd�td��|�dtd	�tdd��|�tdd�tdd�
�ttd�tdd��}|�|jd�|�|jd�tdd�d}|�|tdd��|�|jd�|�|j	d�tdd�d}|�|tdd��|�|jd�|�|j	d�tdd�d}|�|td	d��|�|jd	�|�|j	d�dS)NrZr`rbrar��r�r]r�r��r_rirdr[r���@r^r)
rErrJ�divmod�powr��real�imagr@rA)r�z�prrr�testArithmeticps>"""""""",,  zFractionTest.testArithmeticc	Cs^|�tdd�tdddd�tdddd��|�tdd�td	d
d�tdd	d
��|�d
tdd�fttdddd�tdddd���|�d	ddtd	d
d�tdd	d
��|�dtdd	d
�tdd	d
��|�dtd	d	d
�fttdd	d
�tdd	d
���|�d	ddtdd�fttd	d
d�tdd	d
���dS)Nl�b;e�f�Op�Umn�P|�}�l�~J�w�5�PHyT#/jei�4�T�rb�#rZlP��~�cegr[lr`r�r]ral��_�r|rc)rJrrOr�r*rrr�testLargeArithmetic�sH�"����$������z FractionTest.testLargeArithmeticcCs�|�tdd�tdd�d�|�dtdd�d�|�dtdd�d�|�tdd�dtdd��|�ddtdd��|�ddtdd��|�tdd�tdd�d�|�d	tdd�d�|�d
tdd�d�|�tdd�dtdd��|�ddtdd��|�d
dtdd��|�tdd�tdd�d�|�dtdd�d�|�dtdd�d�|�tdd�dtdd��|�ddtdd��|�ddtdd��|�tdd�tdd�d�|�dtdd�d�|�dtdd�d�|�tdd�dtdd��|�ddtdd��|�ddtdd��|�dtdd�d�|�dtdd�d�|�ddtdd��|�ddtdd��|�ddtdd��|�tdd�tdd�d�|�dtdd�d�|�tdd�dtdd��|�ddtdd��|�dtdd�td��|�td�tdd�td��|�td�tdd�td��|�dtdd�td��|�dtdd�fttdd�d��|�tdd�ttdd�d��|�dtd�ftdtdd���|�tdd�tdtdd���|�tdtd��ttdd�td���|�tdtd��ttdd�td���|�tdtd��ttdd�td���|�tdtd��ttdd�td���|�tdd�tdd�d�|�tdd�tdd�d�|�dtdd�d�|�dtdd�d�|�ddtdd��tdtdd��}|�d|j�|�d|j	�|�tdd�dtdd��|�d dtdd��|�d!d tdd��|�ddtdd��|�
ttjtdd�d�dS)"NrfrbrZg�������?g�?y�������?y�?rgg�������y�������rig�������?y�������?rur�r�y$@r�rdl�d�&O�!g"@g�������?rwrxr^g��������r�r_r`r�r�g�?)
rJrr
rOr�r�r�r�rEr�rpror)rr�rrr�testMixedArithmetic�sx" &&&&

�z FractionTest.testMixedArithmeticcCs<|�ttjtdd�td��|�ttjtd�tdd��dS)Nr]rfz	3.1415926)rprr�addrrr*rrr�testMixingWithDecimal�s
�
�z"FractionTest.testMixingWithDecimalcCs�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)NrZr`r])�
assertTruer�assertFalser*rrr�testComparisonsszFractionTest.testComparisonscCs�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)NrZr`r]r�r[)r�rr3r�r*rrr�testComparisonsDummyRationals8z)FractionTest.testComparisonsDummyRationalcCs�td�}tdd�}|�||k�|�||kp||k�|�||k�|�||ko+||k�|�||k�|�||kp=||k�|�||k�|�||koO||k�dS)NgUUUUUU�?rZr])rrr�r�)r�x�yrrr�testComparisonsDummyFloat+s
z&FractionTest.testComparisonsDummyFloatcCs4|�dtdd�k�|�dtdd�k�|�tdd�dk�|�tdd�dk�|�tdd�dk�|�tdd�dk�|�dtdd�k�|�dtdd�k�|�td	�tdd�k�|�td
�tdd�k�|�td
�tdd�k�|�tdd�td	�k�|�tdd�td
�k�|�tdd�td
�k�dS)Nr`rar�r]rZ�333333�?皙�����?��?rwrxrrbrvr�r[�rm�����r�rr�r
r*rrr�
testMixedLess7szFractionTest.testMixedLesscCs4|�dtdd�k�|�dtdd�k�|�tdd�dk�|�tdd�dk�|�dtdd�k�|�dtdd�k�|�tdd�dk�|�tdd�dk�|�td	�tdd�k�|�td
�tdd�k�|�td
�tdd�k�|�tdd�td	�k�|�tdd�td
�k�|�tdd�td
�k�dS)Nr�rZr`r�r�r�r]rarwrxrrbrvr�r[r�rmr�r�r�r*rrr�testMixedLessEqualIszFractionTest.testMixedLessEqualcCs�|�td�td�k�|�dttt�d�d��k�|�dtt�d�d�k�|�dtt�d�d�k�|�dtt�d�d�k�|�dtt�d�d�k�dS)Nrdr�rZ)r�rr
r4r�r�r*rrr�testBigFloatComparisonsZs  z$FractionTest.testBigFloatComparisonscCs�|�td�td�k�|�ttjtd�td��|�ttjtd�td��tdd�}tdd�}tdd�}|�||k�|�||k�|�||k�|�||k�tj	tjtjtj
fD]"}|�t|||�|�t|||�|�t|||�|�t|||�qZdS)Nrdr]r�g�?r�g�������?)r�rr�rprrr'r!r�r#r%)rr�r��wrrrr�testBigComplexComparisonsds 


�z&FractionTest.testBigComplexComparisonscCs|�dtdd�k�|�dtdd�k�|�tdd�dk�|�tdd�dk�|�dtdd�k�|�dtdd�k�|�tdd�dk�|�tdd�dk�|�tdd�td	�k�|�td	�tdd
�k�|�tdd�td�k�|�td�tdd�k�dS)
Nr�rZr`r�r�r�r]rarvr[rwrxr�r*rrr�testMixedEqualvszFractionTest.testMixedEqualcCsp|�dttdd���|�dttd���|�dttdd���|�d	ttdd���|�d
ttdd���dS)NzFraction(7, 3)r[r]z Fraction(6283185307, 2000000000)z3.1415926535z#Fraction(-1, 100000000000000000000)rZl���� F�x:^Vz7/3�7)rE�reprrrPr*rrr�testStringification�s
��z FractionTest.testStringificationcCs�tjj}tjj}|�td�ttdd���|�tdd�ttdd���|�ttd��ttd���|�|ttd|���|�ttd��td��	��dS)	Nrrrar`rb�2rdrZr^)
�sys�	hash_info�modulusrwrE�hashrr�r
�__hash__)r�hmod�hinfrrr�testHash�s  zFractionTest.testHashc	Cs�td�}d|dddddf\}}}}}}}t||�tdd�krH|}|||d}}|||d}}|||}||7}t||�tdd�ks|�tj|�dS)Nr]rrZ��ʚ;r�� )r�absr�r4�pi)	r�three�lasts�t�s�n�na�d�darrr�testApproximatePi�s �zFractionTest.testApproximatePicCs�td�}ddtd�dddf\}}}}}}t||�tdd�krJ|}|d7}|||d9}|||9}|d9}||||7}t||�tdd�ks|�t�d�|�dS)NrZrr�r`r^)rr�r�r4�cos)rr�r�r�r��factr6�signrrr�testApproximateCos1�s �z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)Nr�r[)
rr?rErr�idrrr�rJ)rrB�drrrr�test_copy_deepcopy_pickle�s

z&FractionTest.test_copy_deepcopy_picklecCs tdd�}|�tt|dd�dS)Nr�r[�arb)rrpr�r�r�rrr�
test_slots�s
zFractionTest.test_slotscCshGdd�dt�}t�|d�|d��}|�|jd�|�|jd�|�t|j�|�|�t|j�|�dS)Nc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��ZdS)z-FractionTest.test_int_subclass.<locals>.myintcSst|�t|�t|��Sr�rFr�rrrr�__mul__�r>z5FractionTest.test_int_subclass.<locals>.myint.__mul__cSst|�t|�t|��Srrrrrr�__floordiv__�r>z:FractionTest.test_int_subclass.<locals>.myint.__floordiv__cSst|�t|�t|��}|Srr)rrr�rrr�__mod__�sz5FractionTest.test_int_subclass.<locals>.myint.__mod__cSst|�t|��Srrr*rrrr@�sz7FractionTest.test_int_subclass.<locals>.myint.numeratorcSst|�d�S)NrZ)rFr*rrrrA�sz9FractionTest.test_int_subclass.<locals>.myint.denominatorN)	r.r/r0r	r
rr�r@rArrrr�myint�s
rr]r�rZr`)r�r9r:rEr@rArF)rr�frrr�test_int_subclass�szFractionTest.test_int_subclassN)&r.r/r0rJrOrXrqrr{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�rrrrrrrrrDYsH



5$""E 
	
rD�__main__)r1�decimalr�test.supportrr4rrr9r�r��unittestrr�picklerrr:r�objectrr3r?rC�TestCaserDr.�mainrrrr�<module>s4  �

Youez - 2016 - github.com/yon3zu
LinuXploit