Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_statistics.cpython-35.pyc



��Yf��@sBdZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlZdd�Zdd�Z
d	d
dd�ZGd
d�d�ZGdd�dej�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�ZGd-d.�d.ej�Z Gd/d0�d0�Z!Gd1d2�d2�Z"Gd3d4�d4e!e"�Z#Gd5d6�d6e�Z$Gd7d8�d8e�Z%Gd9d:�d:e�Z&Gd;d<�d<e!�Z'Gd=d>�d>ee'e"�Z(Gd?d@�d@ee'�Z)GdAdB�dBee"�Z*GdCdD�dDe)e"�Z+GdEdF�dFe)e"�Z,GdGdH�dHe)�Z-GdIdJ�dJee'e"�Z.GdKdL�dLe!�Z/GdMdN�dNe/ee"�Z0GdOdP�dPe/ee"�Z1GdQdR�dRe/e�Z2GdSdT�dTe/e�Z3dUdV�Z4e5dWkr>ej6�dS)Xz_Test suite for statistics module, including helper NumericTestCase and
approx_equal function.

�N)�Decimal)�FractioncCs}t|�t|�k	rdSt|t�rGtj|�oFtj|�S|j�d}|j�d}||ko||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)rr)�type�
isinstance�float�math�isnanZas_tuple)�a�bZaexpZbexp�r�9/opt/alt/python35/lib64/python3.5/test/test_statistics.py�
_nan_equalsrcCsQtt|�t|��}t||�}|r;||n	td�}||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_errors7s
rg�-���q=gH�����z>cCs�|dks|dkr$td��tj|�sBtj|�rFdS||krVdStj|�sttj|�rxdSt||�}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)�
ValueErrorr
r�isinfrr)�x�y�tol�relZactual_errorZ
allowed_errorrrr�approx_equalGs"(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__rrrrr!�s#r!c@sbeZdZdZdZZddddd�Zdd�Zddd	�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.
    rNcCs}|dkr|j}|dkr*|j}t|tj�rZt|tj�rZ|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)rrr�collections�Sequence�_check_approx_seq�_check_approx_num)�self�first�secondrr�msg�checkrrr�assertApproxEqual�s			z!NumericTestCase.assertApproxEqualc
Cs�t|�t|�krUdt|�t|�f}|j||�}|j|��xEtt||��D].\}\}}	|j||	||||�qkWdS)Nz0sequences differ in length: %d items != %d items)�len�_formatMessage�failureException�	enumerate�zipr*)
r+r,r-rrr.�standardMsg�ir�errrr)�s(z!NumericTestCase._check_approx_seqcCsYt||||�rdS|j|||||�}|j||�}|j|��dS)N)r �_make_std_err_msgr2r3)r+r,r-rrr.�idxr6rrrr*�s
z!NumericTestCase._check_approx_numc	Csg||kst�d}|dk	r8d|}||}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.
)�AssertionErrorr)	r,r-rrr:�template�headerrrrrrr9�s

z!NumericTestCase._make_std_err_msg)r"r#r$r%rrr0r)r*�staticmethodr9rrrrr&�s
+	r&c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApproxEqualSymmetryTestcCs�dddtd�tdd�g}ddd
td
�tdd�g}t|�t|�ksft�x-t||�D]\}}|j||�qvWdS)Ni�	gfffff�B@gfffff�(@z2.54��6i�	g������B@gR����(@z2.59�gfffff�(�gR����(�)rrr1r;r5�do_relative_symmetry)r+Zargs1Zargs2rr
rrr�test_relative_symmetrys

$$z.ApproxEqualSymmetryTest.test_relative_symmetrycCs�t||�t||�}}||ks1t�||}t||�t||�}}||d}|jt||ddd|��|jt||ddd|��dS)Nrrrr)�minrr;r�
assertTruer )r+rr
�deltaZrel_err1Zrel_err2rrrrrC!s
!"z,ApproxEqualSymmetryTest.do_relative_symmetryc
Cs�dddddg}d}x^|D]V}xMttttfD]9}||�d}||}t|t||��}|j||d|d|�|j||d|d	dd|�|j||d|d	d|d�|j||d|d|d�|j||d|d	d|�|j||d|d	dd|�|j||dd
dd
�|j||dd
dd
�q;Wq"WdS)
N�r��ki�m�drr�ri�����)�intr	rrrr�do_symmetry_test)r+�argsrGr�type_rr�rrrr�
test_symmetry-s

$$  $z%ApproxEqualSymmetryTest.test_symmetrycCs\d}t||||�}t||||�}|j|||j||||f��dS)Nz+approx_equal comparisons don't match for %r)r �assertEqual�format)r+rr
rrr<Zflag1Zflag2rrrrOEsz(ApproxEqualSymmetryTest.do_symmetry_testN)r"r#r$rDrCrSrOrrrrr?sr?c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ApproxEqualExactTestcCset||d|d|�}|j|d|�t||d|d|�}|j|d|�dS)Nrrzequality failure for x=%r)r rF)r+rrr�resultrrr�do_exactly_equal_testRsz*ApproxEqualExactTest.do_exactly_equal_testcCs=x6dddddddgD]}|j|dd�qWdS)	N�*iMi~:��iiU�
i�r)rX)r+rrrr�test_exactly_equal_intsXs"z,ApproxEqualExactTest.test_exactly_equal_intscCs=x6dddddddgD]}|j|dd�qWdS)	Ng�z�G��?g/�$���?g�����e�@g7@gpf@g!�rh��Q@gB`��"KB@r)rX)r+rrrr�test_exactly_equal_floats]s"z.ApproxEqualExactTest.test_exactly_equal_floatscCsst}xf|dd�|d�|dd�|dd�|dd	�|dd�gD]}|j|dd�qRWdS)
NrLrrrI��	��#�$)rrX)r+�F�frrr�test_exactly_equal_fractionsbsRz1ApproxEqualExactTest.test_exactly_equal_fractionscCs=t}x0t|dj��D]}|j|dd�qWdS)Nz8.2 31.274 912.04 16.745 1.2047r)r�map�splitrX)r+�D�drrr�test_exactly_equal_decimalshsz0ApproxEqualExactTest.test_exactly_equal_decimalscCssxlddddddgD]R}|j|dd�|j|d	dd�t|d
�}|j|dd�qWdS)N�i�i\i�i��g{�G�z�?r�
i�)rXr)r+rrcrrr�test_exactly_equal_absolutens
z0ApproxEqualExactTest.test_exactly_equal_absolutecCsC|jtd�td�d�|jtd�td�d�dS)Nz3.571z0.01rz81.3971)rXr)r+rrr�$test_exactly_equal_absolute_decimalsysz9ApproxEqualExactTest.test_exactly_equal_absolute_decimalscCs\x6ddd
tdd�gD]}|j|dd�qW|jtd�dtd	��dS)Ni� g33333SY@g�z�G�@rI�rg{�G�z�?z11.68z0.01g�z�G�)rrXr)r+rrrr�test_exactly_equal_relative~s"z0ApproxEqualExactTest.test_exactly_equal_relativecCshx6dddtdd�gD]}|j|dd�qWt}|j|d�|d	�|d
��dS)Ni9�gˡE��0@g\��(h�@r]�g�������?g{�G�z�?z7.2z0.1z0.01g\��(h��)rrXr)r+rrgrrr�test_exactly_equal_both�s"z,ApproxEqualExactTest.test_exactly_equal_bothN)r"r#r$rXr[r\rdrirmrnrprrrrrrrVLsrVc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ApproxEqualUnequalTestcCsOxH||fD]9}t||ddddd�}|j|d|�qWdS)NrLrrrzinequality failure for x=%r)r �assertFalse)r+rrrWrrr�do_exactly_unequal_test�sz.ApproxEqualUnequalTest.do_exactly_unequal_testcCs1x*dddddgD]}|j|�qWdS)Ni�i��i�i�iXC)ru)r+rrrr�test_exactly_unequal_ints�sz0ApproxEqualUnequalTest.test_exactly_unequal_intscCs1x*dddddgD]}|j|�qWdS)Ng��Q�#@g����[�@gfffff�G@gףp=
W"@g=
ףp=1@)ru)r+rrrr�test_exactly_unequal_floats�sz2ApproxEqualUnequalTest.test_exactly_unequal_floatscCsXt}xK|dd�|dd�|dd�|dd�gD]}|j|�q=WdS)	NrLrIr_r^���eiς)rru)r+rbrcrrr�test_exactly_unequal_fractions�s=z5ApproxEqualUnequalTest.test_exactly_unequal_fractionscCs1x*ttdj��D]}|j|�qWdS)Nz!3.1415 298.12 3.47 18.996 0.00245)rerrfru)r+rhrrr�test_exactly_unequal_decimals�sz4ApproxEqualUnequalTest.test_exactly_unequal_decimalsN)r"r#r$rurvrwr{r|rrrrrs�s
rsc@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	Cs�d}x�||||fD]j}|j||�}|jt||dd|dd�|�|jt||d|ddd�|�qWdS)NzTest failure for x={!r}, y={!r}rrrr)rUrFr rt)r+rrGr<rr.rrr�do_approx_equal_abs_test�s
)z/ApproxEqualInexactTest.do_approx_equal_abs_testcCsVxOd
dddddddd	d
dgD]&}|j|d�|j|d�q(WdS)Ni�)i�r_rrrLr^�%i�i�&i6�jrli��iI���i����rM)r~)r+rrrr�test_approx_equal_absolute_ints�s.z6ApproxEqualInexactTest.test_approx_equal_absolute_intsc	Cs`xYd
dddddddd	g	D]6}|j|d
�|j|d�|j|d�q"WdS)Ng�t��q@gfffffFX@g333333@g333333@g�?g�?g333333@g�Q���@g�����ҭ@g�?g{�G�z�?g-C��6?g�t��q�gfffffFX�g333333�g333333�)r~)r+rrrr�!test_approx_equal_absolute_floats�s(z8ApproxEqualInexactTest.test_approx_equal_absolute_floatscCs~tdd�}ddddddddd	d
dg}xAdd
�|D�D],}|j||�|j|t|��qJWdS)NrL��TrBrrrIr@rH�"�Gcss|]}t|d�VqdS)r�N)r)�.0rrrr�	<genexpr>�szNApproxEqualInexactTest.test_approx_equal_absolute_fractions.<locals>.<genexpr>i����i�rM���)rr~r	)r+rG�
numeratorsrcrrr�$test_approx_equal_absolute_fractions�s
'z;ApproxEqualInexactTest.test_approx_equal_absolute_fractionscCsQtd�}x>ttdj��D]'}|j||�|j||�q"WdS)Nz0.01z1.0 3.5 36.08 61.79 7912.3648)rrerfr~)r+rGrhrrr�#test_approx_equal_absolute_decimals�sz:ApproxEqualInexactTest.test_approx_equal_absolute_decimalscCs&|jtdddddd��dS)Ng�h㈵��>rg-C��6?rrg�h㈵��)rFr )r+rrr�test_cross_zero�sz&ApproxEqualInexactTest.test_cross_zeroc
Cs�d}x�|d||d|fD]j}|j||�}|jt||dddd|�|�|jt||ddd|d�|�q#WdS)NzTest failure for x={!r}, y={!r}rLrrrr)rUrFr rt)r+rrGr<rr.rrr�do_approx_equal_rel_test�s
#)z/ApproxEqualInexactTest.do_approx_equal_rel_testcCs�|jtdddddd��|jtdddddd��|jtdd	dddd
��|jtdd	dddd
��|jtdd	dddd
��dS)
N�@�/rrrg
ףp=
�?g�G�z��?i�ig�?i�i�)rFr rt)r+rrr�test_approx_equal_relative_ints�s
""""z6ApproxEqualInexactTest.test_approx_equal_relative_intscCsJxCd	d
dddddgD]&}|j|d�|j|d�qWdS)Ng{�G�Jf@g�������?g�?g\��(|B@g��ʡE>�@g��x��@g{�G�z�?g-C��6?g{�G�Jf�g��������)r�)r+rrrr�!test_approx_equal_relative_floats�s"z8ApproxEqualInexactTest.test_approx_equal_relative_floatscCs�t}tdd�}x||dd�|dd�|dd�|dd	�gD]D}x;|t|�fD]'}|j||�|j||�qeWqLWdS)
Nr]rqr�r@��1�2�\�U)rr	r�)r+rbrGrcrhrrr�$test_approx_equal_relative_fractions�s=z;ApproxEqualInexactTest.test_approx_equal_relative_fractionscCsQxJttdj��D]3}|j|td��|j|td��qWdS)Nz$0.02 1.0 5.7 13.67 94.138 91027.9321z0.001z0.05)rerrfr�)r+rhrrr�#test_approx_equal_relative_decimals�sz:ApproxEqualInexactTest.test_approx_equal_relative_decimalscCs�|r|jn|j}|t||d|dd��|rF|jn|j}|t||ddd|��|sz|r�|jn|j}|t||d|d|��dS)Nrrr)rFrtr )r+rr
rrZtol_flagZrel_flagr/rrr�
do_check_bothsz$ApproxEqualInexactTest.do_check_bothcCs<|jdddddd�|jd
ddd	dd�dS)NgR����@g+���@g����Mbp?g���W�8?Tg?5^�I�@g%��C�@g����Mb`?g-C��6*?g?5^�I��g%��C��)r�)r+rrr�test_approx_equal_both1sz.ApproxEqualInexactTest.test_approx_equal_both1cCs |jdddddd�dS)NgR����@g+���@g����Mbp?gV�F�?8?TF)r�)r+rrr�test_approx_equal_both2sz.ApproxEqualInexactTest.test_approx_equal_both2cCs |jdddddd�dS)NgR����@g+���@g����MbP?g���W�8?FT)r�)r+rrr�test_approx_equal_both3sz.ApproxEqualInexactTest.test_approx_equal_both3cCs<|jdddddd�|jdddd	dd�dS)
Ng=
ףp=@g@g{�G�z�?g����MbP?Fg�Q��[�@g�(\��[�@g{�G�z�?giUMu�>)r�)r+rrr�test_approx_equal_both4sz.ApproxEqualInexactTest.test_approx_equal_both4N)r"r#r$r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr}�s 		r}c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApproxEqualSpecialsTestcCs�x�ttfD]�}|d�}|jt||��|jt||dd��|jt||dd��|jt||��|jt||��|jt|d��q
WdS)NrrrLg{�G�z�?i�)r	rrFr rt)r+rQrrrr�test_inf%sz ApproxEqualSpecialsTest.test_infcCs]xVttfD]H}|d�}x3||d�dfD]}|jt||��q5Wq
WdS)N�nanri�)r	rrtr )r+rQr��otherrrr�test_nan/sz ApproxEqualSpecialsTest.test_nancCs8tjdd�}|jt|ddddd��dS)NgrLrg�������?rr�)r
ZcopysignrFr )r+�nzerorrr�test_float_zeroes5sz)ApproxEqualSpecialsTest.test_float_zeroescCs8td�}|jt|td�dddd��dS)Nz-0.0rrg�������?r)rrFr )r+r�rrr�test_decimal_zeroes9sz+ApproxEqualSpecialsTest.test_decimal_zeroesN)r"r#r$r�r�r�r�rrrrr�"s
r�c@s(eZdZdd�Zdd�ZdS)�TestApproxEqualErrorscCs |jttdddd�dS)NrKrLg�������?r�)�assertRaisesrr )r+rrr�test_bad_tolAsz"TestApproxEqualErrors.test_bad_tolcCs |jttdddd�dS)NrKrLg�������?g��������)r�rr )r+rrr�test_bad_relEsz"TestApproxEqualErrors.test_bad_relN)r"r#r$r�r�rrrrr�>sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestNumericTestCasecCsCtj|�}|j|�}x|D]}|j||�q%WdS)N)r&r9�generate_substringsZassertIn)r+rPZ
actual_msgrZ	substringrrr�do_testUs
zTestNumericTestCase.do_testcCs|jtttj��dS)N)rF�
issubclassr&�unittest�TestCase)r+rrr� test_numerictestcase_is_testcase[sz4TestNumericTestCase.test_numerictestcase_is_testcasecCsd}|j|�dS)N�@�@��?��?)r�r�r�r�N)r�)r+rPrrr�test_error_msg_numeric_sz*TestNumericTestCase.test_error_msg_numericcCsd}|j|�dS)N�@�� @��?��?r_)r�r�r�r�r_)r�)r+rPrrr�test_error_msg_sequencedsz+TestNumericTestCase.test_error_msg_sequencec	CsXt||�\}}d|d|d|d|g}|dk	rT|jd|�|S)z5Return substrings we expect to see in error messages.ztol=%rzrel=%rzabsolute error = %rzrelative error = %rNzdiffer at index %d)r�append)	r+r,r-rrr:rrZ
substringsrrrr�is
z'TestNumericTestCase.generate_substringsN)r"r#r$r�r�r�r�r�rrrrr�Os
r�c@s:eZdZeZddgZdd�Zdd�ZdS)�GlobalsTestr%�__all__cCs8x1|jD]&}|jt|j|�d|�q
WdS)Nz%s not present)�expected_metadatarF�hasattr�module)r+�metarrr�	test_meta�szGlobalsTest.test_metacCs[|j}xK|jD]@}|j|jd�d|�|jt||�d|�qWdS)N�_zprivate name "%s" in __all__zmissing name "%s" in __all__)r�r�rt�
startswithrFr�)r+r��namerrr�test_check_all�s	zGlobalsTest.test_check_allN)r"r#r$�
statisticsr�r�r�r�rrrrr�|sr�c@s:eZdZejejjdkd�dd��ZdS)�DocTestsrz)Docstrings are omitted with -OO and abovecCs9tjt�\}}|j|d�|j|d�dS)Nr)�doctestZtestmodr��
assertGreaterrT)r+ZfailedZtriedrrr�test_doc_tests�szDocTests.test_doc_testsN)	r"r#r$r�ZskipIf�sys�flags�optimizer�rrrrr��sr�c@seZdZdd�ZdS)�StatisticsErrorTestcCsFd}|jttd��|jttjt�|tjj�dS)NzNExpected StatisticsError to be a ValueError, but got a subclass of %r instead.�StatisticsError)rFr�r�r�r�r�__base__)r+�errmsgrrr�test_has_exception�s
z&StatisticsErrorTest.test_has_exceptionN)r"r#r$r�rrrrr��sr�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ExactRatioTestcCs4x-dD]%}|jtj|�|df�qWdS)N�r]rrI�crlrL������� F�x:^V)r�r�rrIr�r�)rTr��_exact_ratio)r+r7rrr�test_int�s
zExactRatioTest.test_intcCsId}x<|D]4}t|d�}|jtj|�|df�q
WdS)NrIrLrx�&r���)r�rLrxr�)rrTr�r�)r+r�rrcrrr�
test_fraction�s
zExactRatioTest.test_fractioncCs�|jtjd�d	�|jtjd�d
�dd�td�D�}x7|D]/}tj|�\}}|j|||�qRWdS)Ng�?rLrqg�?r^cSs"g|]}tjdd��qS)rKi����)�random�uniform)r�r�rrr�
<listcomp>�s	z-ExactRatioTest.test_float.<locals>.<listcomp>rK)rLrq)r^rq)rTr�r��range)r+�datar�num�denrrr�
test_float�s
zExactRatioTest.test_floatcCsgt}tj}|j||d��d	�|j||d��d
�|j||d��d�dS)
Nz0.125�}��z12.345�90z-1.98��rK)r�r�)r�r��:���)r�rK)rr�r�rT)r+rgr�rrr�test_decimal�s
	zExactRatioTest.test_decimalcCs�td�}Gdd�dt�}Gdd�dt�}x�||fD]�}xt|t|fD]k}||�}tj|�}|j||df�|jt|d�|�|jtj|d��q_WqFWdS)N�INFc@seZdZdS)z(ExactRatioTest.test_inf.<locals>.MyFloatN)r"r#r$rrrr�MyFloat�sr�c@seZdZdS)z*ExactRatioTest.test_inf.<locals>.MyDecimalN)r"r#r$rrrr�	MyDecimal�sr�r)	r	rr�r�rTrrFr
