Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_fractions.cpython-39.pyc

a

��g]v�@s�dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZm
Z
ddlmZmZejZGdd�de�ZGd	d
�d
e�ZGdd�dej�Zd
d�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�//usr/local/lib/python3.9/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Jd��dS)NFz/__float__ should not be invoked for comparisonsr�rrrr�	__float__(szDummyFloat.__float__cCsdsJd��dS)NFz-__sub__ should not be invoked for comparisonsrrrrr�__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�grrrr4s
zDummyRational.__init__cCs,t|tj�r$|j|jko"|j|jkStSdSr)r	�	fractions�Fractionr3�
_numeratorr4�_denominatorrrrrrr9s

�zDummyRational.__eq__cCs|j|j|j|jkSr�r3r9r4r8rrrrr#@szDummyRational.__lt__cCs|j|j|j|jkSrr:rrrrr'CszDummyRational.__gt__cCs|j|j|j|jkSrr:rrrrr!FszDummyRational.__le__cCs|j|j|j|jkSrr:rrrrr%IszDummyRational.__ge__cCsdsJd��dS)NFz__float__ should not be invokedrr(rrrr)NszDummyRational.__float__N)r+r,r-r.rrr#r'r!r%r)rrrrr01sr0c@seZdZdZdS)�
DummyFractionz6Dummy Fraction subclass for copy and deepcopy testing.N)r+r,r-r.rrrrr;Qsr;cCs|j|jfSr)�	numerator�denominator)�rrrr�_componentsUsr?c@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�maprBrCrrr�assertTypedTupleEquals`sz#FractionTest.assertTypedTupleEqualsc
Os\z||i|��Wn4|yF}z|�|t|��WYd}~nd}~00|�d|j�dS)z@Asserts that callable(*args, **kwargs) raises exc_type(message).Nz
%s not raised)rA�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�)�rRrS�rS�rU)���rRrVrR)rRrR���)rR���
)rS�r[)�m+?�RrRr\)rU�M�)���rYrX����	)i�	i�	��c�qzFraction(12, 0)�ry�?@�3/2yy�?)rAr?rrP�ZeroDivisionError�assertRaisesrr(rrr�testInitos("�zFractionTest.testInitcCsv|�dttd���|�dttd���|�dttd���|�tttd��|�tttd��|�tttd	��dS)
N)rYrX�@rQ��)��L�33fl皙�����?�nan�inf�-inf)rAr?rrh�
ValueErrorr
�
OverflowErrorr(rrr�testInitFromFloat�s
�zFractionTest.testInitFromFloatcCs�|�dtttd����|�dtttd����|�dtttd����|�tttd��|�tttd��|�tttd	��|�tttd
��dS)N)r^rZz1.1)rS��z3.5e-2rQz.000e20rn�snanrorp)rAr?rrrhrqrrr(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)rYrR�5)rUrXrfz 
  +3/2)���rXz-3/2  )�
rXz    013/02 
  )�rYz 3.2 )i�rYz -3.2 )rxrRz -3. )rUrYz .6 )rRi5z32.e-5)i@BrRz1E+06)i���rRz-1.23e4rQz .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: '.'�.)rAr?rrPrgrqr(rrr�testFromString�sl����������zFractionTest.testFromStringcCs�tdd�}|�dd�|�dt|��|�tt|dd�|�tt|dd	�|�dt|��d
|_d|_|�dt|��|�	td
d�|�dS)NrSrUrXr[rTr<rer=��)r~rX)
rrrAr?rh�AttributeError�setattrr8r9�assertNotEqual�rr>rrr�
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�@@)rZrRrZl�{�C	rRrQrk�$@)���rXg�)ll+?�RrR�J��-�Dr\)rll g������	@g��(cannot convert Infinity to integer ratio�#cannot convert NaN to integer ratio)
rhrrrrAr?r
rPrrrq)rZbigintrornrrr�
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�rZrRrz-0rYz0.5i�z5e-3i�Z5e3l�7�3M�e'z 0.999999999999999999999999999999r�rorpr�rnru)	rhrrZfrom_decimalrArrPrrrqr(rrr�testFromDecimals2�
�
�
�
�zFractionTest.testFromDecimalcCs\|�tdd���d�|�tdd���d�|�tdd���d�|�tdd���d�dS)	Nr~r})rXrU���)rWrUi����rrQ)rAr�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|�q�dS)Nz3.1415926535897932i'rcrdi�����piM�j��rt�drR�e�fr)rrVz$max_denominator should be at least 1)rrAZlimit_denominatorrPrq)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)NrVi����rZrRr^rWr`rr������FTrUrXrmA�22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222227gUUUUUU�?A�33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331��������?)rEr1�truncr�floor�ceil�int�roundrA�boolr
rhrr�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>.CustomValuerRcSs
||_dSr)rr
rrrrLszFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__init__cSs
t|j�Sr)r�rr(rrr�__bool__OszFFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__bool__cSs|Srrr(rrrr<RszGFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.numeratorcSstd��dS)Nz&Avoid comparisons in Fraction.__bool__)�AssertionErrorrrrrrWszDFractionTest.testBoolGuarateesBoolReturn.<locals>.CustomValue.__eq__N)
r+r,r-r=rr��propertyr<rr#rrrr�CustomValueHs
r�rRTrF)	�	functools�total_orderingrr�registerrZassertIsr<r�)rr�r<r>rrr�testBoolGuarateesBoolReturnEsz(FractionTest.testBoolGuarateesBoolReturncCs�|�td�ttd�d��|�td�ttd�d��|�td�ttd�d��|�tdd�ttd	d
�d��|�tdd�ttdd
�d��dS)
Ni8���ij���rWi�����rVrZr�r�rRi��)rErr�r(rrr�	testRoundis
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)NrRrXrZrYrx�r~rar\r}rSrUr�rW���@rVr)
rArrE�divmod�powr��real�imagr<r=)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�rZ�#rRlP��~�cegrSlrXr�rUrYl��_�rtr[)rErrHr�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)"Nr^rZrRg�������?g�?y�������?y�?r_g�������y�������rag�������?y�������?rmr�r�y$@r�r\l�d�&O�!g"@g�������?rorprVg��������r�rWrXr~r�g�?)
rErr
rHr�r�r�r�rAr�rhrgr)rr�rrr�testMixedArithmetic�sx" &&&&

