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: //proc/self/root/usr/local/lib/python3.7/test/__pycache__/test_statistics.cpython-37.opt-1.pyc
B

��gc)�@sTdZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlZdd�Z
dd�Zd	d
�Zd`d
d�ZGdd�d�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd �d ej�ZGd!d"�d"ej�ZGd#d$�d$ej�ZGd%d&�d&ej�ZGd'd(�d(ej�ZGd)d*�d*ej�ZGd+d,�d,ej�Z Gd-d.�d.ej�Z!Gd/d0�d0ej�Z"Gd1d2�d2ej�Z#Gd3d4�d4ej�Z$Gd5d6�d6�Z%Gd7d8�d8�Z&Gd9d:�d:e%e&�Z'Gd;d<�d<e�Z(Gd=d>�d>e�Z)Gd?d@�d@e�Z*GdAdB�dBe%�Z+GdCdD�dDee+e&�Z,GdEdF�dFee+e&�Z-GdGdH�dHee+�Z.GdIdJ�dJee&�Z/GdKdL�dLe.e&�Z0GdMdN�dNe.e&�Z1GdOdP�dPe.�Z2GdQdR�dRee+e&�Z3GdSdT�dTe%�Z4GdUdV�dVe4ee&�Z5GdWdX�dXe4ee&�Z6GdYdZ�dZe4e�Z7Gd[d\�d\e4e�Z8d]d^�Z9e:d_k�rPe�;�dS)az_Test suite for statistics module, including helper NumericTestCase and
approx_equal function.

�N)�Decimal)�FractioncCst�d|�S)z:Return -1.0 for negatives, including -0.0, otherwise +1.0.�)�math�copysign)�x�r�0/usr/local/lib/python3.7/test/test_statistics.py�signsr
cCsZt|�t|�k	rdSt|t�r2t�|�o0t�|�S|��d}|��d}||koX|dkS)a�Return True if a and b are both the same kind of NAN.

    >>> _nan_equal(Decimal('NAN'), Decimal('NAN'))
    True
    >>> _nan_equal(Decimal('sNAN'), Decimal('sNAN'))
    True
    >>> _nan_equal(Decimal('NAN'), Decimal('sNAN'))
    False
    >>> _nan_equal(Decimal(42), Decimal('NAN'))
    False

    >>> _nan_equal(float('NAN'), float('NAN'))
    True
    >>> _nan_equal(float('NAN'), 0.5)
    False

    >>> _nan_equal(float('NAN'), Decimal('NAN'))
    False

    NAN payloads are not compared.
    F�)�n�N)�type�
isinstance�floatr�isnanZas_tuple)�a�bZaexpZbexprrr	�
_nan_equals
rcCs:tt|�t|��}t||�}|r*||ntd�}||fS)z�Return the absolute and relative errors between two numbers.

    >>> _calc_errors(100, 75)
    (25, 0.25)
    >>> _calc_errors(100, 100)
    (0, 0.0)

    Returns the (absolute error, relative error) between the two arguments.
    �inf)�max�absr)�actual�expected�base�abs_err�rel_errrrr	�_calc_errors<s
r��-���q=�H�����z>cCs�|dks|dkrtd��t�|�s,t�|�r0dS||kr<dSt�|�sPt�|�rTdSt||�}t||tt|�t|���}||kS)a�approx_equal(x, y [, tol [, rel]]) => True|False

    Return True if numbers x and y are approximately equal, to within some
    margin of error, otherwise return False. Numbers which compare equal
    will also compare approximately equal.

    x is approximately equal to y if the difference between them is less than
    an absolute error tol or a relative error rel, whichever is bigger.

    If given, both tol and rel must be finite, non-negative numbers. If not
    given, default values are tol=1e-12 and rel=1e-7.

    >>> approx_equal(1.2589, 1.2587, tol=0.0003, rel=0)
    True
    >>> approx_equal(1.2589, 1.2587, tol=0.0001, rel=0)
    False

    Absolute error is defined as abs(x-y); if that is less than or equal to
    tol, x and y are considered approximately equal.

    Relative error is defined as abs((x-y)/x) or abs((x-y)/y), whichever is
    smaller, provided x or y are not zero. If that figure is less than or
    equal to rel, x and y are considered approximately equal.

    Complex numbers are not directly supported. If you wish to compare to
    complex numbers, extract their real and imaginary parts and compare them
    individually.

    NANs always compare unequal, even with themselves. Infinities compare
    approximately equal if they have the same sign (both positive or both
    negative). Infinities with different signs compare unequal; so do
    comparisons of infinities with finite numbers.
    rz%error tolerances must be non-negativeFT)�
ValueErrorrr�isinfrr)r�y�tol�relZactual_errorZ
allowed_errorrrr	�approx_equalLs"r%c@seZdZdZdS)�
_DoNothinga�
    When doing numeric work, especially with floats, exact equality is often
    not what you want. Due to round-off error, it is often a bad idea to try
    to compare floats with equality. Instead the usual procedure is to test
    them with some (hopefully small!) allowance for error.

    The ``approx_equal`` function allows you to specify either an absolute
    error tolerance, or a relative error, or both.

    Absolute error tolerances are simple, but you need to know the magnitude
    of the quantities being compared:

    >>> approx_equal(12.345, 12.346, tol=1e-3)
    True
    >>> approx_equal(12.345e6, 12.346e6, tol=1e-3)  # tol is too small.
    False

    Relative errors are more suitable when the values you are comparing can
    vary in magnitude:

    >>> approx_equal(12.345, 12.346, rel=1e-4)
    True
    >>> approx_equal(12.345e6, 12.346e6, rel=1e-4)
    True

    but a naive implementation of relative error testing can run into trouble
    around zero.

    If you supply both an absolute tolerance and a relative error, the
    comparison succeeds if either individual test succeeds:

    >>> approx_equal(12.345e6, 12.346e6, tol=1e-3, rel=1e-4)
    True

    N)�__name__�
__module__�__qualname__�__doc__rrrr	r&�s#r&c@s@eZdZdZdZZddd�Zdd�Zd
dd	�Ze	d
d��Z
dS)�NumericTestCasez�Unit test class for numeric work.

    This subclasses TestCase. In addition to the standard method
    ``TestCase.assertAlmostEqual``,  ``assertApproxEqual`` is provided.
    rNcCsZ|dkr|j}|dkr|j}t|tjj�r@t|tjj�r@|j}n|j}||||||�dS)a�Test passes if ``first`` and ``second`` are approximately equal.

        This test passes if ``first`` and ``second`` are equal to
        within ``tol``, an absolute error, or ``rel``, a relative error.

        If either ``tol`` or ``rel`` are None or not given, they default to
        test attributes of the same name (by default, 0).

        The objects may be either numbers, or sequences of numbers. Sequences
        are tested element-by-element.

        >>> class MyTest(NumericTestCase):
        ...     def test_number(self):
        ...         x = 1.0/6
        ...         y = sum([x]*6)
        ...         self.assertApproxEqual(y, 1.0, tol=1e-15)
        ...     def test_sequence(self):
        ...         a = [1.001, 1.001e-10, 1.001e10]
        ...         b = [1.0, 1e-10, 1e10]
        ...         self.assertApproxEqual(a, b, rel=1e-3)
        ...
        >>> import unittest
        >>> from io import StringIO  # Suppress test runner output.
        >>> suite = unittest.TestLoader().loadTestsFromTestCase(MyTest)
        >>> unittest.TextTestRunner(stream=StringIO()).run(suite)
        <unittest.runner.TextTestResult run=2 errors=0 failures=0>

        N)r#r$r�collections�abc�Sequence�_check_approx_seq�_check_approx_num)�self�first�secondr#r$�msg�checkrrr	�assertApproxEqual�sz!NumericTestCase.assertApproxEqualc
	Csrt|�t|�kr:dt|�t|�f}|�||�}|�|��x2tt||��D] \}\}}	|�||	||||�qJWdS)Nz0sequences differ in length: %d items != %d items)�len�_formatMessage�failureException�	enumerate�zipr0)
r1r2r3r#r$r4�standardMsg�ir�errr	r/�s
z!NumericTestCase._check_approx_seqcCs>t||||�rdS|�|||||�}|�||�}|�|��dS)N)r%�_make_std_err_msgr8r9)r1r2r3r#r$r4�idxr<rrr	r0�s
z!NumericTestCase._check_approx_numc	Cs>d}|dk	rd|}||}t||�\}}|||||||fS)Nzk  %r != %r
  values differ by more than tol=%r and rel=%r
  -> absolute error = %r
  -> relative error = %rz,numeric sequences first differ at index %d.
)r)	r2r3r#r$r@�template�headerrrrrr	r?�sz!NumericTestCase._make_std_err_msg)NNN)N)r'r(r)r*r#r$r6r/r0�staticmethodr?rrrr	r+�s
+
	r+c@seZdZdZdd�ZdS)�TestSignz5Test that the helper function sign() works correctly.cCs$|�td�d�|�td�d�dS)Ngrg����)�assertEqualr
)r1rrr	�
testZeroesszTestSign.testZeroesN)r'r(r)r*rGrrrr	rDsrDc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApproxEqualSymmetryTestcCsXdddtd�tdd�g}ddd	td
�tdd�g}x"t||�D]\}}|�||�q<WdS)Ni�	gfffff�B@gfffff�(�z2.54��6i�	g������B@gR����(�z2.59�)rrr;�do_relative_symmetry)r1Zargs1Zargs2rrrrr	�test_relative_symmetrys
z.ApproxEqualSymmetryTest.test_relative_symmetrycCstt||�t||�}}||}t||�t||�}}||d}|�t||d|d��|�t||d|d��dS)Nrr)r#r$)�minrr�
assertTruer%)r1rr�deltaZrel_err1Zrel_err2r$rrr	rL-sz,ApproxEqualSymmetryTest.do_relative_symmetrycCsdddddg}d}x�|D]�}x�ttttfD]�}||�d}||}t|t||��}|j||||d�|j|||d	d|d�|j|||d	|dd�|j||||dd�|j|||d	|d�|j|||d	d|d�|j||d
d
d�|j||d
d
d�q*WqWdS)Ni�������ki�mr�d)r#r$rr)�intrrrrr�do_symmetry_test)r1�argsrPr�type_rr"�rrrr	�
test_symmetry9s
z%ApproxEqualSymmetryTest.test_symmetryc
Cs@d}t||||�}t||||�}|�|||�||||f��dS)Nz+approx_equal comparisons don't match for %r)r%rF�format)r1rrr#r$rAZflag1Zflag2rrr	rVQsz(ApproxEqualSymmetryTest.do_symmetry_testN)r'r(r)rMrLrZrVrrrr	rHsrHc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ApproxEqualExactTestcCsJt||||d�}|�|d|�t||||d�}|�|d|�dS)N)r#r$zequality failure for x=%r)r%rO)r1rr#r$�resultrrr	�do_exactly_equal_test^sz*ApproxEqualExactTest.do_exactly_equal_testcCs xdD]}|�|dd�qWdS)N)�*iMi~:��iiU�
i�r)r^)r1rrrr	�test_exactly_equal_intsds
z,ApproxEqualExactTest.test_exactly_equal_intscCs xdD]}|�|dd�qWdS)N)g�z�G��?g/�$���?g�����e�@g7@gpf@g!�rh��Q@gB`��"KB@r)r^)r1rrrr	�test_exactly_equal_floatsis
z.ApproxEqualExactTest.test_exactly_equal_floatscCsRt}xH|dd�|d�|dd�|dd�|dd	�|dd�gD]}|�|dd�q8WdS)
NrrrrR��	��#�$)rr^)r1�F�frrr	�test_exactly_equal_fractionsns8z1ApproxEqualExactTest.test_exactly_equal_fractionscCs.t}x$t|d���D]}|�|dd�qWdS)Nz8.2 31.274 912.04 16.745 1.2047r)r�map�splitr^)r1�D�drrr	�test_exactly_equal_decimalstsz0ApproxEqualExactTest.test_exactly_equal_decimalscCsJxDdD]<}|�|dd�|�|ddd�t|d�}|�|dd�qWdS)N)�i�i\i�i��g{�G�z�?r�
i�)r^r)r1rrirrr	�test_exactly_equal_absolutezs


