Your IP : 216.73.216.85


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_fractions.cpython-38.opt-1.pyc

U

i�fWw�@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�8/opt/alt/python38/lib64/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__�__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)rr3r4�grrrr5s
zDummyRational.__init__cCs,t|tj�r$|j|jko"|j|jkStSdSr)r	�	fractions�Fractionr3�
_numeratorr4�_denominatorrrrrrr:s

�zDummyRational.__eq__cCs|j|j|j|jkSr�r3r9r4r8rrrrr#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__cCsdSrrr(rrrr)OszDummyRational.__float__N)r+r,r-r.rrr#r'r!r%r)rrrrr02sr0c@seZdZdZdS)�
DummyFractionz6Dummy Fraction subclass for copy and deepcopy testing.N)r+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�DeprecationWarningr2�warnings�catch_warnings�filterwarnings�assertEqualrr(rrr�testMiscWs(�zGcdTest.testMiscN)r+r,r-rLrrrrr<Usr<cCs|j|jfSr)�	numerator�denominator)�rrrr�_componentsnsrPc@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)rK�type�rZexpectedZactualrrr�assertTypedEqualstszFractionTest.assertTypedEqualscCs0|�||�|�ttt|��ttt|���dS)zBAsserts that both the types and values in the tuples are the same.N)ZassertTupleEqualZassertListEqual�list�maprRrSrrr�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)rK�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@rArA)�m+?�Rr=rg)rbrE�)���rerd����	)i�	i�	��c�qzFraction(12, 0)rBry�?@�3/2yy�?)rKrPrr_�ZeroDivisionError�assertRaisesrr(rrr�testInit�s,"�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)rerd�@r`��)��L�33fl皙�����?�nan�inf�-inf)rKrPrrq�
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)rKrPrrrqrzr{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: '.'�.)rKrPrr_rprzr(rrr�testFromString�s�����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)Nr@rbrdrArarMrBrN��)r�rd)
rrrKrPrq�AttributeError�setattrr8r9�assertNotEqual�rrOrrr�
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)
rqrrrrKrPr
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_decimalrKrr_r{rzr(rrr�testFromDecimalsB�����zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr�r�)rdrb���)rcrbi����rr`)rKr�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)rrKZlimit_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��������?)rTr1�truncrZfloorZceil�int�roundrK�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(rrrrMkszGFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.numeratorcSstd��dS)Nz&Avoid comparisons in Fraction.__bool__)�AssertionErrorrrrrrpszDFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__eq__N)
r+r,r-rNrr��propertyrMrr#rrrr�CustomValueas
r�r=TrF)	�	functools�total_orderingrr�registerrZassertIsrMr�)rr�rMrOrrr�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)
rKrrT�divmod�powr��real�imagrMrN)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}rA)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�rKr�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�rr0r�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@�rB�����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�rBr�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
r1r�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)rK�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�modulusrxrK�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�r1Zpi)	rZthree�lasts�t�s�nZna�dZdarrr�testApproximatePi�s 
zFractionTest.testApproximatePicCs�td�}ddtd�dddf\}}}}}}t||�tdd�kr�|}|d7}|||d9}|||9}|d9}||||7}q(|�t�d�|�dS)Nr=rr�rdr?)rr�r�r1Zcos)rr�r�r�r�Zfactr3Zsignrrr�testApproximateCos1�s z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)Nr�r@)
rr;rKrr�idrrr�rT)rrOZdrrrr�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�rrrrrQrsD



5$ "E 
	
rQ�__main__)r.�decimalrZtest.supportrr1rrr6r�r�ZunittestrHrr�picklerrr7rr2�objectrr0r;ZTestCaser<rPrQr+�mainrrrr�<module>s4  l