�z FractionTest.testMixedArithmeticcCs<|�ttjtdd�td��|�ttjtd�tdd��dS)NrUr^z	3.1415926)rhrr�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)NrRrXrU)�
assertTruer�assertFalser(rrr�testComparisons�szFractionTest.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)NrRrXrUr~rS)r�rr0r�r(rrr�testComparisonsDummyRational	s8z)FractionTest.testComparisonsDummyRationalcCs�td�}tdd�}|�||k�|�||kp2||k�|�||k�|�||koV||k�|�||k�|�||kpz||k�|�||k�|�||ko�||k�dS)NgUUUUUU�?rRrU)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)NrXrYr~rUrR�333333�?皙�����?��?rorprrZrnrxrS�re�����r�rr�r
r(rrr�
testMixedLess5szFractionTest.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�rRrXr�r�r~rUrYrorprrZrnrxrSr�rer�r�r�r(rrr�testMixedLessEqualGszFractionTest.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�rR)r�rr
r1r�r�r(rrr�testBigFloatComparisonsXs 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)Nr\rUr�g�?r�g�������?)r�rr�rhrrr&r r�r"r$)rr�r��wrrrr�testBigComplexComparisonsbs


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�rRrXr�r�r~rUrYrnrSrorpr�r(rrr�testMixedEqualtszFractionTest.testMixedEqualcCsp|�dttdd���|�dttd���|�dttdd���|�d	ttdd���|�d
ttdd���dS)NzFraction(7, 3)rSrUz Fraction(6283185307, 2000000000)z3.1415926535z#Fraction(-1, 100000000000000000000)rRl���� F�x:^Vz7/3�7)rA�reprrrIr(rrr�testStringification�s
��z FractionTest.testStringificationcCs�tjj}tjj}|�td�ttdd���|�tdd�ttdd���|�ttd��ttd���|�|ttd|���|�ttd��td��	��dS)	NrjrYrXrZ�2r\rRrV)
�sys�	hash_info�modulusrorA�hashrr�r
�__hash__)rZhmodZhinfrrr�testHash�s zFractionTest.testHashc	Cs�td�}d|dddddf\}}}}}}}t||�tdd�kr||}|||d}}|||d}}|||}||7}q(|�tj|�dS)NrUrrR��ʚ;r�� )r�absr�r1�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)NrRrr�rXrV)rr�r�r1�cos)rr�r�r�r�Zfactr3�signrrr�testApproximateCos1�s z FractionTest.testApproximateCos1cCs�tdd�}tdd�}|�|tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�t|�tt|���|�	|t|��|�	|t|��dS)NryrS)
rr;rArr�idrrr�rE)rr>Zdrrrr�test_copy_deepcopy_pickle�s

z&FractionTest.test_copy_deepcopy_picklecCs tdd�}|�tt|dd�dS)NryrS�arZ)rrhrr�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�rBr�rrrr�__mul__�sz5FractionTest.test_int_subclass.<locals>.myint.__mul__cSst|�t|�t|��Srr�rrrr�__floordiv__�sz: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)NrR)rBr(rrrr=�sz9FractionTest.test_int_subclass.<locals>.myint.denominatorN)	r+r,r-r�r�r�r�r<r=rrrr�myint�s
r�rUr}rRrX)r�r6r7rAr<r=rB)rr��frrr�test_int_subclass�szFractionTest.test_int_subclassN)&r+r,r-rErHrPrirrsrvr|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�rrrrr@YsF



5$ "E 
	
r@�__main__)r.ZdecimalrZtest.supportrr1rrr6r�r�Zunittestrr�picklerrr7r�objectrr0r;r?ZTestCaser@r+�mainrrrr�<module>s0  

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists