Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_fractions.cpython-38.pyc
U

>��gWw�@s�dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
m
Z
mZddlmZmZejZejZGdd�de�ZGd	d
�d
e�ZGdd�dej�ZGd
d�dej�Zdd�ZGdd�dej�Zedkr�e��dS)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�std��||_dS)Nz-DummyFloat can only be initialized from float)�
isinstance�float�	TypeError�value��selfr�r�2/opt/cppython/lib/python3.8/test/test_fractions.py�__init__s
zDummyFloat.__init__cCs>t|tj�r|t�|j�|�St|t�r6||j|j�StSdS�N)r	�numbers�Rational�F�
from_floatrr�NotImplemented)r�other�oprrr�_richcmps

zDummyFloat._richcmpcCs|�|tj�Sr)r�operator�eq�rrrrr�__eq__"�zDummyFloat.__eq__cCs|�|tj�Sr)rr�lerrrr�__le__#rzDummyFloat.__le__cCs|�|tj�Sr)rr�ltrrrr�__lt__$rzDummyFloat.__lt__cCs|�|tj�Sr)rr�gerrrr�__ge__%rzDummyFloat.__ge__cCs|�|tj�Sr)rr�gtrrrr�__gt__&rzDummyFloat.__gt__cCsdstd��dS)NFz/__float__ should not be invoked for comparisons��AssertionError�rrrr�	__float__)szDummyFloat.__float__cCsdstd��dS)NFz-__sub__ should not be invoked for comparisonsr(rrrr�__sub__-szDummyFloat.__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)rr5r6�grrrr5s
zDummyRational.__init__cCs,t|tj�r$|j|jko"|j|jkStSdSr)r	�	fractions�Fractionr5�
_numeratorr6�_denominatorrrrrrr:s

�zDummyRational.__eq__cCs|j|j|j|jkSr�r5r;r6r:rrrrr#AszDummyRational.__lt__cCs|j|j|j|jkSrr<rrrrr'DszDummyRational.__gt__cCs|j|j|j|jkSrr<rrrrr!GszDummyRational.__le__cCs|j|j|j|jkSrr<rrrrr%JszDummyRational.__ge__cCsdstd��dS)NFz__float__ should not be invokedr(r*rrrr+OszDummyRational.__float__N)r-r.r/r0rrr#r'r!r%r+rrrrr22sr2c@seZdZdZdS)�
DummyFractionz6Dummy Fraction subclass for copy and deepcopy testing.N)r-r.r/r0rrrrr=Rsr=c@seZdZdd�ZdS)�GcdTestc	Csd|�td��tdd�W5QRXt����.t�ddt�|�dtdd��|�dtdd��|�dtdd��|�dtdd��|�dtdd��|�dtdd��|�dtdd��|�dtdd��|�d	td
d��|�dtdd
��|�tdd�d�|�td
d�d�|�ttd
�td��td	��|�ttd
d�tdd��td	d��W5QRXdS)Nzfractions\.gcd��ignorer����i�����x�Ti�i����g^@g(@gU@�M�7i�)ZassertWarnsRegex�DeprecationWarningr4�warnings�catch_warnings�filterwarnings�assertEqualrr*rrr�testMiscWs(�zGcdTest.testMiscN)r-r.r/rNrrrrr>Usr>cCs|j|jfSr)�	numerator�denominator)�rrrr�_componentsnsrRc@seZdZdd�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$dCS)D�FractionTestcCs$|�t|�t|��|�||�dS)z4Asserts that both the types and values are the same.N)rM�type�rZexpected�actualrrr�assertTypedEqualstszFractionTest.assertTypedEqualscCs0|�||�|�ttt|��ttt|���dS)zBAsserts that both the types and values in the tuples are the same.N)ZassertTupleEqualZassertListEqual�list�maprTrUrrr�assertTypedTupleEqualsysz#FractionTest.assertTypedTupleEqualsc
OsVz|||�Wn2|k
r@}z|�|t|��W5d}~XYnX|�d|j�dS)z@Asserts that callable(*args, **kwargs) raises exc_type(message).Nz
%s not raised)rM�strZfailr-)r�exc_type�message�callable�args�kwargs�errr�assertRaisesMessage~s
"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�rr?)rBr?rB�rB�re)rAr?rAr?)r?r?���)r?���
)rBrCrC)�m+?�Rr?rj)rerG�)���rhrg����	)i�	i�	��c�qzFraction(12, 0)rDry�?@�3/2yy�?)rMrRrrb�ZeroDivisionError�assertRaisesrr*rrr�testInit�s,"�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)rhrg�@rc��)��L�33fl皙�����?�nan�inf�-inf)rMrRrrt�
ValueErrorr
�
OverflowErrorr*rrr�testInitFromFloat�s
�zFractionTest.testInitFromFloatcCs�|�dtttd����|�dtttd����|�dtttd����|�tttd��|�tttd��|�tttd	��|�tttd
��dS)N)rkriz1.1)rB��z3.5e-2rcz.000e20rz�snanr{r|)rMrRrrrtr}r~r*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)rhr?�5)rergrrz 
  +3/2)���rgz-3/2  )�
rgz    013/02 
  )�rhz 3.2 )i�rhz -3.2 )r�r?z -3. )rerhz .6 )r?i5z32.e-5)i@Br?z1E+06)i���r?z-1.23e4rcz .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: '.'�.)rMrRrrbrsr}r*rrr�testFromString�s�����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)NrBrergrCrdrOrDrP��)r�rg)
rrrMrRrt�AttributeError�setattrr:r;�assertNotEqual�rrQrrr�
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�@@)rir?ril�{�C	r?rcrw�$@)���rgg�)ll+?�Rr?�J��-�Drj)rxl g������	@g��(cannot convert Infinity to integer ratio�#cannot convert NaN to integer ratio)
rtrrrrMrRr
rbr~r})rZbigintr{rzrrr�
testFromFloat�sF�����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�rir?rz-0rhz0.5i�z5e-3i�Z5e3l�7�3M�e'z 0.999999999999999999999999999999r�r{r|r�rzr�)	rtrrZfrom_decimalrMrrbr~r}r*rrr�testFromDecimalsB�����zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr�r�)rgre���)rfrei����rrc)rMr�as_integer_ratior*rrr�test_as_integer_ratio2sz"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|�q�dS)Nz3.1415926535897932i'rprqi�����piM�j��r��dr?�e�fr)rrAz$max_denominator should be at least 1)rrMZlimit_denominatorrbr})rZrpi�irrr�testLimitDenominator8s�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)NrAi����rir?rkrfrmrr������FTrergryA�22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222227gUUUUUU�?A�33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331��������?)rWr3�truncr�floor�ceil�int�roundrM�boolr
rtr~�assertAlmostEqual�complexr*rrr�testConversionsFs$�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>.CustomValuer?cSs
||_dSr)rr
rrrreszFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__init__cSs
t|j�Sr)r�rr*rrr�__bool__hszFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__bool__cSs|Srrr*rrrrOkszGFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.numeratorcSstd��dS)Nz&Avoid comparisons in Fraction.__bool__r(rrrrrpszDFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__eq__N)
r-r.r/rPrr��propertyrOrr#rrrr�CustomValueas
r�r?TrF)	�	functools�total_orderingrr�registerrZassertIsrOr�)rr�rOrQrrr�testBoolGuarateesBoolReturn^sz(FractionTest.testBoolGuarateesBoolReturncCs�|�td�ttd�d��|�td�ttd�d��|�td�ttd�d��|�tdd�ttd	d
�d��|�tdd�ttdd
�d��dS)
Ni8���ij���rfi�����rArir�r�r?i��)rWrr�r*rrr�	testRound�s
zFractionTest.testRoundcCs�|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�tdd�tdd�tdd��|�dtdd�tdd��|�d	td	d�td��|�tdd
�tdd�tdd��|�tdd�td
d�tdd��|�td�tdd
�fttdd�tdd���|�td�tdd�fttd
d�tdd���|�tdd�tdd�td��|�tdd�tdd�td��|�dtd�tdd��|�tdd�tdd�
�ttd�tdd��}|�|jd�|�|jd�tdd�d}|�|tdd��|�|jd�|�|j	d�tdd�d}|�|tdd��|�|jd�|�|j	d�tdd�d}|�|tdd��|�|jd�|�|j	d�dS)Nr?rgrirhr��r�rnrjr�rBrer�rf���@rAr)
rMrrW�divmod�powr��real�imagrOrP)r�z�prrr�testArithmetic�s:"""""",,  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�ri�#r?lP��~�cegrBlrgr�rerhl��_�r�rC)rWrrZr�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)"Nrkrir?g�������?g�?y�������?y�?rlg�������y�������rng�������?y�������?ryr�r�y$@r�rjl�d�&O�!g"@g�������?r{r|rAg��������r�rfrgr�r�g�?)
rWrr
rZr�r�r�r�rMr�rtrsr)rr�rrr�testMixedArithmetic�sz" &&&&
�z FractionTest.testMixedArithmeticcCs<|�ttjtdd�td��|�ttjtd�tdd��dS)Nrerkz	3.1415926)rtrr�addrrr*rrr�testMixingWithDecimals
�
�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)Nr?rgre)�
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)Nr?rgrer�rB)r�rr2r�r*rrr�testComparisonsDummyRational"s8z)FractionTest.testComparisonsDummyRationalcCs�td�}tdd�}|�||k�|�||kp2||k�|�||k�|�||koV||k�|�||k�|�||kpz||k�|�||k�|�||ko�||k�dS)NgUUUUUU�?r?re)rrr�r�)r�x�yrrr�testComparisonsDummyFloatBs
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)Nrgrhr�rer?�333333�?皙�����?��?r{r|rrirzr�rB�rD�����r�rr�r
r*rrr�
testMixedLessNszFractionTest.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�r?rgr�r�r�rerhr{r|rrirzr�rBr�rDr�r�r�r*rrr�testMixedLessEqual`szFractionTest.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)Nrjr�r?)r�rr
r3r�r�r*rrr�testBigFloatComparisonsqs z$FractionTest.testBigFloatComparisonscCs�|�td�td�k�|�ttjtd�td��|�ttjtd�td��tdd�}tdd�}tdd�}|�||k�|�||k�|�||k�|�||k�tj	tjtjtj
fD]D}|�t|||�|�t|||�|�t|||�|�t|||�q�dS)Nrjrer�g�?r�g�������?)r�rr�rtrrr&r r�r"r$)rr�r��wrrrr�testBigComplexComparisons{s


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�r?rgr�r�r�rerhrzrBr{r|r�r*rrr�testMixedEqual�szFractionTest.testMixedEqualcCsp|�dttdd���|�dttd���|�dttdd���|�d	ttdd���|�d
ttdd���dS)NzFraction(7, 3)rBrez Fraction(6283185307, 2000000000)z3.1415926535z#Fraction(-1, 100000000000000000000)r?l���� F�x:^Vz7/3�7)rM�reprrr[r*rrr�testStringification�s
��z FractionTest.testStringificationcCs�tjj}tjj}|�td�ttdd���|�tdd�ttdd���|�ttd��ttd���|�|ttd|���|�ttd��td��	��dS)	Nrvrhrgri�2rjr?rA)
�sys�	hash_info�modulusr{rM�hashrr�r
�__hash__)rZhmodZhinfrrr�testHash�s zFractionTest.testHashc	Cs�td�}d|dddddf\}}}}}}}t||�tdd�kr||}|||d}}|||d}}|||}||7}q(|�tj|�dS)Nrerr?��ʚ;r�� )r�absr�r3�pi)	rZthree�lasts�t�s�nZna�d�darrr�testApproximatePi�s 
zFractionTest.testApproximatePicCs�td�}ddtd�dddf\}}}}}}t||�tdd�kr�|}|d7}|||d9}|||9}|d9}||||7}q(|�t�d�|�dS)Nr?rr�rgrA)rr�r�r3�cos)rr�r�r�r�Zfactr5�signrrr�testApproximateCos1�s z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)Nr�rB)
rr=rMrr�idrrr�rW)rrQZdrrrr�test_copy_deepcopy_pickle�s

z&FractionTest.test_copy_deepcopy_picklecCs tdd�}|�tt|dd�dS)Nr�rB�ari)rrtr�r�r�rrr�
test_slots�s
zFractionTest.test_slotsN)%r-r.r/rWrZrbrurrr�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�rrrrrSrsD



5$ "E 
	
rS�__main__)r0ZdecimalrZtest.supportrr3rrr8r�r�ZunittestrJrr�picklerrr9rr4�objectrr2r=ZTestCaser>rRrSr-�mainrrrr�<module>s4  l

F1le Man4ger