z0ApproxEqualExactTest.test_exactly_equal_absolutecCs2|�td�td�d�|�td�td�d�dS)Nz3.571z0.01rz81.3971)r^r)r1rrr	�$test_exactly_equal_absolute_decimals�sz9ApproxEqualExactTest.test_exactly_equal_absolute_decimalscCsDx(dddtdd�gD]}|�|dd�qW|�td�dtd	��dS)
Ni� g33333SY@g�z�G�rR�rg{�G�z�?z11.68z0.01)rr^r)r1rrrr	�test_exactly_equal_relative�sz0ApproxEqualExactTest.test_exactly_equal_relativecCsLx(dddtdd�gD]}|�|dd�qWt}|�|d�|d	�|d
��dS)Ni9�gˡE��0@g\��(h��rc�g�������?g{�G�z�?z7.2z0.1z0.01)rr^r)r1rrmrrr	�test_exactly_equal_both�sz,ApproxEqualExactTest.test_exactly_equal_bothN)r'r(r)r^rarbrjrorsrtrvrxrrrr	r\Xsr\c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ApproxEqualUnequalTestcCs<x6||fD](}t||dddd�}|�|d|�qWdS)Nrr)r#r$zinequality failure for x=%r)r%�assertFalse)r1rrr]rrr	�do_exactly_unequal_test�sz.ApproxEqualUnequalTest.do_exactly_unequal_testcCsxdD]}|�|�qWdS)N)i�i��i�i�iXC)r{)r1rrrr	�test_exactly_unequal_ints�s
z0ApproxEqualUnequalTest.test_exactly_unequal_intscCsxdD]}|�|�qWdS)N)g��Q�#@g����[�@gfffff�G@gףp=
W"@g=
ףp=1@)r{)r1rrrr	�test_exactly_unequal_floats�s
z2ApproxEqualUnequalTest.test_exactly_unequal_floatscCs@t}x6|dd�|dd�|dd�|dd�gD]}|�|�q*WdS)	NrrRrerd���eiς)rr{)r1rhrirrr	�test_exactly_unequal_fractions�s*z5ApproxEqualUnequalTest.test_exactly_unequal_fractionscCs&x ttd���D]}|�|�qWdS)Nz!3.1415 298.12 3.47 18.996 0.00245)rkrrlr{)r1rnrrr	�test_exactly_unequal_decimals�sz4ApproxEqualUnequalTest.test_exactly_unequal_decimalsN)r'r(r)r{r|r}r�r�rrrr	ry�s
ryc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�ApproxEqualInexactTestc	Csfd}x\||||fD]H}|�||�}|�t||d|dd�|�|�t|||ddd�|�qWdS)NzTest failure for x={!r}, y={!r}rr)r#r$)r[rOr%rz)r1rrPrAr"r4rrr	�do_approx_equal_abs_test�s
z/ApproxEqualInexactTest.do_approx_equal_abs_testcCs*x$dD]}|�|d�|�|d�qWdS)N)i��iI���i����rQrrrd�%i�i�&i6�jrrr)r�)r1rrrr	�test_approx_equal_absolute_ints�s
z6ApproxEqualInexactTest.test_approx_equal_absolute_intscCs6x0dD](}|�|d�|�|d�|�|d�qWdS)N)	g�t��q�gfffffFX�g333333�g333333�g�?g�?g333333@g�Q���@g�����ҭ@g�?g{�G�z�?g-C��6?)r�)r1rrrr	�!test_approx_equal_absolute_floats�s
z8ApproxEqualInexactTest.test_approx_equal_absolute_floatscCs\tdd�}dddddddd	d
ddg}x2d
d�|D�D] }|�||�|�|t|��q4WdS)Nr�i����i�rQrErrRrI��"�Gcss|]}t|d�VqdS)r�N)r)�.0rrrr	�	<genexpr>�szNApproxEqualInexactTest.test_approx_equal_absolute_fractions.<locals>.<genexpr>)rr�r)r1rP�
numeratorsrirrr	�$test_approx_equal_absolute_fractions�s