r)r+r�r�r�rrQr�ratiorrrr��szExactRatioTest.test_infcCs�td�}Gdd�dt�}xw|||�fD]c}tj|�}|jtj|d��|j|dd�|jt|d�t|��q5WdS)N�NANc@seZdZdS)z.ExactRatioTest.test_float_nan.<locals>.MyFloatN)r"r#r$rrrrr��sr�rrL)	r	r�r�rFr
r�assertIsrTr)r+r�r�r�r�rrr�test_float_nan�szExactRatioTest.test_float_nancCs�td�}td�}Gdd�dt�}x�|||�|||�fD]c}tj|�}|jt|d|��|j|dd�|jt|d�t|��qMWdS)Nr��sNANc@seZdZdS)z2ExactRatioTest.test_decimal_nan.<locals>.MyDecimalN)r"r#r$rrrrr��sr�rrL)rr�r�rFrr�rTr)r+r�r�r�r�r�rrr�test_decimal_nan�s%zExactRatioTest.test_decimal_nanN)
r"r#r$r�r�r�r�r�r�r�rrrrr��s
r�c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�DecimalToRatioTestcCsPtd�}|jtj|�|df�|jtj|�|df�dS)Nr�)rrTr��_decimal_to_ratio)r+rrrr�
test_infinity�sz DecimalToRatioTest.test_infinitycCsbx[td�td�fD]A}tj|�\}}|jt||��|j|d�qWdS)Nr�r�)rr�r�rFrr�)r+r�r�r�rrrr��szDecimalToRatioTest.test_nancCs�td�td�g}x�|D]�}|dks7t�tj|�\}}|j|d�|j|d�tj|�\}}|j|d�|j|d�qWdS)Nz	9.8765e12z
9.8765e-12r)rr;r�r��assertGreaterEqualr�ZassertLessEqual)r+Znumbersrhr�r�rrr�	test_sign�s
zDecimalToRatioTest.test_signcCs)tjtd��}|j|d�dS)Nz0.1234���')r�r�)r�r�rrT)r+�trrr�test_negative_exponent
sz)DecimalToRatioTest.test_negative_exponentcCs)tjtd��}|j|d�dS)Nz1.234e7� K�rL)r�rL)r�r�rrT)r+r�rrr�test_positive_exponentsz)DecimalToRatioTest.test_positive_exponentcCsNtjtd��}|j|d�tjtd��}|j|d�dS)NZ1e2rKrLz1.47e5�8>)rKrL)rrL)r�r�rrT)r+r�rrr�test_regression_20536sz(DecimalToRatioTest.test_regression_20536N)	r"r#r$r�r�r�r�rrrrrrr��s
r�c@s4eZdZdd�Zdd�Zdd�ZdS)�IsFiniteTestcCsFx?dtdd�dtd�fD]}|jtj|��q"WdS)NrIrLr]g@z5.5)rrrFr��	_isfinite)r+rrrr�test_finite s(zIsFiniteTest.test_finitecCs=x6td�td�fD]}|jtj|��qWdS)Nr)r	rrtr�r)r+rrrrr�%szIsFiniteTest.test_infinitycCsFx?td�td�td�fD]}|jtj|��q"WdS)Nr�r�r�)r	rrtr�r)r+rrrrr�*s(zIsFiniteTest.test_nanN)r"r#r$rr�r�rrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
CoerceTestcCsoxhttttfD]T}|jtj|t�|�Gdd�d|�}|jtj|t�|�qWdS)Nc@seZdZdS)z%CoerceTest.test_bool.<locals>.MyClassN)r"r#r$rrrr�MyClassKsr)rNr	rrr�r��_coerce�bool)r+�Trrrr�	test_boolEszCoerceTest.test_boolcCs<|jtj||�|�|jtj||�|�dS)z Assert that type A coerces to B.N)r�r�r)r+�A�Brrr�assertCoerceToNszCoerceTest.assertCoerceTocCsp|j||�Gdd�d|�}|j||�Gdd�d|�}|j||�|j||�dS)z6Checks that type A coerces to B, including subclasses.c@seZdZdS)z/CoerceTest.check_coerce_to.<locals>.SubclassOfAN)r"r#r$rrrr�SubclassOfAXsrc@seZdZdS)z/CoerceTest.check_coerce_to.<locals>.SubclassOfBN)r"r#r$rrrr�SubclassOfB[srN)r)r+rr
rrrrr�check_coerce_toSszCoerceTest.check_coerce_tocCs<|jttj||f�|jttj||f�dS)z=Assert that coercing A to B, or vice versa, raises TypeError.N)r��	TypeErrorr�r)r+rr
rrr�assertCoerceRaises_szCoerceTest.assertCoerceRaisescCs�|tk	st�|jtj||�|�Gdd�d|�}Gdd�d|�}Gdd�d|�}x'|||fD]}|j||�q�W|j||�|j||�|j||�dS)z>Check that type T coerces correctly with subclasses of itself.c@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.UN)r"r#r$rrrr�Ujsrc@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.VN)r"r#r$rrrr�Vksrc@seZdZdS)z*CoerceTest.check_type_coercions.<locals>.WN)r"r#r$rrrr�WlsrN)r	r;r�r�rrr)r+r
rrr�typrrr�check_type_coercionsdszCoerceTest.check_type_coercionscCs;|jt�x'tttfD]}|jt|�qWdS)N)rrNr	rrr)r+rrrrr�ts
zCoerceTest.test_intcCs!|jt�|jtt�dS)N)rrrr	)r+rrrr�zs
zCoerceTest.test_fractioncCs|jt�dS)N)rr)r+rrrr�szCoerceTest.test_decimalcCs|jt�dS)N)rr	)r+rrrr��szCoerceTest.test_floatcCsWxPtttd�ttfD]3}x*ttttfD]}|j	||�q5WqWdS)N)
�str�listr�tuple�dictrNr	rrr)r+Zbad_typeZ	good_typerrr�test_non_numeric_types�s"z!CoerceTest.test_non_numeric_typescCsQxJttfD]<}Gdd�d|�}|j|t�|j|t�q
WdS)Nc@seZdZdS)z6CoerceTest.test_incompatible_types.<locals>.MySubclassN)r"r#r$rrrr�
MySubclass�sr)r	rrr)r+r
rrrr�test_incompatible_types�sz"CoerceTest.test_incompatible_typesN)r"r#r$rrrrrr�r�r�r�rrrrrrr0s	rc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ConvertTestcCs0|j||�|jt|�t|��dS)z5Check that x equals y, and has the same type as well.N)rTr�r)r+rrrrr�check_exact_equal�szConvertTest.check_exact_equalcCsptjtd�t�}|j|d�Gdd�dt�}tjtd�|�}|j||d��dS)Nr�c@seZdZdS)z#ConvertTest.test_int.<locals>.MyIntN)r"r#r$rrrr�MyInt�sr"r@)r��_convertrrNr!)r+rr"rrrr��s
zConvertTest.test_intcCs�tjtdd�t�}|j|tdd��Gdd�dt�}tjtdd�|�}|j||dd��dS)N�_r�cs"eZdZ�fdd�Z�S)z-ConvertTest.test_fraction.<locals>.MyFractioncs|jt�j|��S)N)�	__class__�super�__truediv__)r+r�)r%rrr'�sz9ConvertTest.test_fraction.<locals>.MyFraction.__truediv__)r"r#r$r'rr)r%r�
MyFraction�sr(r��
)r�r#rr!)r+rr(rrrr��s
zConvertTest.test_fractioncCsvtjtd	d�t�}|j|d
�Gdd�dt�}tjtdd�|�}|j||d��dS)NrLrg�?cs"eZdZ�fdd�Z�S)z'ConvertTest.test_float.<locals>.MyFloatcs|jt�j|��S)N)r%r&r')r+r�)r%rrr'�sz3ConvertTest.test_float.<locals>.MyFloat.__truediv__)r"r#r$r'rr)r%rr��sr�r^rqg�?r�g�)r�r#rr	r!)r+rr�rrrr��s
zConvertTest.test_floatcCs|tjtdd�t�}|j|td��Gdd�dt�}tjtd	d�|�}|j||d��dS)
NrL�(z0.025cs"eZdZ�fdd�Z�S)z+ConvertTest.test_decimal.<locals>.MyDecimalcs|jt�j|��S)N)r%r&r')r+r�)r%rrr'�sz7ConvertTest.test_decimal.<locals>.MyDecimal.__truediv__)r"r#r$r'rr)r%rr��sr�rBrjz-0.9375i�)r�r#rrr!)r+rr�rrrr��s
zConvertTest.test_decimalcCsgx`td�td�fD]F}x=||fD].}tj|t|��}|j||�q-WqWdS)Nr)r	rr�r#rr!)r+r�rrrrrr��szConvertTest.test_infcCs^xWtd�td�td�fD]4}tj|t|��}|jt||��q"WdS)Nr�r�r�)r	rr�r#rrFr)r+r�rrrrr��s(zConvertTest.test_nanN)
r"r#r$r!r�r�r�r�r�r�rrrrr �s


r c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�UnivariateCommonMixincCs|jt|j�dS)N)r�r�func)r+rrr�test_no_args�sz"UnivariateCommonMixin.test_no_argscCs=x6gftg�fD]}|jtj|j|�qWdS)N)�iterr�r�r�r,)r+�emptyrrr�test_empty_data�sz%UnivariateCommonMixin.test_empty_datacCs<ttd��}x#|t|�kr7tj|�qW|S)z"Return int data for various tests.rl)rr��sortedr��shuffle)r+r�rrr�prepare_data�sz"UnivariateCommonMixin.prepare_datacCs�|j�}t|�dks$t�|t|�ks<t�|dd�}||k	s^t�|j|�}|j||d�dS)NrLzdata has been modified)r3r1r;r1r,ZassertListEqual)r+r�Zsavedr�rrr�test_no_inplace_modifications�sz3UnivariateCommonMixin.test_no_inplace_modificationscCsaddddddddgd}|j|�}tj|�|j|�}|j||�dS)NrLrr]rkrI�rK)r,r�r2rT)r+r�rrrrr�test_order_doesnt_matter�s
"
z.UnivariateCommonMixin.test_order_doesnt_mattercCs�Gdd�dt�}Gdd�dt�}dd�}|j�}|j|�}xEttt|||fD]+}|j||��}|j||�qlWdS)Nc@seZdZdS)zBUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyListN)r"r#r$rrrr�MyList�sr7c@seZdZdS)zCUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyTupleN)r"r#r$rrrr�MyTuple�sr8cSsdd�|D�S)Ncss|]}|VqdS)Nr)r��objrrrr�szXUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator.<locals>.<genexpr>r)r�rrr�	generatorszEUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator)rrr3r,r.rT)r+r7r8r:r�r�kindrWrrr�test_type_of_data_collection�sz2UnivariateCommonMixin.test_type_of_data_collectioncCsDtddd�}|jt|��}|j|j|�|�dS)Nr�r�r])r�r,rrT)r+r�rrrr�test_range_datasz%UnivariateCommonMixin.test_range_datacCs;|jd�|jd�|jd�|jt��dS)NrHgE@)�check_for_type_error�object)r+rrr�test_bad_arg_typess



z(UnivariateCommonMixin.test_bad_arg_typescGs|jt|j|�dS)N)r�rr,)r+rPrrrr>sz*UnivariateCommonMixin.check_for_type_errorcs�Gdd�dt�}|j�}|j|�}x^t|ttfD]J��fdd�|D�}t|�|j|��}|j||�qDWdS)Ncs:eZdZ�fdd�Z�fdd�ZeZ�S)z@UnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloatcst|�t�j|��S)N)rr&r')r+r�)r%rrr'%szLUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__truediv__cst|�t�j|��S)N)rr&�__add__)r+r�)r%rrrA'szHUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__add__)r"r#r$r'rA�__radd__rr)r%rr�$sr�csg|]}�|��qSrr)r�r)r;rrr�.s	zCUnivariateCommonMixin.test_type_of_data_element.<locals>.<listcomp>)r	r3r,rrrrT)r+r��rawrr�rWr)r;r�test_type_of_data_element sz/UnivariateCommonMixin.test_type_of_data_elementN)
r"r#r$r-r0r3r4r6r<r=r@r>rDrrrrr+�s

r+c@s"eZdZdZdd�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.
    cs�Gdd�dt�}|j�}xXttt|fD]D��fdd�|D�}|j|�}|jt|���q5WdS)NcspeZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Z�fd	d
�ZeZ�S)z9UnivariateTypeMixin.test_types_conserved.<locals>.MyFloatcst|�t�j|��S)N)rr&r')r+r�)r%rrr'BszEUnivariateTypeMixin.test_types_conserved.<locals>.MyFloat.__truediv__cst|�t�j|��S)N)rr&�__sub__)r+r�)r%rrrFDszAUnivariateTypeMixin.test_types_conserved.<locals>.MyFloat.__sub__cst|�t�j|��S)N)rr&�__rsub__)r+r�)r%rrrGFszBUnivariateTypeMixin.test_types_conserved.<locals>.MyFloat.__rsub__cst|�t�j|��S)N)rr&�__pow__)r+r�)r%rrrHHszAUnivariateTypeMixin.test_types_conserved.<locals>.MyFloat.__pow__cst|�t�j|��S)N)rr&rA)r+r�)r%rrrAJszAUnivariateTypeMixin.test_types_conserved.<locals>.MyFloat.__add__)	r"r#r$r'rFrGrHrArBrr)r%rr�Asr�csg|]}�|��qSrr)r�r)r;rrr�Ps	z<UnivariateTypeMixin.test_types_conserved.<locals>.<listcomp>)r	r3rrr,r�r)r+r�r�rhrWr)r;r�test_types_conserved=s
z(UnivariateTypeMixin.test_types_conservedN)r"r#r$r%rIrrrrrE3s	rEc@seZdZdd�ZdS)�
TestSumCommoncCsdd�}||_dS)NcWs(tj|�\}}}tj||�S)N)r��_sumr)rPr
�valuerrrr�simplified_sum[sz+TestSumCommon.setUp.<locals>.simplified_sum)r,)r+rMrrr�setUpZszTestSumCommon.setUpN)r"r#r$rNrrrrrJUsrJc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestSumcCstj|_dS)N)r�rKr,)r+rrrrNfsz
TestSum.setUpcCs�x�gftg�fD]�}|j|j|�ttd�df�|j|j|d�ttd�df�|j|j|d�ttd�df�qWdS)NrrHgffffff@)r.rTr,rNrr	)r+r�rrrr0is(+zTestSum.test_empty_datac
Cs~|j|jdddd
ddddg�ttd�df�|j|jdd	ddd
gd�ttd�df�dS)NrLrIr]rkrqr�rY�<rr_i�i����i����i����)rTr,rNr)r+rrr�	test_intsps*$zTestSum.test_intscCsj|j|jdgd�ttd�df�|j|jddddgd�ttd�d	f�dS)
Ng�?r�g@g�?g�?g�?g�?g	@rk)rTr,r	r)r+rrr�test_floatsvs!zTestSum.test_floatscCs?|j|jtdd�gd�ttdd�df�dS)NrLi�i�r)rTr,r)r+rrr�test_fractions|s"zTestSum.test_fractionsc	Cs�t}|d�|d�|d�|d�|d�|d�|d�|d�g}|j|j|�ttd	�d
f�dS)Nz0.001z5.246z1.702z-0.025z3.974z2.328z4.617z2.843z20.686rq)rrTr,)r+rgr�rrr�
test_decimals�s
$*zTestSum.test_decimalscCsOdd�td�D�}|jt|j|�d�tj|�dd�dS)NcSs"g|]}tjdd��qS)rKi�i����)r�r�)r�r�rrrr��s	z7TestSum.test_compare_with_math_fsum.<locals>.<listcomp>i�rLrg��ؗ�Ҭ<)r�r0r	r,r
Zfsum)r+r�rrr�test_compare_with_math_fsum�sz#TestSum.test_compare_with_math_fsumcCs�dd�td�D�}|j|�d}|j|d|j|d�d�|j|d|j|d�d�|j|td�|j|d�d�dS)	NcSs"g|]}tjdd��qS)rLi�)r�r�)r�r�rrrr��s	z/TestSum.test_start_argument.<locals>.<listcomp>rKrLrYrHg@��x�Di��)r�r,rTr)r+r�r�rrr�test_start_argument�s
$$zTestSum.test_start_argumentcCsH|jt|jdddgd�|jt|jddddg�dS)NrLrr]Z999)r�rr,)r+rrr�test_strings_fail�s"zTestSum.test_strings_failcCsH|jt|jdddgd�|jt|jddddg�dS)NrLrr]s999)r�rr,)r+rrr�test_bytes_fail�s"zTestSum.test_bytes_failcCsN|jt|jddtd�g�|jt|jddgtd��dS)NrLg@)r�rr,r)r+rrr�test_mixed_sum�s%zTestSum.test_mixed_sumN)r"r#r$rNr0rRrSrTrUrVrWrXrYrZrrrrrOasrOc@seZdZdd�ZdS)�SumTortureTestcCs�|jtjdddd
gd�ttd�df�|jtjddddgd�ttd�df�tjddddgd�\}}}|j|t�|j|d�|jt|�ddd	�dS)
NrLg}Ô%�I�Ti'g��@i@�g0��.�++g���^�,rgV瞯�<g}Ô%�I��g}Ô%�I��r�)rTr�rKr	rr�r0)r+r
r��countrrr�test_torture�s""(zSumTortureTest.test_tortureN)r"r#r$r]rrrrr[�sr[c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�SumSpecialValuescCsoxhttfD]Z}|d�}tjd|dg�d}|jt|�|�|jtj|��q
WdS)Nr�rLr)	r	rr�rKr�rrFr
r)r+rQr�rWrrrr��s
zSumSpecialValues.test_nancCsd|jtj|��|jt|�t|��|j|dk|dk�||ks`t�dS)z8Check x is an infinity of the same type and sign as inf.rN)rFr
rr�rrTr;)r+rrrrr�check_infinity�szSumSpecialValues.check_infinitycCshtjdd|dg�d}|j||�tjdd|d|dg�d}|j||�dS)NrLrr]rk)r�rKr_)r+rrWrrr�do_test_inf�s%zSumSpecialValues.do_test_infcCs2td�}xdD]}|j||�qWdS)NrrLrLr�)rLr�)r	r`)r+r�signrrr�test_float_inf�s
zSumSpecialValues.test_float_infcCs2td�}xdD]}|j||�qWdS)NrrLrLr�)rLr�)rr`)r+rrarrr�test_decimal_inf�s
z!SumSpecialValues.test_decimal_infcCsLtd�}tjdd|d|dg�d}|jtj|��dS)NrrLrr]rk)r	r�rKrFr
r)r+rrWrrr�test_float_mismatched_infs�s&z+SumSpecialValues.test_float_mismatched_infscCsftd�}dd|d|dg}tjtj��(|jtjtj|�d��WdQRXdS)NrrLrr]rk)	r�decimal�localcontextZExtendedContextrFr
rr�rK)r+rr�rrr�3test_decimal_extendedcontext_mismatched_infs_to_nan�szDSumSpecialValues.test_decimal_extendedcontext_mismatched_infs_to_nancCs\td�}dd|d|dg}tjtj��|jtjtj|�WdQRXdS)NrrLrr]rk)rrerfZBasicContextr��InvalidOperationr�rK)r+rr�rrr�0test_decimal_basiccontext_mismatched_infs_to_nan�szASumSpecialValues.test_decimal_basiccontext_mismatched_infs_to_nancCs8td�}d|dg}|jtjtj|�dS)Nr�rLr)rr�rerhr�rK)r+r�r�rrr�test_decimal_snan_raises�sz)SumSpecialValues.test_decimal_snan_raisesN)r"r#r$r�r_r`rbrcrdrgrirjrrrrr^�sr^c@s(eZdZdd�Zdd�ZdS)�AverageMixincCsOxHdddtdd�td�fD]"}|j|j|g�|�q%WdS)NrHg@E@g�X_yCrB�z0.28)rrrTr,)r+rrrr�test_single_value�s+zAverageMixin.test_single_valuecCsjxcdddtdd�td�fD]=}x4dD],}|g|}|j|j|�|�q2Wq%WdS)Ng@r@g��7y�!C�=�Cz4.9712rrIrlr�)rrIrlr�)rrrTr,)r+rr\r�rrr�test_repeated_single_value�s+

