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.opt-2.pyc
U

>��gWw�@s�ddlmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZm
Z
ddlmZmZejZejZGdd�de�ZGdd	�d	e�ZGd
d�dej�ZGdd
�d
e
j�Zdd�ZGdd�de
j�Zedkr�e
��dS)�)�Decimal)�requires_IEEE_754N)�copy�deepcopy)�dumps�loadsc@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZeZdS)�
DummyFloatcCst|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__cCsdSrr�rrrr�	__float__)szDummyFloat.__float__cCsdSrrrrrr�__sub__-szDummyFloat.__sub__N)
�__name__�
__module__�__qualname__rrrr!r#r%r'r)r*�__rsub__rrrrrsrc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�
DummyRationalcCs$t�||�}|||_|||_dSr)�math�gcd�num�den)rr2r3�grrrr5s
zDummyRational.__init__cCs,t|tj�r$|j|jko"|j|jkStSdSr)r	�	fractions�Fractionr2�
_numeratorr3�_denominatorrrrrrr:s

�zDummyRational.__eq__cCs|j|j|j|jkSr�r2r8r3r7rrrrr#AszDummyRational.__lt__cCs|j|j|j|jkSrr9rrrrr'DszDummyRational.__gt__cCs|j|j|j|jkSrr9rrrrr!GszDummyRational.__le__cCs|j|j|j|jkSrr9rrrrr%JszDummyRational.__ge__cCsdSrrr(rrrr)OszDummyRational.__float__N)
r+r,r-rrr#r'r!r%r)rrrrr/2sr/c@seZdZdS)�
DummyFractionN)r+r,r-rrrrr: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�DeprecationWarningr1�warnings�catch_warnings�filterwarnings�assertEqualrr(rrr�testMiscWs(�zGcdTest.testMiscN)r+r,r-rKrrrrr;Usr;cCs|j|jfSr)�	numerator�denominator)�rrrr�_componentsnsrOc@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|��|�||�dSr)rJ�type�rZexpected�actualrrr�assertTypedEqualstszFractionTest.assertTypedEqualscCs0|�||�|�ttt|��ttt|���dSr)ZassertTupleEqualZassertListEqual�list�maprQrRrrr�assertTypedTupleEqualsysz#FractionTest.assertTypedTupleEqualsc
OsVz|||�Wn2|k
r@}z|�|t|��W5d}~XYnX|�d|j�dS)Nz
%s not raised)rJ�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<)r?r<r?�r?�rb)r>r<r>r<)r<r<���)r<���
)r?r@r@)�m+?�Rr<rg)rbrD�)���rerd����	)i�	i�	��c�qzFraction(12, 0)rAry�?@�3/2yy�?)rJrOrr_�ZeroDivisionError�assertRaisesrr(rrr�testInit�s,"�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)rerd�@r`��)��L�33fl皙�����?�nan�inf�-inf)rJrOrrq�
ValueErrorr
�
OverflowErrorr(rrr�testInitFromFloat�s
�zFractionTest.testInitFromFloatcCs�|�dtttd����|�dtttd����|�dtttd����|�tttd��|�tttd��|�tttd	��|�tttd
��dS)N)rhrfz1.1)r?��z3.5e-2r`z.000e20rw�snanrxry)rJrOrrrqrzr{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)rer<�5)rbrdroz 
  +3/2)���rdz-3/2  )�
rdz    013/02 
  )�rez 3.2 )i�rez -3.2 )r�r<z -3. )rbrez .6 )r<i5z32.e-5)i@Br<z1E+06)i���r<z-1.23e4r`z .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: '.'�.)rJrOrr_rprzr(rrr�testFromString�s�����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)Nr?rbrdr@rarLrArM��)r�rd)