z;ApproxEqualInexactTest.test_approx_equal_absolute_fractionscCs>td�}x0ttd���D]}|�||�|�||�qWdS)Nz0.01z1.0 3.5 36.08 61.79 7912.3648)rrkrlr�)r1rPrnrrr	�#test_approx_equal_absolute_decimals�sz:ApproxEqualInexactTest.test_approx_equal_absolute_decimalscCs|�tddddd��dS)Ng�h㈵��>g�h㈵��g-C��6?r)r#r$)rOr%)r1rrr	�test_cross_zero�sz&ApproxEqualInexactTest.test_cross_zeroc	Csnd}xd|d||d|fD]H}|�||�}|�t||dd|d�|�|�t||d|dd�|�qWdS)NzTest failure for x={!r}, y={!r}rrr)r#r$)r[rOr%rz)r1rrPrAr"r4rrr	�do_approx_equal_rel_test�s
z/ApproxEqualInexactTest.do_approx_equal_rel_testcCsr|�tddddd��|�tddddd��|�tdddd	d��|�td
ddd	d��|�tdddd	d��dS)N�@�/rg
ףp=
�?)r#r$g�G�z��?i�ig�?i�i�)rOr%rz)r1rrr	�test_approx_equal_relative_ints�s
z6ApproxEqualInexactTest.test_approx_equal_relative_intscCs*x$dD]}|�|d�|�|d�qWdS)N)g{�G�Jf�g��������g�������?g�?g\��(|B@g��ʡE>�@g��x��@g{�G�z�?g-C��6?)r�)r1rrrr	�!test_approx_equal_relative_floats�s
z8ApproxEqualInexactTest.test_approx_equal_relative_floatscCspt}tdd�}x\|dd�|dd�|dd�|dd	�gD]4}x.|t|�fD]}|�||�|�||�qFWq4WdS)
Nrcrw�TrI��1�2�\�U)rrr�)r1rhrPrirnrrr	�$test_approx_equal_relative_fractions�s
*z;ApproxEqualInexactTest.test_approx_equal_relative_fractionscCs>x8ttd���D]&}|�|td��|�|td��qWdS)Nz$0.02 1.0 5.7 13.67 94.138 91027.9321z0.001z0.05)rkrrlr�)r1rnrrr	�#test_approx_equal_relative_decimalssz:ApproxEqualInexactTest.test_approx_equal_relative_decimalscCst|r
|jn|j}|t|||dd��|r.|jn|j}|t||d|d��|sP|rV|jn|j}|t||||d��dS)Nr)r#r$)rOrzr%)r1rrr#r$Ztol_flagZrel_flagr5rrr	�
do_check_bothsz$ApproxEqualInexactTest.do_check_bothcCs,|�dddddd�|�dddd	dd�dS)
NgR����@g+���@g����Mbp?g���W�8?Tg?5^�I��g%��C��g����Mb`?g-C��6*?)r�)r1rrr	�test_approx_equal_both1sz.ApproxEqualInexactTest.test_approx_equal_both1cCs|�dddddd�dS)NgR����@g+���@g����Mbp?gV�F�?8?TF)r�)r1rrr	�test_approx_equal_both2 sz.ApproxEqualInexactTest.test_approx_equal_both2cCs|�dddddd�dS)NgR����@g+���@g����MbP?g���W�8?FT)r�)r1rrr	�test_approx_equal_both3$sz.ApproxEqualInexactTest.test_approx_equal_both3cCs,|�dddddd�|�dddd	dd�dS)
Ng=
ףp=@g@g{�G�z�?g����MbP?Fg�Q��[�@g�(\��[�@g{�G�z�?giUMu�>)r�)r1rrr	�test_approx_equal_both4(sz.ApproxEqualInexactTest.test_approx_equal_both4N)r'r(r)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	r��s 		r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApproxEqualSpecialsTestcCs�x�ttfD]z}|d�}|�t||��|�t||dd��|�t||dd��|�t||��|�t||��|�t|d��q
WdS)Nrrrg{�G�z�?i�)rrrOr%rz)r1rXrrrr	�test_inf1sz ApproxEqualSpecialsTest.test_infcCsFx@ttfD]4}|d�}x&||d�dfD]}|�t||��q&Wq
WdS)N�nanri�)rrrzr%)r1rXr��otherrrr	�test_nan;sz ApproxEqualSpecialsTest.test_nancCs&t�dd�}|�t|dddd��dS)NgrEg�������?)r#r$)rrrOr%)r1�nzerorrr	�test_float_zeroesAsz)ApproxEqualSpecialsTest.test_float_zeroescCs&td�}|�t|td�ddd��dS)Nz-0.0rg�������?)r#r$)rrOr%)r1r�rrr	�test_decimal_zeroesEsz+ApproxEqualSpecialsTest.test_decimal_zeroesN)r'r(r)r�r�r�r�rrrr	r�.s
r�c@seZdZdd�Zdd�ZdS)�TestApproxEqualErrorscCs|�ttdddd�dS)NrTrEg�������?)�assertRaisesr r%)r1rrr	�test_bad_tolMsz"TestApproxEqualErrors.test_bad_tolcCs|�ttdddd�dS)NrTrg��������)r�r r%)r1rrr	�test_bad_relQsz"TestApproxEqualErrors.test_bad_relN)r'r(r)r�r�rrrr	r�Jsr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestNumericTestCasecCs2tj|�}|j|�}x|D]}|�||�qWdS)N)r+r?�generate_substringsZassertIn)r1rWZ
actual_msgrZ	substringrrr	�do_testas


zTestNumericTestCase.do_testcCs|�tttj��dS)N)rO�
issubclassr+�unittest�TestCase)r1rrr	� test_numerictestcase_is_testcasegsz4TestNumericTestCase.test_numerictestcase_is_testcasecCsd}|�|�dS)N)g@g@g�?g�?N)r�)r1rWrrr	�test_error_msg_numericksz*TestNumericTestCase.test_error_msg_numericcCsd}|�|�dS)N)g@g� @g�?g�?re)r�)r1rWrrr	�test_error_msg_sequencepsz+TestNumericTestCase.test_error_msg_sequencec	CsDt||�\}}d|d|d|d|g}|dk	r@|�d|�|S)z5Return substrings we expect to see in error messages.ztol=%rzrel=%rzabsolute error = %rzrelative error = %rNzdiffer at index %d)r�append)	r1r2r3r#r$r@rrZ
substringsrrr	r�us
z'TestNumericTestCase.generate_substringsN)r'r(r)r�r�r�r�r�rrrr	r�[s
r�c@s(eZdZeZddgZdd�Zdd�ZdS)�GlobalsTestr*�__all__cCs,x&|jD]}|�t|j|�d|�qWdS)Nz%s not present)�expected_metadatarO�hasattr�module)r1�metarrr	�	test_meta�szGlobalsTest.test_metacCsF|j}x:|jD]0}|�|�d�d|�|�t||�d|�qWdS)N�_zprivate name "%s" in __all__zmissing name "%s" in __all__)r�r�rz�
startswithrOr�)r1r��namerrr	�test_check_all�s
zGlobalsTest.test_check_allN)r'r(r)�
statisticsr�r�r�r�rrrr	r��sr�c@s(eZdZe�ejjdkd�dd��ZdS)�DocTestsrz)Docstrings are omitted with -OO and abovecCs0tjttjd�\}}|�|d�|�|d�dS)N)Zoptionflagsr)�doctestZtestmodr��ELLIPSIS�
assertGreaterrF)r1ZfailedZtriedrrr	�test_doc_tests�szDocTests.test_doc_testsN)	r'r(r)r�ZskipIf�sys�flags�optimizer�rrrr	r��sr�c@seZdZdd�ZdS)�StatisticsErrorTestcCs4d}|�ttd��|�ttjt�|tjj�dS)NzNExpected StatisticsError to be a ValueError, but got a subclass of %r instead.�StatisticsError)rOr�r�r�r�r �__base__)r1�errmsgrrr	�test_has_exception�s

z&StatisticsErrorTest.test_has_exceptionN)r'r(r)r�rrrr	r��sr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ExactRatioTestcCs(x"dD]}|�t�|�|df�qWdS)N)i�����rrR�cl F�x:^Vr)rFr��_exact_ratio)r1r=rrr	�test_int�s
zExactRatioTest.test_intcCs6d}x,|D]$}t|d�}|�t�|�|df�q
WdS)N)���rr~�&r�)rrFr�r�)r1r�rrirrr	�
test_fraction�s

zExactRatioTest.test_fractioncCsf|�t�d�d�|�t�d�d�dd�td�D�}x*|D]"}t�|�\}}|�|||�q<WdS)Ng�?)rrwg�?)rdrwcSsg|]}t�dd��qS)i����rT)�random�uniform)r�r�rrr	�
<listcomp>�sz-ExactRatioTest.test_float.<locals>.<listcomp>rT)rFr�r��range)r1�datar�num�denrrr	�
test_float�s
zExactRatioTest.test_floatcCsJt}tj}|�||d��d�|�||d��d�|�||d��d�dS)Nz0.125)rrwz12.345)i�	��z-1.98)i����r�)rr�r�rF)r1rmr�rrr	�test_decimal�s
zExactRatioTest.test_decimalcCs�td�}Gdd�dt�}Gdd�dt�}xr||fD]d}x^t|t|fD]N}||�}t�|�}|�||df�|�t|d�|�|�t�|d��qFWq4WdS)N�INFc@seZdZdS)z(ExactRatioTest.test_inf.<locals>.MyFloatN)r'r(r)rrrr	�MyFloat�sr�c@seZdZdS)z*ExactRatioTest.test_inf.<locals>.MyDecimalN)r'r(r)rrrr	�	MyDecimal�sr�r)	rrr�r�rFrrOrr!)r1r�r�r�rrXr�ratiorrr	r��s
zExactRatioTest.test_infcCsxtd�}Gdd�dt�}xZ|||�fD]J}t�|�}|�t�|d��|�|dd�|�t|d�t|��q&WdS)N�NANc@seZdZdS)z.ExactRatioTest.test_float_nan.<locals>.MyFloatN)r'r(r)rrrr	r��sr�rr)	rr�r�rOrr�assertIsrFr)r1r�r�r�r�rrr	�test_float_nan�s
zExactRatioTest.test_float_nancCs�td�}td�}Gdd�dt�}xb|||�|||�fD]J}t�|�}|�t|d|��|�|dd�|�t|d�t|��q6WdS)Nr��sNANc@seZdZdS)z2ExactRatioTest.test_decimal_nan.<locals>.MyDecimalN)r'r(r)rrrr	r��sr�rr)rr�r�rOrr�rFr)r1r�r�r�r�r�rrr	�test_decimal_nan�s
zExactRatioTest.test_decimal_nanN)
r'r(r)r�r�r�r�r�r�r�rrrr	r��s
r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�DecimalToRatioTestcCs<td�}|�t�|�|df�|�t�|�|df�dS)Nr�)rrFr�r�)r1rrrr	�
test_infinity�sz DecimalToRatioTest.test_infinitycCsHxBtd�td�fD].}t�|�\}}|�t||��|�|d�qWdS)Nr�r�)rr�r�rOrr�)r1r�r�r�rrr	r��szDecimalToRatioTest.test_nancCsptd�td�g}xZ|D]R}t�|�\}}|�|d�|�|d�t�|�\}}|�|d�|�|d�qWdS)Nz	9.8765e12z
9.8765e-12r)rr�r��assertGreaterEqualr�ZassertLessEqual)r1Znumbersrnr�r�rrr	�	test_signs
zDecimalToRatioTest.test_signcCst�td��}|�|d�dS)Nz0.1234)iii�)r�r�rrF)r1�trrr	�test_negative_exponentsz)DecimalToRatioTest.test_negative_exponentcCst�td��}|�|d�dS)Nz1.234e7)i K�r)r�r�rrF)r1r�rrr	�test_positive_exponentsz)DecimalToRatioTest.test_positive_exponentcCs8t�td��}|�|d�t�td��}|�|d�dS)NZ1e2)rTrz1.47e5)i8>r)r�r�rrF)r1r�rrr	�test_regression_20536 sz(DecimalToRatioTest.test_regression_20536N)	r'r(r)r�r�r�r�r�r�rrrr	r��s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�IsFiniteTestcCs4x.dtdd�dtd�fD]}|�t�|��qWdS)NrRrrcg@z5.5)rrrOr��	_isfinite)r1rrrr	�test_finite,szIsFiniteTest.test_finitecCs.x(td�td�fD]}|�t�|��qWdS)Nr)rrrzr�r�)r1rrrr	r�1szIsFiniteTest.test_infinitycCs4x.td�td�td�fD]}|�t�|��qWdS)Nr�r�r�)rrrzr�r�)r1rrrr	r�6szIsFiniteTest.test_nanN)r'r(r)r�r�r�rrrr	r�)sr�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
CoerceTestcCsRxLttttfD]<}|�t�|t�|�Gdd�d|�}|�t�|t�|�qWdS)Nc@seZdZdS)z%CoerceTest.test_bool.<locals>.MyClassN)r'r(r)rrrr	�MyClassWsr�)rUrrrr�r��_coerce�bool)r1�Tr�rrr	�	test_boolQszCoerceTest.test_boolcCs,|�t�||�|�|�t�||�|�dS)z Assert that type A coerces to B.N)r�r�r�)r1�A�Brrr	�assertCoerceToZszCoerceTest.assertCoerceTocCsT|�||�Gdd�d|�}|�||�Gdd�d|�}|�||�|�||�dS)z6Checks that type A coerces to B, including subclasses.c@seZdZdS)z/CoerceTest.check_coerce_to.<locals>.SubclassOfAN)r'r(r)rrrr	�SubclassOfAdsrc@seZdZdS)z/CoerceTest.check_coerce_to.<locals>.SubclassOfBN)r'r(r)rrrr	�SubclassOfBgsrN)r)r1r�rrrrrr	�check_coerce_to_szCoerceTest.check_coerce_tocCs,|�ttj||f�|�ttj||f�dS)z=Assert that coercing A to B, or vice versa, raises TypeError.N)r��	TypeErrorr�r�)r1r�rrrr	�assertCoerceRaiseskszCoerceTest.assertCoerceRaisescCs�|�t�||�|�Gdd�d|�}Gdd�d|�}Gdd�d|�}x|||fD]}|�||�qPW|�||�|�||�|�||�dS)z>Check that type T coerces correctly with subclasses of itself.c@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.UN)r'r(r)rrrr	�Uvsrc@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.VN)r'r(r)rrrr	�Vwsrc@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.WN)r'r(r)rrrr	�Wxsr	N)r�r�r�rr)r1r�rrr	�typrrr	�check_type_coercionspszCoerceTest.check_type_coercionscCs.|�t�xtttfD]}|�t|�qWdS)N)rrUrrrr)r1r
rrr	r��s
zCoerceTest.test_intcCs|�t�|�tt�dS)N)rrrr)r1rrr	r��s
zCoerceTest.test_fractioncCs|�t�dS)N)rr)r1rrr	r��szCoerceTest.test_decimalcCs|�t�dS)N)rr)r1rrr	r��szCoerceTest.test_floatcCsBx<tttd�ttfD]&}x ttttfD]}|�	||�q&WqWdS)N)
�str�listr�tuple�dictrUrrrr)r1Zbad_typeZ	good_typerrr	�test_non_numeric_types�sz!CoerceTest.test_non_numeric_typescCs>x8ttfD],}Gdd�d|�}|�|t�|�|t�q
WdS)Nc@seZdZdS)z6CoerceTest.test_incompatible_types.<locals>.MySubclassN)r'r(r)rrrr	�
MySubclass�sr)rrrr)r1r�rrrr	�test_incompatible_types�sz"CoerceTest.test_incompatible_typesN)r'r(r)r�rrrrr�r�r�r�rrrrrr	r�<s	r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ConvertTestcCs$|�||�|�t|�t|��dS)z5Check that x equals y, and has the same type as well.N)rFr�r)r1rr"rrr	�check_exact_equal�szConvertTest.check_exact_equalcCsPt�td�t�}|�|d�Gdd�dt�}t�td�|�}|�||d��dS)Nr�c@seZdZdS)z#ConvertTest.test_int.<locals>.MyIntN)r'r(r)rrrr	�MyInt�srrI)r��_convertrrUr)r1rrrrr	r��s
zConvertTest.test_intcCs\t�tdd�t�}|�|tdd��Gdd�dt�}t�tdd�|�}|�||dd��dS)N�_r�cseZdZ�fdd�Z�ZS)z-ConvertTest.test_fraction.<locals>.MyFractioncs|�t��|��S)N)�	__class__�super�__truediv__)r1r�)rrr	r�sz9ConvertTest.test_fraction.<locals>.MyFraction.__truediv__)r'r(r)r�
__classcell__rr)rr	�
MyFraction�srr��
)r�rrr)r1rrrrr	r��s
zConvertTest.test_fractioncCsTt�tdd�t�}|�|d�Gdd�dt�}t�tdd�|�}|�||d��dS)	NrErg�cseZdZ�fdd�Z�ZS)z'ConvertTest.test_float.<locals>.MyFloatcs|�t��|��S)N)rrr)r1r�)rrr	r�sz3ConvertTest.test_float.<locals>.MyFloat.__truediv__)r'r(r)rrrr)rr	r��sr�rdrwg�?)r�rrrr)r1rr�rrr	r��s
zConvertTest.test_floatcCsXt�tdd�t�}|�|td��Gdd�dt�}t�tdd�|�}|�||d��dS)	Nr�(z0.025cseZdZ�fdd�Z�ZS)z+ConvertTest.test_decimal.<locals>.MyDecimalcs|�t��|��S)N)rrr)r1r�)rrr	r�sz7ConvertTest.test_decimal.<locals>.MyDecimal.__truediv__)r'r(r)rrrr)rr	r��sr�i�rpz-0.9375)r�rrrr)r1rr�rrr	r��s
zConvertTest.test_decimalcCsNxHtd�td�fD]4}x.||fD] }t�|t|��}|�||�q"WqWdS)Nr)rrr�rrr)r1r�rrrrr	r��szConvertTest.test_infcCsDx>td�td�td�fD]$}t�|t|��}|�t||��qWdS)Nr�r�r�)rrr�rrrOr)r1r�rrrr	r��szConvertTest.test_nanN)
r'r(r)rr�r�r�r�r�r�rrrr	r�s


rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�FailNegTestz Test _fail_neg private function.cCs2ddtd�td�g}tt�|��}|�||�dS)Nrg@rcrq)rrr
r��	_fail_negrF)r1�values�newrrr	�test_pass_through�szFailNegTest.test_pass_throughcCsDx>ddtd�td�gD]&}|g}t�|�}|�tjt|�qWdS)Nrg@rcrq)rrr�r r�r��next)r1r�seq�itrrr	�test_negatives_raise�s
z FailNegTest.test_negatives_raisec
Cspdt�dd�}ytt�dg|��Wn.tjk
rT}z|jd}Wdd}~XYnX|�d�|�||�dS)Nzbadness #%di'i��rErz(expected exception, but it didn't happen)	r�Zrandintr$r�r r�rWZfailrF)r1r4r>r�rrr	�test_error_msg�s
zFailNegTest.test_error_msgN)r'r(r)r*r#r'r(rrrr	r�src@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�UnivariateCommonMixincCs|�t|j�dS)N)r�r�func)r1rrr	�test_no_args�sz"UnivariateCommonMixin.test_no_argscCs.x(gdtg�fD]}|�tj|j|�qWdS)Nr)�iterr�r�r�r*)r1�emptyrrr	�test_empty_data�sz%UnivariateCommonMixin.test_empty_datacCs,ttd��}x|t|�kr&t�|�qW|S)z"Return int data for various tests.rr)r
r��sortedr��shuffle)r1r�rrr	�prepare_datasz"UnivariateCommonMixin.prepare_datacCs0|��}|dd�}|�|�}|�||d�dS)Nzdata has been modified)r1r*ZassertListEqual)r1r�Zsavedr�rrr	�test_no_inplace_modificationss
z3UnivariateCommonMixin.test_no_inplace_modificationscCsFddddddddgd}|�|�}t�|�|�|�}|�||�dS)NrrrcrqrR�rT)r*r�r0rF)r1r�rrrrr	�test_order_doesnt_matters



z.UnivariateCommonMixin.test_order_doesnt_mattercCsrGdd�dt�}Gdd�dt�}dd�}|��}|�|�}x2ttt|||fD]}|�||��}|�||�qLWdS)Nc@seZdZdS)zBUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyListN)r'r(r)rrrr	�MyList$sr5c@seZdZdS)zCUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyTupleN)r'r(r)rrrr	�MyTuple&sr6cSsdd�|D�S)Ncss|]
}|VqdS)Nr)r��objrrr	r�)szXUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator.<locals>.<genexpr>r)r�rrr	�	generator(szEUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator)r
rr1r*r,rF)r1r5r6r8r�r�kindr]rrr	�test_type_of_data_collection"s
z2UnivariateCommonMixin.test_type_of_data_collectioncCs0tddd�}|�t|��}|�|�|�|�dS)N�r�rc)r�r*r
rF)r1r�rrrr	�test_range_data0sz%UnivariateCommonMixin.test_range_datacCs.|�d�|�d�|�d�|�t��dS)Nr�gE@)�check_for_type_error�object)r1rrr	�test_bad_arg_types6s



z(UnivariateCommonMixin.test_bad_arg_typescGs|jt|jf|��dS)N)r�rr*)r1rWrrr	r=Esz*UnivariateCommonMixin.check_for_type_errorcslGdd�dt�}|��}|�|�}xDt|ttfD]4��fdd�|D�}t|�|�|��}|�||�q0WdS)Ncs,eZdZ�fdd�Z�fdd�ZeZ�ZS)z@UnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloatcst|�t��|��S)N)rrr)r1r�)rrr	rMszLUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__truediv__cst|�t��|��S)N)rr�__add__)r1r�)rrr	r@OszHUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__add__)r'r(r)rr@�__radd__rrr)rr	r�Lsr�csg|]}�|��qSrr)r�r)r9rr	r�VszCUnivariateCommonMixin.test_type_of_data_element.<locals>.<listcomp>)rr1r*rrrrF)r1r��rawrr�r]r)r9r	�test_type_of_data_elementHs
z/UnivariateCommonMixin.test_type_of_data_elementN)
r'r(r)r+r.r1r2r4r:r<r?r=rCrrrr	r)�s

r)c@s eZdZdZdd�Zdd�ZdS)�UnivariateTypeMixinamMixin class for type-conserving functions.

    This mixin class holds test(s) for functions which conserve the type of
    individual data points. E.g. the mean of a list of Fractions should itself
    be a Fraction.

    Not all tests to do with types need go in this class. Only those that
    rely on the function returning the same type as its input data.
    cCsGdd�dt�}ttt|fS)z4Return the types which are expected to be conserved.cs\eZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Z�fd	d
�Z�fdd�ZeZ	�Z
S)
zHUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloatcst|�t��|��S)N)rrr)r1r�)rrr	rhszTUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__truediv__cst|�t��|��S)N)rr�__rtruediv__)r1r�)rrr	rEjszUUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rtruediv__cst|�t��|��S)N)rr�__sub__)r1r�)rrr	rFlszPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__sub__cst|�t��|��S)N)rr�__rsub__)r1r�)rrr	rGnszQUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rsub__cst|�t��|��S)N)rr�__pow__)r1r�)rrr	rHpszPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__pow__cst|�t��|��S)N)rrr@)r1r�)rrr	r@rszPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__add__)r'r(r)rrErFrGrHr@rArrr)rr	r�gsr�)rrr)r1r�rrr	�#prepare_types_for_conservation_testesz7UnivariateTypeMixin.prepare_types_for_conservation_testcsJ|��}x<|��D]0��fdd�|D�}|�|�}|�t|���qWdS)Ncsg|]}�|��qSrr)r�r)r9rr	r�}sz<UnivariateTypeMixin.test_types_conserved.<locals>.<listcomp>)r1rIr*r�r)r1r�rnr]r)r9r	�test_types_conservedws

z(UnivariateTypeMixin.test_types_conservedN)r'r(r)r*rIrJrrrr	rD[s	rDc@seZdZdd�ZdS)�
TestSumCommoncCsdd�}||_dS)NcWstj|�\}}}t�||�S)N)r��_sumr�)rWr��valuerrrr	�simplified_sum�sz+TestSumCommon.setUp.<locals>.simplified_sum)r*)r1rNrrr	�setUp�szTestSumCommon.setUpN)r'r(r)rOrrrr	rK�srKc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestSumcCstj|_dS)N)r�rLr*)r1rrr	rO�sz
TestSum.setUpcCstxngdtg�fD]\}|�|�|�ttd�df�|�|�|d�ttd�df�|�|�|d�ttd�df�qWdS)Nrrr�gffffff@)r,rFr*rUrr)r1r�rrr	r.�szTestSum.test_empty_datacCsX|�|�ddddddddg�ttd�d	f�|�|�d
ddddgd
�ttd�df�dS)NrrRrc���i����r;r_�<rwrqrrei�i�)rFr*rUr)r1rrr	�	test_ints�szTestSum.test_intscCsL|�|�dgd�ttd�df�|�|�ddddgd�ttd�d	f�dS)
Ng�?r;g@g�?g�?g�?g�?g	@rq)rFr*rr)r1rrr	�test_floats�szTestSum.test_floatscCs.|�|�tdd�gd�ttdd�df�dS)Nri�i�r)rFr*r)r1rrr	�test_fractions�szTestSum.test_fractionsc	CsXt}|d�|d�|d�|d�|d�|d�|d�|d�g}|�|�|�ttd	�d
f�dS)Nz0.001z5.246z1.702z-0.025z3.974z2.328z4.617z2.843z20.686rw)rrFr*)r1rmr�rrr	�
test_decimals�s
zTestSum.test_decimalscCs:dd�td�D�}|jt|�|�d�t�|�dd�dS)NcSsg|]}t�dd��qS)i����i�)r�r�)r�r�rrr	r��sz7TestSum.test_compare_with_math_fsum.<locals>.<listcomp>i�rg��ؗ�Ҭ<)r$)r�r6rr*rZfsum)r1r�rrr	�test_compare_with_math_fsum�sz#TestSum.test_compare_with_math_fsumcCs|dd�td�D�}|�|�d}|�|d|�|d�d�|�|d|�|d�d�|�|td�|�|d�d�dS)	NcSsg|]}t�dd��qS)ri�)r�r�)r�r�rrr	r��sz/TestSum.test_start_argument.<locals>.<listcomp>rTrr_r�i��g@��x�D)r�r*rFr)r1r�r�rrr	�test_start_argument�s
zTestSum.test_start_argumentcCs4|�t|jdddgd�|�t|jddddg�dS)NrrrcZ999)r�rr*)r1rrr	�test_strings_fail�szTestSum.test_strings_failcCs4|�t|jdddgd�|�t|jddddg�dS)Nrrrcs999)r�rr*)r1rrr	�test_bytes_fail�szTestSum.test_bytes_failcCs8|�t|jddtd�g�|�t|jddgtd��dS)Nrg@)r�rr*r)r1rrr	�test_mixed_sum�szTestSum.test_mixed_sumN)r'r(r)rOr.rSrTrUrVrWrXrYrZr[rrrr	rP�srPc@seZdZdd�ZdS)�SumTortureTestcCs�|�t�ddddgd�ttd�df�|�t�ddddgd�ttd�df�t�ddddgd�\}}}|�|t�|�|d�|jt|�d	d
d�dS)Nrg}Ô%�I�Tg}Ô%�I��i'g��@i@�g0��.�++rEg���^�,gV瞯�<)r$)rFr�rLrrr�r6)r1r�r��countrrr	�test_torture�szSumTortureTest.test_tortureN)r'r(r)r^rrrr	r\�sr\c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�SumSpecialValuescCsRxLttfD]@}|d�}t�d|dg�d}|�t|�|�|�t�|��q
WdS)Nr�rr)	rrr�rLr�rrOrr)r1rXr�r]rrr	r��s
zSumSpecialValues.test_nancCs<|�t�|��|�t|�t|��|�|dk|dk�dS)z8Check x is an infinity of the same type and sign as inf.rN)rOrr!r�rrF)r1rrrrr	�check_infinity�szSumSpecialValues.check_infinitycCsLt�dd|dg�d}|�||�t�dd|d|dg�d}|�||�dS)Nrrrcrq)r�rLr`)r1rr]rrr	�do_test_inf�szSumSpecialValues.do_test_infcCs(td�}xdD]}|�||�qWdS)Nr)rrE)rra)r1rr
rrr	�test_float_inf�s
zSumSpecialValues.test_float_infcCs(td�}xdD]}|�||�qWdS)Nr)rrE)rra)r1rr
rrr	�test_decimal_infs
z!SumSpecialValues.test_decimal_infcCs8td�}t�dd|d|dg�d}|�t�|��dS)Nrrrrcrq)rr�rLrOrr)r1rr]rrr	�test_float_mismatched_infssz+SumSpecialValues.test_float_mismatched_infsc	CsPtd�}dd|d|dg}t�tj�� |�t�t�|�d��WdQRXdS)Nrrrrcrq)	r�decimal�localcontextZExtendedContextrOrrr�rL)r1rr�rrr	�3test_decimal_extendedcontext_mismatched_infs_to_nanszDSumSpecialValues.test_decimal_extendedcontext_mismatched_infs_to_nanc	CsHtd�}dd|d|dg}t�tj��|�tjtj|�WdQRXdS)Nrrrrcrq)rrerfZBasicContextr��InvalidOperationr�rL)r1rr�rrr	�0test_decimal_basiccontext_mismatched_infs_to_nanszASumSpecialValues.test_decimal_basiccontext_mismatched_infs_to_nancCs(td�}d|dg}|�tjtj|�dS)Nr�rr)rr�rerhr�rL)r1r�r�rrr	�test_decimal_snan_raisess
z)SumSpecialValues.test_decimal_snan_raisesN)r'r(r)r�r`rarbrcrdrgrirjrrrr	r_�sr_c@s$eZdZdd�Zdd�Zdd�ZdS)�AverageMixincCs:x4dddtdd�td�fD]}|�|�|g�|�qWdS)Nr�g@E@g�X_yCrK�z0.28)rrrFr*)r1rrrr	�test_single_value&szAverageMixin.test_single_valuecCsdddtdd�td�fS)Ng@rIg��7y�!C�=�Cz4.9712)rr)r1rrr	�'prepare_values_for_repeated_single_test+sz4AverageMixin.prepare_values_for_repeated_single_testcCsZxT|��D]H}xBdD]:}|j||d��"|g|}|�|�|�|�WdQRXqWq
WdS)N)rrRrrr;)rr])rp�subTestrFr*)r1rr]r�rrr	�test_repeated_single_value.s