z'AverageMixin.test_repeated_single_valueN)r"r#r$rmrprrrrrk�srkc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�TestMeancCstj|_dS)N)r��meanr,)r+rrrrNszTestMean.setUpcCs)|j|jddddg�d�dS)Ng}Ô%�I�TrLr]g}Ô%�I��)rTr,)r+rrr�test_torture_pep
szTestMean.test_torture_pepcCs`ddddddddddddddd	d
g}tj|�|j|j|�d�dS)NrrLrr]rkrIr5r_rqr^g@@)r�r2rTr,)r+r�rrrrRs6
zTestMean.test_intscCsHddddddddg}tj|�|j|j|�d	�dS)
Ng@1@g�3@g4@g�5@g�5@g@7@g 9@g�;@g6@)r�r2rTr,)r+r�rrrrSs
zTestMean.test_floatscCsit}|d�|d�|d�|d�|d�g}tj|�|j|j|�|d��dS)Nz1.634z2.517z3.912z4.072z5.813z3.5896)rr�r2rTr,)r+rgr�rrrrUs3
zTestMean.test_decimalsc	Cs�t}|dd�|dd�|dd�|dd�|dd�|dd�|dd�g}tj|�|j|j|�|d	d
��dS)NrLrr]rkrIr5r_rqi�i�)rr�r2rTr,)r+rbr�rrrrT!sZ
zTestMean.test_fractionscCs�dddddg}xwttfD]i}x`dD]X}|d�|}||g}|j|�}|jtj|��|j||�q/Wq"WdS)	NrLr]rIr_r^rr�)rLr�)r	rr,rFr
rrT)r+rCr;rarr�rWrrrr�(s

zTestMean.test_infc	CsSdddtd�dddtd�g}|j|�}|jtj|��dS)	Nrrkr5rrLr]rIz-inf)r	r,rFr
r)r+r�rWrrr�test_mismatched_infs3s*zTestMean.test_mismatched_infscCsndddddg}xRttfD]D}|d�}||g}|j|�}|jtj|��q"WdS)NrLr]rIr_r^r�)r	rr,rFr
r)r+rCr;rr�rWrrrr�9s
zTestMean.test_nanc	s�d�dddddddd	d
g	}|j|��}|�ksLt�|j�fdd�|D��}|j||�dS)
Nge��Ag333333@g@g������@g������@g333333@g������@g @g333333 @g������"@csg|]}|��qSrr)r�r)�crrr�Hs	z*TestMean.test_big_data.<locals>.<listcomp>)r,r;rT)r+r�rrWr)rur�
test_big_dataBs!"zTestMean.test_big_datacCsOdd�td�D�}|j|�}|j|d�}|j||�dS)NcSs"g|]}tjdd��qS)r]rIr�)r�r�)r�r�rrrr�Ms	z.TestMean.test_doubled_data.<locals>.<listcomp>i�r)r�r,r0)r+r�rrrrr�test_doubled_dataKszTestMean.test_doubled_datacCs,td�}|jtj|g�|�dS)NZ1e4)rrTr�rr)r+rhrrr�test_regression_20561RszTestMean.test_regression_20561cCs�|jtjddg�d�d}d}xNdD]F}|jtj|g|�|�|jtj|g|�|�q2WdS)	Ng�������g�grr]rI��)rr]rIry)rTr�rr)r+ZbigZtinyrrrr�test_regression_25177Xs
 zTestMean.test_regression_25177N)r"r#r$rNrsrRrSrUrTr�rtr�rvrwrxrzrrrrrqs		rqcsveZdZdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�S)�
TestMediancCstj|_dS)N)r��medianr,)r+rrrrNhszTestMedian.setUpcs6t�j�}t|�ddkr2|jd�|S)z+Overload method from UnivariateCommonMixin.rrL)r&r3r1r�)r+r�)r%rrr3ks
zTestMedian.prepare_datacCsQddddddg}t|�ddks4t�|j|j|�d�dS)	NrLrr]rkrIr5rg@)r1r;rTr,)r+r�rrr�test_even_intsrszTestMedian.test_even_intscCsTdddddddg}t|�ddks7t�|j|j|�d�dS)NrLrr]rkrIr5r^)r1r;rTr,)r+r�rrr�
test_odd_intsxszTestMedian.test_odd_intscCs�t}|dd�|dd�|dd�|dd�|dd�g}t|�ddksdt�tj|�|j|j|�|dd��dS)NrLr_rr]rkrI)rr1r;r�r2rTr,)r+rbr�rrr�test_odd_fractions~s
B
zTestMedian.test_odd_fractionscCs�t}|dd�|dd�|dd�|dd�|dd�|dd�g}t|�ddkspt�tj|�|j|j|�|dd��dS)	NrLr_rr]rkrIr5r)rr1r;r�r2rTr,)r+rbr�rrr�test_even_fractions�s
N
zTestMedian.test_even_fractionscCs�t}|d�|d�|d�|d�|d�g}t|�ddksUt�tj|�|j|j|�|d��dS)Nz2.5z3.1z4.2z5.7z5.8rrL)rr1r;r�r2rTr,)r+rgr�rrr�test_odd_decimals�s
3
zTestMedian.test_odd_decimalscCs�t}|d�|d�|d�|d�|d�|d�g}t|�ddks^t�tj|�|j|j|�|d	��dS)
Nz1.2z2.5z3.1z4.2z5.7z5.8rrz3.65)rr1r;r�r2rTr,)r+rgr�rrr�test_even_decimals�s
<
zTestMedian.test_even_decimals)r"r#r$rNr3r}r~rr�r�r�rr)r%rr{fsr{c@s(eZdZdd�Zdd�ZdS)�TestMedianDataTypecCstj|_dS)N)r�r|r,)r+rrrrN�szTestMedianDataType.setUpcCsXttd��}t|�ddks.t�x#|t|�krStj|�q1W|S)NrBrrL)rr�r1r;r1r�r2)r+r�rrrr3�s
zTestMedianDataType.prepare_dataN)r"r#r$rNr3rrrrr��sr�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TestMedianLowcCstj|_dS)N)r�Z
median_lowr,)r+rrrrN�szTestMedianLow.setUpcCsQddddddg}t|�ddks4t�|j|j|�d�dS)NrLrr]rkrIr5r)r1r;rTr,)r+r�rrrr}�szTestMedianLow.test_even_intscCs�t}|dd�|dd�|dd�|dd�|dd�|dd�g}t|�ddkspt�tj|�|j|j|�|dd��dS)	NrLr_rr]rkrIr5r)rr1r;r�r2rTr,)r+rbr�rrrr��s
N
z!TestMedianLow.test_even_fractionscCs�t}|d�|d�|d�|d�|d�|d�g}t|�ddks^t�tj|�|j|j|�|d��dS)	Nz1.1z2.2z3.3z4.4z5.5z6.6rr)rr1r;r�r2rTr,)r+rgr�rrrr��s
<
z TestMedianLow.test_even_decimalsN)r"r#r$rNr}r�r�rrrrr��sr�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestMedianHighcCstj|_dS)N)r�Zmedian_highr,)r+rrrrN�szTestMedianHigh.setUpcCsQddddddg}t|�ddks4t�|j|j|�d�dS)NrLrr]rkrIr5r)r1r;rTr,)r+r�rrrr}�szTestMedianHigh.test_even_intscCs�t}|dd�|dd�|dd�|dd�|dd�|dd�g}t|�ddkspt�tj|�|j|j|�|dd��dS)	NrLr_rr]rkrIr5r)rr1r;r�r2rTr,)r+rbr�rrrr��s
N
z"TestMedianHigh.test_even_fractionscCs�t}|d�|d�|d�|d�|d�|d�g}t|�ddks^t�tj|�|j|j|�|d��dS)	Nz1.1z2.2z3.3z4.4z5.5z6.6rr)rr1r;r�r2rTr,)r+rgr�rrrr��s
<
z!TestMedianHigh.test_even_decimalsN)r"r#r$rNr}r�r�rrrrr��sr�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestMedianGroupedcCstj|_dS)N)r�Zmedian_groupedr,)r+rrrrN�szTestMedianGrouped.setUpcCstdddddddg}t|�ddks7t�|j|j|�d�dddddddg}t|�ddks�t�|j|j|�d�dd	d	dd
d
d
d
dddg}t|�ddks�t�|j|j|d�d
�dddddd
d
d
dddddddg}t|�ddksNt�|j|j|d�ddd�dS)Nrxr)�rBrrLg�+@rIrlr��r�g`3@rj�����g������4@rg:�0�yE>)r1r;rTr,r0)r+r�rrr�test_odd_number_repeated�s'3z*TestMedianGrouped.test_odd_number_repeatedcCsqddddddddddg
}t|�ddks@t�|j|j|d�d	d
d�ddd
d
d
dg}t|�ddks�t�|j|j|�dd
d�dddd
d
d
ddddddg}t|�ddks�t�|j|j|�d�dd
d
d
ddddddg
}t|�ddksTt�|j|j|�d�dS)NrIrlrBr�r�r�rrg�����*3@rg:�0�yE>r]rkg["8���@r5g@g@)r1r;r0r,rT)r+r�rrr�test_even_number_repeated�s$"*$z+TestMedianGrouped.test_even_number_repeatedcCspxidddtdd�td�fD]C}x:dD]2}|g|}|j|j|�t|��q2Wq%WdS)Ng333333@�Dg��ޗCr�rzz32.9714rrIrlr�)rrIrlr�)rrrTr,r	)r+rr\r�rrrrps+

z,TestMedianGrouped.test_repeated_single_valuecCs�t}|dd�|dd�|dd�|dd�|dd�g}t|�ddksdt�tj|�|j|j|�d�dS)	NrIrkr^r)r@rrLg@)rr1r;r�r2rTr,)r+rbr�rrrrs
B
z$TestMedianGrouped.test_odd_fractionscCs�t}|dd�|dd�|dd�|dd�|dd�|dd�g}t|�ddkspt�tj|�|j|j|�d�dS)	NrIrkr^r)r@rrg
@)rr1r;r�r2rTr,)r+rbr�rrrr�s
N
z%TestMedianGrouped.test_even_fractionscCst}|d�|d�|d�|d�|d�g}t|�ddksUt�tj|�|j|j|�d�dS)Nz5.5z6.5z7.5z8.5rrLg@)rr1r;r�r2rTr,)r+rgr�rrrr�%s
3
z#TestMedianGrouped.test_odd_decimalscCst}|d�|d�|d�|d�|d�|d�g}t|�ddks^t�tj|�|j|j|�d�|d�|d�|d�|d�|d�|d�g}t|�ddks�t�tj|�|j|j|�d�dS)	Nz5.5z6.5z7.5z8.5rrg@g@)rr1r;r�r2rTr,)r+rgr�rrrr�-s<
<
z$TestMedianGrouped.test_even_decimalscCs�ddddddddddg
}|j|j|d�d	�dddddddddddg}|j|j|d�d
dd�d
d
ddddddddddg}|j|j|d�d�dS)Ng@g@g@g@g
@g@g@g�?g@g["8���@rg:�0�yE>����iii,i@iTr�g�p@)rTr,r0)r+r�rrr�
test_interval:s$'"*zTestMedianGrouped.test_intervalN)r"r#r$rNr�r�rprr�r�r�r�rrrrr��s	
r�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestModecCstj|_dS)N)r��moder,)r+rrrrNFszTestMode.setUpcCs%dddddddddddgS)	z+Overload method from UnivariateCommonMixin.rLr]rkr_r^rrqrr)r+rrrr3IszTestMode.prepare_datacCs/tddd�}|jtj|j|�dS)Nr�r�r])r�r�r�r�r,)r+r�rrrr=NszTestMode.test_range_datacCsHd}|j|j|�d�dj�}|j|j|�d�dS)NZabcbdbr
zfe fi fo fum fi fiZfi)rTr,rf)r+r�rrr�test_nominal_dataSszTestMode.test_nominal_datacCs`ttd��}xGtd�D]9}||g}tj|�|j|j|�|�qWdS)Nrl)rr�r�r2rTr,)r+r�r7rhrrr�test_discrete_dataZs