rrrJrOrq�AttributeError�setattrr7r8�assertNotEqual�rrNrrr�
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�@@)rfr<rfl�{�C	r<r`rt�$@)���rdg�)ll+?�Rr<�J��-�Drg)rul g������	@g��(cannot convert Infinity to integer ratio�#cannot convert NaN to integer ratio)
rqrrrrJrOr
r_r{rz)rZbigintrxrwrrr�
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�rfr<rz-0rez0.5i�z5e-3i�Z5e3l�7�3M�e'z 0.999999999999999999999999999999r�rxryr�rwr~)	rqrrZfrom_decimalrJrr_r{rzr(rrr�testFromDecimalsB�����zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr�r�)rdrb���)rcrbi����rr`)rJr�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'rmrni�����piM�j��r}�dr<�e�fr)rr>z$max_denominator should be at least 1)rrJZlimit_denominatorr_rz)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)Nr>i����rfr<rhrcrjrr������FTrbrdrvA�22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222227gUUUUUU�?A�33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331��������?)rTr0�truncr�floor�ceil�int�roundrJ�boolr
rqr{�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(rrrrLkszGFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.numeratorcSstd��dS)Nz&Avoid comparisons in Fraction.__bool__)�AssertionErrorrrrrrpszDFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__eq__N)
r+r,r-rMrr��propertyrLrr#rrrr�CustomValueas
r�r<TrF)	�	functools�total_orderingrr�registerrZassertIsrLr�)rr�rLrNrrr�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���rci�����r>rfr�r�r<i��)rTrr�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<rdrfrer��r�rkrgr�r?rbr�rc���@r>r)
rJrrT�divmod�powr��real�imagrLrM)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�rf�#r<lP��~�cegr?lrdr�rbrel��_�r}r@)rTrrWr�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)"Nrhrfr<g�������?g�?y�������?y�?rig�������y�������rkg�������?y�������?rvr�r�y$@r�rgl�d�&O�!g"@g�������?rxryr>g��������r�rcrdr�r�g�?)
rTrr
rWr�r�r�r�rJr�rqrpr)rr�rrr�testMixedArithmetic�sz" &&&&
�z FractionTest.testMixedArithmeticcCs<|�ttjtdd�td��|�ttjtd�tdd��dS)Nrbrhz	3.1415926)rqrr�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<rdrb)�
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<rdrbr�r?)r�rr/r�r(rrr�testComparisonsDummyRational"s8z)FractionTest.testComparisonsDummyRationalcCs�td�}tdd�}|�||k�|�||kp2||k�|�||k�|�||koV||k�|�||k�|�||kpz||k�|�||k�|�||ko�||k�dS)NgUUUUUU�?r<rb)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)Nrdrer�rbr<�333333�?皙�����?��?rxryrrfrwr�r?�rA�����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<rdr�r�r�rbrerxryrrfrwr�r?r�rAr�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)Nrgr�r<)r�rr
r0r�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)Nrgrbr�g�?r�g�������?)r�rr�rqrrr&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<rdr�r�r�rbrerwr?rxryr�r(rrr�testMixedEqual�szFractionTest.testMixedEqualcCsp|�dttdd���|�dttd���|�dttdd���|�d	ttdd���|�d
ttdd���dS)NzFraction(7, 3)r?rbz Fraction(6283185307, 2000000000)z3.1415926535z#Fraction(-1, 100000000000000000000)r<l���� F�x:^Vz7/3�7)rJ�reprrrXr(rrr�testStringification�s
��z FractionTest.testStringificationcCs�tjj}tjj}|�td�ttdd���|�tdd�ttdd���|�ttd��ttd���|�|ttd|���|�ttd��td��	��dS)	Nrsrerdrf�2rgr<r>)
�sys�	hash_info�modulusrxrJ�hashrr�r
�__hash__)rZhmodZhinfrrr�testHash�s zFractionTest.testHashc	Cs�td�}d|dddddf\}}}}}}}t||�tdd�kr||}|||d}}|||d}}|||}||7}q(|�tj|�dS)Nrbrr<��ʚ;r�� )r�absr�r0�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�rdr>)rr�r�r0�cos)rr�r�r�r�Zfactr2�signrrr�testApproximateCos1�s z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)Nr�r?)
rr:rJrr�idrrr�rT)rrNZdrrrr�test_copy_deepcopy_pickle�s

z&FractionTest.test_copy_deepcopy_picklecCs tdd�}|�tt|dd�dS)Nr�r?�arf)rrqr�r�r�rrr�
test_slots�s
zFractionTest.test_slotsN)%r+r,r-rTrWr_rrrr|rr�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�rrrrrPrsD



5$ "E 
	
rP�__main__)ZdecimalrZtest.supportrr0rrr5r�r�ZunittestrGrr�picklerrr6rr1�objectrr/r:ZTestCaser;rOrPr+�mainrrrr�<module>s2  l

F1le Man4ger