z'AverageMixin.test_repeated_single_valueN)r'r(r)rmrprrrrrr	rk#srkc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�TestMeancCstj|_dS)N)r��meanr*)r1rrr	rO8szTestMean.setUpcCs|�|�ddddg�d�dS)Ng}Ô%�I�Trrcg}Ô%�I��)rFr*)r1rrr	�test_torture_pep;szTestMean.test_torture_pepcCsDddddddddddddddd	d
g}t�|�|�|�|�d�dS)NrrrrcrqrRr3rerwrdg@@)r�r0rFr*)r1r�rrr	rS?s$
zTestMean.test_intscCs4ddddddddg}t�|�|�|�|�d	�dS)
Ng@1@g�3@g4@g�5@g�5@g@7@g 9@g�;@g6@)r�r0rFr*)r1r�rrr	rTEs
zTestMean.test_floatscCsJt}|d�|d�|d�|d�|d�g}t�|�|�|�|�|d��dS)Nz1.634z2.517z3.912z4.072z5.813z3.5896)rr�r0rFr*)r1rmr�rrr	rVKs"
zTestMean.test_decimalsc	Csft}|dd�|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|d	d
��dS)NrrrcrqrRr3rerwi�i�)rr�r0rFr*)r1rhr�rrr	rURs<
zTestMean.test_fractionscCsndddddg}xZttfD]N}xHdD]@}|d�|}||g}|�|�}|�t�|��|�||�q"WqWdS)NrrcrRrerd)rrEr)rrr*rOrr!rF)r1rBr9r
rr�r]rrr	r�Ys


