HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_fractions.cpython-310.pyc
o

�i�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�0/usr/local/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�rZexpected�actualrrr�assertTypedEquals[szFractionTest.assertTypedEqualscCs0|�||�|�ttt|��ttt|���dS)zBAsserts that both the types and values in the tuples are the same.N)ZassertTupleEqualZassertListEqual�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�strZfailr.)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�)�rVrW�rW�rY)���rVrZrV)rVrV���)rV���
)rW�r_)�m+?�RrVr`)rY�M�)���r]r\����	)i�	i�	��c�qzFraction(12, 0)�ry�?@�3/2yy�?)rErCrrT�ZeroDivisionError�assertRaisesrr*rrr�testInitos("�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)r]r\�@rU��)��L�33fl皙�����?�nan�inf�-inf)rErCrrl�
ValueErrorr
�
OverflowErrorr*rrr�testInitFromFloat�s
�zFractionTest.testInitFromFloatcCs�|�dtttd����|�dtttd����|�dtttd����|�tttd��|�tttd��|�tttd	��|�tttd
��dS)N)rbr^z1.1)rW��z3.5e-2rUz.000e20rr�snanrsrt)rErCrrrlrurvr*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)r]rV�5)rYr\rjz 
  +3/2)���r\z-3/2  )�
r\z    013/02 
  )�r]z 3.2 )i�r]z -3.2 )r|rVz -3. )rYr]z .6 )rVi5z32.e-5)i@BrVz1E+06)i���rVz-1.23e4rUz .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'Z3a2z%Invalid literal for Fraction: '3/7.2'z3/7.2z%Invalid literal for Fraction: '3.2/7'z3.2/7z!Invalid literal for Fraction: '.'�.)rErCrrTrkrur*rrr�testFromString�sl����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)NrWrYr\r_rXr@rirA��)r�r\)
rrrErCrl�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�@@)r^rVr^l�{�C	rVrUro�$@)���r\g�)ll+?�RrV�J��-�Dr`)rpl g������	@g��(cannot convert Infinity to integer ratio�#cannot convert NaN to integer ratio)
rlrrrrErCr
rTrvru)rZbigintrsrrrrr�
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�r^rVrz-0r]z0.5i�z5e-3i�Z5e3l�7�3M�e'z 0.999999999999999999999999999999r�rsrtr�rrry)	rlrrZfrom_decimalrErrTrvrur*rrr�testFromDecimals2�
�
�
�
�zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr�r�)r\rY���)r[rYi����rrU)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'rgrhi�����piM�j��rx�drV�e�fr)rrZz$max_denominator should be at least 1)rrEZlimit_denominatorrTru)rZrpi�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)NrZi����r^rVrbr[rdrr������FTrYr\rqA�22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222227gUUUUUU�?A�33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331��������?)rIr4�truncr�floor�ceil�int�roundrE�boolr
rlrv�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>.CustomValuerVcSs
||_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�rVTrF)	�	functools�total_orderingrr�registerrZassertIsr@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�����rZr^r�r�rVi��)rIrr�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)NrVr\r^r]r|�r�rYr�r��r[rer`rWr���@rZr)
rErrI�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�r^�#rVlP��~�cegrWlr\r�rYr]l��_�rxr_)rIrrLr�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)"Nrbr^rVg�������?g�?y�������?y�?rcg�������y�������reg�������?y�������?rqr�r�y$@r�r`l�d�&O�!g"@g�������?rsrtrZg��������r�r[r\r�r�g�?)
rIrr
rLr�r�r�r�rEr�rlrkr)rr�rrr�testMixedArithmetic�sx" &&&&

�z FractionTest.testMixedArithmeticcCs<|�ttjtdd�td��|�ttjtd�tdd��dS)NrYrbz	3.1415926)rlrr�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)NrVr\rY)�
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)NrVr\rYr�rW)r�rr3r�r*rrr�testComparisonsDummyRationals8z)FractionTest.testComparisonsDummyRationalcCs�td�}tdd�}|�||k�|�||kp||k�|�||k�|�||ko+||k�|�||k�|�||kp=||k�|�||k�|�||koO||k�dS)NgUUUUUU�?rVrY)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\r]r�rYrV�333333�?皙�����?��?rsrtrr^rrr|rW�ri�����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�rVr\r�r�r�rYr]rsrtrr^rrr|rWr�rir�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)Nr`r�rV)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)Nr`rYr�g�?r�g�������?)r�rr�rlrrr'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�rVr\r�r�r�rYr]rrrWrsrtr�r*rrr�testMixedEqualvszFractionTest.testMixedEqualcCsp|�dttdd���|�dttd���|�dttdd���|�d	ttdd���|�d
ttdd���dS)NzFraction(7, 3)rWrYz Fraction(6283185307, 2000000000)z3.1415926535z#Fraction(-1, 100000000000000000000)rVl���� F�x:^Vz7/3�7)rE�reprrrMr*rrr�testStringification�s
��z FractionTest.testStringificationcCs�tjj}tjj}|�td�ttdd���|�tdd�ttdd���|�ttd��ttd���|�|ttd|���|�ttd��td��	��dS)	Nrnr]r\r^�2r`rVrZ)
�sys�	hash_info�modulusrsrE�hashrr�r
�__hash__)rZhmodZhinfrrr�testHash�s  zFractionTest.testHashc	Cs�td�}d|dddddf\}}}}}}}t||�tdd�krH|}|||d}}|||d}}|||}||7}t||�tdd�ks|�tj|�dS)NrYrrV��ʚ;r�� )r�absr�r4�pi)	rZthree�lasts�t�s�nZna�d�darrr�testApproximatePi�s �zFractionTest.testApproximatePicCs�td�}ddtd�dddf\}}}}}}t||�tdd�krJ|}|d7}|||d9}|||9}|d9}||||7}t||�tdd�ks|�t�d�|�dS)NrVrr�r\rZ)rr�r�r4�cos)rr�r�r�r�Zfactr6�signrrr�testApproximateCos1�s �z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)Nr}rW)
rr?rErr�idrrr�rI)rrBZdrrrr�test_copy_deepcopy_pickle�s

z&FractionTest.test_copy_deepcopy_picklecCs tdd�}|�tt|dd�dS)Nr}rW�ar^)rrlr�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|��Srr�rrrr�__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|��Srr�r*rrrr@�sz7FractionTest.test_int_subclass.<locals>.myint.numeratorcSst|�d�S)NrV)rFr*rrrrA�sz9FractionTest.test_int_subclass.<locals>.myint.denominatorN)	r.r/r0r�r�r�r�r@rArrrr�myint�s
r�rYr�rVr\)r�r9r:rEr@rArF)rr��frrr�test_int_subclass�szFractionTest.test_int_subclassN)&r.r/r0rIrLrTrmrrwrzr�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�r�rrrrrDYsH



5$""E 
	
rD�__main__)r1ZdecimalrZtest.supportrr4rrr9r�r�Zunittestrr�picklerrr:r�objectrr3r?rCZTestCaserDr.�mainrrrr�<module>s4  