zTestMode.test_discrete_datacCs�dddddddddddddddd	d	g}|jd�|jd�kobdknsmt�|jtj|j|�dS)
NrLrr]rkrIr5r_rqr^)r\r;r�r�r�r,)r+r�rrr�test_bimodal_databs94zTestMode.test_bimodal_datacCs/ttd��}|jtj|j|�dS)Nrl)rr�r�r�r�r,)r+r�rrr�test_unique_data_failureisz!TestMode.test_unique_data_failurecCs|jt|jd�dS)N)r�rr,)r+rrr�test_none_datanszTestMode.test_none_datacCs8tjddddg�}|jtj|j|�dS)NrLr)r'�Counterr�r�r�r,)r+r�rrr�test_counter_datauszTestMode.test_counter_dataN)r"r#r$rNr3r=r�r�r�r�r�r�rrrrr�Dsr�c@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�VarianceStdevMixing�-���q=cCsOxHdddtdd�td�fD]"}|j|j|g�d�q%WdS)Nryg������3@g���%�Bror�z8.392r)rrrTr,)r+rrrrrm�s+z$VarianceStdevMixin.test_single_valuecCsjxcdddtdd�td�fD]=}x4dD],}|g|}|j|j|�d
�q2Wq%WdS)Ng������@r�g@�6��<Cr]r_z62.4802rrIrBr)rr]rIrB)rrrTr,)r+rr\r�rrrrp�s+