zTestMean.test_infc	Cs:dddtd�dddtd�g}|�|�}|�t�|��dS)	Nrrqr3rrrcrRz-inf)rr*rOrr)r1r�r]rrr	�test_mismatched_infsds
zTestMean.test_mismatched_infscCsPdddddg}x<ttfD]0}|d�}||g}|�|�}|�t�|��qWdS)NrrcrRrerdr�)rrr*rOrr)r1rBr9rr�r]rrr	r�js

zTestMean.test_nanc	sPd�dddddddd	d
g	}|�|��}|��fdd�|D��}|�||�dS)
Nge��Ag333333@g@g������@g������@g333333@g������@g @g333333 @g������"@csg|]}|��qSrr)r�r)�crr	r�ysz*TestMean.test_big_data.<locals>.<listcomp>)r*rF)r1r�rr]r)rwr	�
test_big_datass
zTestMean.test_big_datacCs:dd�td�D�}|�|�}|�|d�}|�||�dS)NcSsg|]}t�dd��qS)r�rR)r�r�)r�r�rrr	r�~sz.TestMean.test_doubled_data.<locals>.<listcomp>i�r)r�r*r6)r1r�rrrrr	�test_doubled_data|s
zTestMean.test_doubled_datacCs td�}|�t�|g�|�dS)NZ1e4)rrFr�rt)r1rnrrr	�test_regression_20561�szTestMean.test_regression_20561cCs`|�t�ddg�d�d}d}x<dD]4}|�t�|g|�|�|�t�|g|�|�q$WdS)Ng�������g�g)rrcrRr�)rFr�rt)r1ZbigZtinyrrrr	�test_regression_25177�s
zTestMean.test_regression_25177N)r'r(r)rOrurSrTrVrUr�rvr�rxryrzr{rrrr	rs7s		rscs�eZdZdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�TestHarmonicMeancCstj|_dS)N)r�Z
harmonic_meanr*)r1rrr	rO�szTestHarmonicMean.setUpcst���}|�d�|S)Nr)rr1�remove)r1r!)rrr	r1�s

zTestHarmonicMean.prepare_datacCsdddtdd�td�fS)Ng@rIg��7y�!Crnroz4.125)rr)r1rrr	rp�sz8TestHarmonicMean.prepare_values_for_repeated_single_testcCs dddg}|�|�|�d�dS)Nrrr)rFr*)r1r!rrr	�	test_zero�s
zTestHarmonicMean.test_zeroc
CsLtj}x@dgdddgfD],}|j|d��|�||j|�WdQRXqWdS)NrErrQrc)r!)r�r�rqr�r*)r1�excr!rrr	�test_negative_error�sz$TestHarmonicMean.test_negative_errorcCs0ddddddg}t�|�|�|�|�d�dS)Nrrqrwrpg333333@)r�r0rFr*)r1r�rrr	rS�s
zTestHarmonicMean.test_intscCsHdddddg}t�|�|�|�|�d�|�|�ddddg�d�dS)Ng�?g�?g�?g�?)r�r0rFr*)r1r�rrr	�test_floats_exact�s
z"TestHarmonicMean.test_floats_exactcCs,x&tdd�D]}|�|�|g�|�qWdS)Nrr�)r�rFr*)r1rrrr	�test_singleton_lists�sz%TestHarmonicMean.test_singleton_listsc	Cs�t}|�|�|d�|d�|d�|d�g�|d��|d�|d�|d�|d�g}t�|�|�|�|�|d��|d�|d�|d	�|d
�g}t�|�|�|�|�|d�d�dS)
NrKr�rRz0.05z0.10z0.20z1.68z0.32z5.94z2.75i�iC)rrFr*r�r0)r1rmr�rrr	�test_decimals_exact�s.

z$TestHarmonicMean.test_decimals_exactc	Csft}|dd�|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|d	d
��dS)NrrrcrqrRr3rerwi|i�)rr�r0rFr*)r1rhr�rrr	rU�s<
zTestHarmonicMean.test_fractionscCs$dtd�dg}|�|�|�d�dS)Ng@rg�?)rrFr*)r1r!rrr	r��szTestHarmonicMean.test_infcCs(dtd�dg}|�t�|�|���dS)Ng@r�g�?)rrOrrr*)r1r!rrr	r��szTestHarmonicMean.test_nanc	sPd�dddddddd	d
g	}|�|��}|��fdd�|D��}|�||�dS)
N�og333333@g@g������@g������@g333333@g������@g @g333333 @g������"@csg|]}|��qSrr)r�r)rwrr	r��sz>TestHarmonicMean.test_multiply_data_points.<locals>.<listcomp>)r*rF)r1r�rr]r)rwr	�test_multiply_data_points�s
z*TestHarmonicMean.test_multiply_data_pointscCs:dd�td�D�}|�|�}|�|d�}|�||�dS)NcSsg|]}t�dd��qS)rrR)r�r�)r�r�rrr	r��sz6TestHarmonicMean.test_doubled_data.<locals>.<listcomp>i�r)r�r*r6)r1r�rrrrr	ry�s
z"TestHarmonicMean.test_doubled_data)r'r(r)rOr1rpr~r�rSr�r�r�rUr�r�r�ryrrr)rr	r|�sr|csTeZdZdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�
TestMediancCstj|_dS)N)r��medianr*)r1rrr	rO�szTestMedian.setUpcs(t���}t|�ddkr$|�d�|S)z+Overload method from UnivariateCommonMixin.rr)rr1r7r�)r1r�)rrr	r1�s

zTestMedian.prepare_datacCs&ddddddg}|�|�|�d�dS)NrrrcrqrRr3g@)rFr*)r1r�rrr	�test_even_ints�szTestMedian.test_even_intscCs(dddddddg}|�|�|�d�dS)NrrrcrqrRr3rd)rFr*)r1r�rrr	�
test_odd_intsszTestMedian.test_odd_intscCsVt}|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|dd��dS)NrrerrcrqrR)rr�r0rFr*)r1rhr�rrr	�test_odd_fractionss,
zTestMedian.test_odd_fractionscCs^t}|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|dd��dS)NrrerrcrqrRr3)rr�r0rFr*)r1rhr�rrr	�test_even_fractionss4
zTestMedian.test_even_fractionscCsJt}|d�|d�|d�|d�|d�g}t�|�|�|�|�|d��dS)Nz2.5z3.1z4.2z5.7z5.8)rr�r0rFr*)r1rmr�rrr	�test_odd_decimalss"
zTestMedian.test_odd_decimalscCsPt}|d�|d�|d�|d�|d�|d�g}t�|�|�|�|�|d��dS)Nz1.2z2.5z3.1z4.2z5.7z5.8z3.65)rr�r0rFr*)r1rmr�rrr	�test_even_decimalss(
zTestMedian.test_even_decimals)r'r(r)rOr1r�r�r�r�r�r�rrr)rr	r��sr�c@seZdZdd�Zdd�ZdS)�TestMedianDataTypecCstj|_dS)N)r�r�r*)r1rrr	rO*szTestMedianDataType.setUpcCs,ttd��}x|t|�kr&t�|�qW|S)NrK)r
r�r/r�r0)r1r�rrr	r1-szTestMedianDataType.prepare_dataN)r'r(r)rOr1rrrr	r�(sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestMedianLowcCstj|_dS)N)r�Z
median_lowr*)r1rrr	rO6szTestMedianLow.setUpcCs&ddddddg}|�|�|�d�dS)NrrrcrqrRr3)rFr*)r1r�rrr	r�9szTestMedianLow.test_even_intscCs^t}|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|dd��dS)NrrerrcrqrRr3)rr�r0rFr*)r1rhr�rrr	r�?s4
z!TestMedianLow.test_even_fractionscCsPt}|d�|d�|d�|d�|d�|d�g}t�|�|�|�|�|d��dS)Nz1.1z2.2z3.3z4.4z5.5z6.6)rr�r0rFr*)r1rmr�rrr	r�Gs(
z TestMedianLow.test_even_decimalsN)r'r(r)rOr�r�r�rrrr	r�5sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestMedianHighcCstj|_dS)N)r�Zmedian_highr*)r1rrr	rOQszTestMedianHigh.setUpcCs&ddddddg}|�|�|�d�dS)NrrrcrqrRr3)rFr*)r1r�rrr	r�TszTestMedianHigh.test_even_intscCs^t}|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�|dd��dS)NrrerrcrqrRr3)rr�r0rFr*)r1rhr�rrr	r�Zs4
z"TestMedianHigh.test_even_fractionscCsPt}|d�|d�|d�|d�|d�|d�g}t�|�|�|�|�|d��dS)Nz1.1z2.2z3.3z4.4z5.5z6.6)rr�r0rFr*)r1rmr�rrr	r�bs(
z!TestMedianHigh.test_even_decimalsN)r'r(r)rOr�r�r�rrrr	r�Psr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestMedianGroupedcCstj|_dS)N)r�Zmedian_groupedr*)r1rrr	rOnszTestMedianGrouped.setUpcCs�dddddddg}|�|�|�d�dddddddg}|�|�|�d�ddddddddd	d	d
g}|�|�|d�d�dd
d
d
d
ddddddddddg}|j|�|d�ddd�dS)Nr~r�rKg�+@rRrrr;�r�g`3@rp�����rg������4@g:�0�yE>)r#)rFr*r6)r1r�rrr	�test_odd_number_repeatedqs"z*TestMedianGrouped.test_odd_number_repeatedcCs�ddddddddddg
}|j|�|d�ddd	�d
dddddg}|j|�|�d
dd	�d
dddddddddddg}|�|�|�d�ddddddddddg
}|�|�|�d�dS)NrRrrrKr;r�r�g�����*3@g:�0�yE>)r#rrcrqg["8���@r3g@g@)r6r*rF)r1r�rrr	�test_even_number_repeated�sz+TestMedianGrouped.test_even_number_repeatedcCsTxNdddtdd�td�fD]2}x,dD]$}|g|}|�|�|�t|��q$WqWdS)Ng333333@�Dg��ޗCr�r�z32.9714)rrRrrr;)rrrFr*r)r1rr]r�rrr	rr�s

z,TestMedianGrouped.test_repeated_single_valuecCsPt}|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�d�dS)NrRrqrdrrIg@)rr�r0rFr*)r1rhr�rrr	r��s,
z$TestMedianGrouped.test_odd_fractionscCsXt}|dd�|dd�|dd�|dd�|dd�|dd�g}t�|�|�|�|�d�dS)NrRrqrdrrIg
@)rr�r0rFr*)r1rhr�rrr	r��s4
z%TestMedianGrouped.test_even_fractionscCsFt}|d�|d�|d�|d�|d�g}t�|�|�|�|�d�dS)Nz5.5z6.5z7.5z8.5g@)rr�r0rFr*)r1rmr�rrr	r��s"
z#TestMedianGrouped.test_odd_decimalscCs�t}|d�|d�|d�|d�|d�|d�g}t�|�|�|�|�d�|d�|d�|d�|d�|d�|d�g}t�|�|�|�|�d�dS)Nz5.5z6.5z7.5z8.5g@g@)rr�r0rFr*)r1rmr�rrr	r��s(
(
z$TestMedianGrouped.test_even_decimalscCs�ddddddddddg
}|�|�|d�d	�dddddddddddg}|j|�|d�d
dd�d
d
ddddddddddg}|�|�|d�d�dS)Ng@g@g@g@g
@g@g@g�?g@g["8���@g:�0�yE>)r#����iii,i@iTr;g�p@)rFr*r6)r1r�rrr	�
test_interval�szTestMedianGrouped.test_intervalcCsxdddg}|�t|j|�dddg}|�t|j|�dddg}d}|�t|j||�dddg}d}|�t|j||�dS)N��rrrc)r�rr*)r1r��intervalrrr	�test_data_type_error�s