z-VarianceStdevMixin.test_repeated_single_valuecCsFdgd}|j|�}|j|ddd�|j|d�dS)Ng.�F7ݚ�?i'grg��ؗ�Ҍ<r)r,r0r�)r+r�rWrrr�test_domain_error_regression�s
z/VarianceStdevMixin.test_domain_error_regressionc
soddddddddd	d
g
}|j|�}d��fdd
�|D�}|j|j|�|�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)�shiftrrr��s	z6VarianceStdevMixin.test_shift_data.<locals>.<listcomp>)r,r0)r+rCrr�r)r�r�test_shift_data�s
$z"VarianceStdevMixin.test_shift_datac
s�dddddddddd	g
}td
d�|D��sCt�|j|�}d��fdd
�|D�}|j|j|�|�dS)NrLr]rkrIr_r^rlryrjcss!|]}|t|�kVqdS)N)rN)r�rrrrr��sz;VarianceStdevMixin.test_shift_data_exact.<locals>.<genexpr>csg|]}|��qSrr)r�r)r�rrr��s	z<VarianceStdevMixin.test_shift_data_exact.<locals>.<listcomp>iʚ;)�allr;r,rT)r+rCrr�r)r�r�test_shift_data_exact�s$z(VarianceStdevMixin.test_shift_data_exactcCsKdd�td�D�}|j|�}|j|jt|��|�dS)NcSs"g|]}tjdd��qS)r]rqr�)r�r�)r�r�rrrr��s	z:VarianceStdevMixin.test_iter_list_same.<locals>.<listcomp>i�)r�r,rTr.)r+r�rrrr�test_iter_list_same�sz&VarianceStdevMixin.test_iter_list_sameN)
r"r#r$rrmrpr�r�r�r�rrrrr��s
	r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�
TestPVariancecCstj|_dS)N)r��	pvariancer,)r+rrrrN�szTestPVariance.setUpcCsBttd��}tj|�d}|j|j|�|�dS)Ni'rrLrxi�i��gP�_A)rr�r�r2rTr,)r+r�rrrr�test_exact_uniform�s
z TestPVariance.test_exact_uniformcCs5ddddg}d}|j|j|�|�dS)Nrkr_r)rjg�6@)rTr,)r+r��exactrrrrR�szTestPVariance.test_intscCs~t}|dd�|dd�|dd�|dd�g}|dd�}|j|�}|j||�|j|t�dS)NrLrkr]r_rq)rr,rT�assertIsInstance)r+rbr�r�rWrrrrT�s6zTestPVariance.test_fractionscCsot}|d�|d�|d�|d�g}|d�}|j|�}|j||�|j|t�dS)Nz12.1z12.2z12.5z12.9z0.096875)rr,rTr�)r+rgr�r�rWrrrrU�s*zTestPVariance.test_decimalsN)r"r#r$rNr�rRrTrUrrrrr��s
	r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestVariancecCstj|_dS)N)r��variancer,)r+rrrrN�szTestVariance.setUpcCsOxHdddtdd�td�fD]"}|jtj|j|g�q%WdS)Nr`g33333�8@g�(G�!=Crlr�z4.2084)rrr�r�r�r,)r+rrrrrm�s+zTestVariance.test_single_valuecCs5ddddg}d}|j|j|�|�dS)Nrkr_r)rjr�)rTr,)r+r�r�rrrrR�szTestVariance.test_intscCs~t}|dd�|dd�|dd�|dd�g}|dd�}|j|�}|j||�|j|t�dS)NrLrkr]r_r)rr,rTr�)r+rbr�r�rWrrrrT�s6zTestVariance.test_fractionscCs}t}|d�|d�|d�|d�g}d|d�|d�}|j|�}|j||�|j|t�dS)Nrr_r^rkz9.5r])rr,rTr�)r+rgr�r�rWrrrrUs*zTestVariance.test_decimalsN)r"r#r$rNrmrRrTrUrrrrr��s
	r�c@s(eZdZdd�Zdd�ZdS)�
TestPStdevcCstj|_dS)N)r�Zpstdevr,)r+rrrrNszTestPStdev.setUpcCsNdd�td�D�}tjtj|��}|j|j|�|�dS)NcSs"g|]}tjdd��qS)r@r�i��)r�r�)r�r�rrrr�s	z7TestPStdev.test_compare_to_variance.<locals>.<listcomp>i�)r�r
�sqrtr�r�rTr,)r+r�rrrr�test_compare_to_variancesz#TestPStdev.test_compare_to_varianceN)r"r#r$rNr�rrrrr�
sr�c@s4eZdZdd�Zdd�Zdd�ZdS)�	TestStdevcCstj|_dS)N)r�Zstdevr,)r+rrrrNszTestStdev.setUpcCsOxHdddtdd�td�fD]"}|jtj|j|g�q%WdS)N�QgH�z�wi@gf7?+�BrIroz35.719)rrr�r�r�r,)r+rrrrrms+zTestStdev.test_single_valuecCsNdd�td�D�}tjtj|��}|j|j|�|�dS)NcSs"g|]}tjdd��qS)rr^rM)r�r�)r�r�rrrr�"s	z6TestStdev.test_compare_to_variance.<locals>.<listcomp>i�)r�r
r�r�r�rTr,)r+r�rrrrr� sz"TestStdev.test_compare_to_varianceN)r"r#r$rNrmr�rrrrr�sr�cCs|jtj��|S)z&Used for doctest/unittest integration.)ZaddTestsr�ZDocTestSuite)�loaderZtests�ignorerrr�
load_tests)sr��__main__)7r%r'rer�r
r�r�r�rZ	fractionsrr�rrr r!r�r&r?rVrsr}r�r�r�r�r�r�r�r�rrr r+rErJrOr[r^rkrqr{r�r�r�r�r�r�r�r�r�r�r�r"�mainrrrr�<module>sh:+b>@w-@4d<c"H
@`9
b<B%#