z&TestMedianGrouped.test_data_type_errorN)
r'r(r)rOr�r�rrr�r�r�r�r�r�rrrr	r�ks	
	r�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestModecCstj|_dS)N)r��moder*)r1rrr	rO�szTestMode.setUpcCsdddddddddddgS)	z+Overload method from UnivariateCommonMixin.rrcrqrerdrrwrr)r1rrr	r1�szTestMode.prepare_datacCs"tddd�}|�tj|j|�dS)Nr;r�rc)r�r�r�r�r*)r1r�rrr	r<�szTestMode.test_range_datacCs4d}|�|�|�d�d��}|�|�|�d�dS)NZabcbdbrzfe fi fo fum fi fi�fi)rFr*rl)r1r�rrr	�test_nominal_data�szTestMode.test_nominal_datacCsHttd��}x6td�D]*}||g}t�|�|�|�|�|�qWdS)Nrr)r
r�r�r0rFr*)r1r�r=rnrrr	�test_discrete_data�s


zTestMode.test_discrete_datacCs<dddddddddddddddd	d	g}|�tj|j|�dS)
NrrrcrqrRr3rerwrd)r�r�r�r*)r1r�rrr	�test_bimodal_data�s&zTestMode.test_bimodal_datacCs"ttd��}|�tj|j|�dS)Nrr)r
r�r�r�r�r*)r1r�rrr	�test_unique_data_failuresz!TestMode.test_unique_data_failurecCs|�t|jd�dS)N)r�rr*)r1rrr	�test_none_dataszTestMode.test_none_datacCs(t�ddddg�}|�tj|j|�dS)Nrr)r,�Counterr�r�r�r*)r1r�rrr	�test_counter_dataszTestMode.test_counter_dataN)r'r(r)rOr1r<r�r�r�r�r�r�rrrr	r��sr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�VarianceStdevMixing�-���q=cCs:x4dddtdd�td�fD]}|�|�|g�d�qWdS)Nrg������3@g���%�Brur�z8.392r)rrrFr*)r1rrrr	rm!sz$VarianceStdevMixin.test_single_valuecCsPxJdddtdd�td�fD].}x(dD] }|g|}|�|�|�d�q$WqWdS)	Ng������@r�g@�6��<Crcrez62.4802)rrcrRrKr)rrrFr*)r1rr]r�rrr	rr&s

z-VarianceStdevMixin.test_repeated_single_valuecCs4dgd}|�|�}|j|ddd�|�|d�dS)Ng.�F7ݚ�?i'gg��ؗ�Ҍ<)r#r)r*r6r�)r1r�r]rrr	�test_domain_error_regression-s

z/VarianceStdevMixin.test_domain_error_regressionc
sNddddddddd	d
g
}|�|�}d��fdd
�|D�}|�|�|�|�dS)Ng{�G�z�?gR���Q�?g
ףp=
�?gR���Q@g�p=
ף@g��Q�	@g@g�Q���@g�G�z�@g��Q�@gj�@csg|]}|��qSrr)r�r)�shiftrr	r�Bsz6VarianceStdevMixin.test_shift_data.<locals>.<listcomp>)r*r6)r1rBrr�r)r�r	�test_shift_data7s

z"VarianceStdevMixin.test_shift_datac
sNdddddddddd	g
}|�|�}d
��fdd�|D�}|�|�|�|�dS)
NrrcrqrRrerdrrrrpiʚ;csg|]}|��qSrr)r�r)r�rr	r�Ksz<VarianceStdevMixin.test_shift_data_exact.<locals>.<listcomp>)r*rF)r1rBrr�r)r�r	�test_shift_data_exactEs

z(VarianceStdevMixin.test_shift_data_exactcCs6dd�td�D�}|�|�}|�|�t|��|�dS)NcSsg|]}t�dd��qS)r�rw)r�r�)r�r�rrr	r�Vsz:VarianceStdevMixin.test_iter_list_same.<locals>.<listcomp>i�)r�r*rFr,)r1r�rrrr	�test_iter_list_sameNs
z&VarianceStdevMixin.test_iter_list_sameN)
r'r(r)r$rmrrr�r�r�r�rrrr	r�s
	r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestPVariancecCstj|_dS)N)r��	pvariancer*)r1rrr	rO]szTestPVariance.setUpcCs0ttd��}t�|�d}|�|�|�|�dS)Ni'gP�_A)r
r�r�r0rFr*)r1r�rrrr	�test_exact_uniform`s
z TestPVariance.test_exact_uniformcCs&ddddg}d}|�|�|�|�dS)Nrqrerrpg�6@)rFr*)r1r��exactrrr	rSgszTestPVariance.test_intscCsXt}|dd�|dd�|dd�|dd�g}|dd�}|�|�}|�||�|�|t�dS)Nrrqrcrerw)rr*rF�assertIsInstance)r1rhr�r�r]rrr	rUms$

zTestPVariance.test_fractionscCsNt}|d�|d�|d�|d�g}|d�}|�|�}|�||�|�|t�dS)Nz12.1z12.2z12.5z12.9z0.096875)rr*rFr�)r1rmr�r�r]rrr	rVvs
zTestPVariance.test_decimalsN)r'r(r)rOr�rSrUrVrrrr	r�[s
	r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestVariancecCstj|_dS)N)r��variancer*)r1rrr	rO�szTestVariance.setUpcCs:x4dddtdd�td�fD]}|�tj|j|g�qWdS)Nrfg33333�8@g�(G�!=Crlr�z4.2084)rrr�r�r�r*)r1rrrr	rm�szTestVariance.test_single_valuecCs&ddddg}d}|�|�|�|�dS)Nrqrerrpr�)rFr*)r1r�r�rrr	rS�szTestVariance.test_intscCsXt}|dd�|dd�|dd�|dd�g}|dd�}|�|�}|�||�|�|t�dS)Nrrqrcrer)rr*rFr�)r1rhr�r�r]rrr	rU�s$

zTestVariance.test_fractionscCsZt}|d�|d�|d�|d�g}d|d�|d�}|�|�}|�||�|�|t�dS)Nrrerdrqz9.5rc)rr*rFr�)r1rmr�r�r]rrr	rV�s
zTestVariance.test_decimalsN)r'r(r)rOrmrSrUrVrrrr	r��s
	r�c@seZdZdd�Zdd�ZdS)�
TestPStdevcCstj|_dS)N)r�Zpstdevr*)r1rrr	rO�szTestPStdev.setUpcCs8dd�td�D�}t�t�|��}|�|�|�|�dS)NcSsg|]}t�dd��qS)i��r�)r�r�)r�r�rrr	r��sz7TestPStdev.test_compare_to_variance.<locals>.<listcomp>i�)r�r�sqrtr�r�rFr*)r1r�rrrr	�test_compare_to_variance�sz#TestPStdev.test_compare_to_varianceN)r'r(r)rOr�rrrr	r��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�	TestStdevcCstj|_dS)N)r�Zstdevr*)r1rrr	rO�szTestStdev.setUpcCs:x4dddtdd�td�fD]}|�tj|j|g�qWdS)N�QgH�z�wi@gf7?+�BrRruz35.719)rrr�r�r�r*)r1rrrr	rm�szTestStdev.test_single_valuecCs8dd�td�D�}t�t�|��}|�|�|�|�dS)NcSsg|]}t�dd��qS)rQrd)r�r�)r�r�rrr	r��sz6TestStdev.test_compare_to_variance.<locals>.<listcomp>i�)r�rr�r�r�rFr*)r1r�rrrr	r��sz"TestStdev.test_compare_to_varianceN)r'r(r)rOrmr�rrrr	r��sr�cCs|�t���|S)z&Used for doctest/unittest integration.)ZaddTestsr�ZDocTestSuite)�loaderZtests�ignorerrr	�
load_tests�sr��__main__)rr)<r*r,Zcollections.abcrer�rr�r�r�rZ	fractionsrr�r
rrr%r&r�r+rDrHr\ryr�r�r�r�r�r�r�r�r�r�r�rrr)rDrKrPr\r_rkrsr|r�r�r�r�r�r�r�r�r�r�r�r�r'�mainrrrr	�<module>sr
:+_
>@w-@4d:c'H
@`X9
r<B%#