
    daf                    6   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZmZ ddlmZ ddlmZ ddlZd Zd Zd	 Zdxd
Z G d d      Z ej6                  ddg      Z ej6                  ddg      Z G d dej<                        Z G d dej<                        Z  G d dej<                        Z! G d dej<                        Z" G d dej<                        Z# G d dej<                        Z$ G d dej<                        Z% G d d ej<                        Z& G d! d"ej<                        Z' G d# d$ej<                        Z( G d% d&ej<                        Z) G d' d(ej<                        Z* G d) d*ej<                        Z+ G d+ d,ej<                        Z, G d- d.ej<                        Z- G d/ d0ej<                        Z. G d1 d2ej<                        Z/ G d3 d4ej<                        Z0 G d5 d6ej<                        Z1 G d7 d8      Z2 G d9 d:      Z3 G d; d<e2e3      Z4 G d= d>e       Z5 G d? d@e       Z6 G dA dBe       Z7 G dC dDe2      Z8 G dE dFe e8e3      Z9 G dG dHe e8e3      Z: G dI dJe e8      Z; G dK dLe e3      Z< G dM dNe;e3      Z= G dO dPe;e3      Z> G dQ dRe;      Z? G dS dTe e8e3      Z@ G dU dVej<                        ZA G dW dXej<                        ZB G dY dZe2      ZC G d[ d\eCe e3      ZD G d] d^eCe e3      ZE G d_ d`eCe       ZF G da dbej<                        ZG G dc ddeCe       ZH G de dfej<                        ZI G dg dhej<                        ZJ G di djej<                        ZK G dk dlej<                        ZL G dm dnej<                        ZM G do dp      ZN G dq drej<                  eN      ZO ej                  eds       G dt duej<                  eN             ZQdv ZReSdwk(  r ej                          yy)yz_Test suite for statistics module, including helper NumericTestCase and
approx_equal function.

    N)support)import_helperrequires_IEEE_754)DecimalFractionc                 .    t        j                  d|       S )z:Return -1.0 for negatives, including -0.0, otherwise +1.0.   )mathcopysignxs    //root/Python-3.12.4/Lib/test/test_statistics.pysignr      s    ==A    c                 
   t        |       t        |      uryt        | t              r,t        j                  |       xr t        j                  |      S | j                         d   }|j                         d   }||k(  xr |dv S )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   isnanas_tuple)abaexpbexps       r   
_nan_equalr   #   sn    , Awd1g!Uzz!}.A.::<?D::<?DDL2tz12r   c                     t        t        |       t        |            }t        | |z
        }|r||z  n
t        d      }||fS )zReturn 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_errs        r   _calc_errorsr)   B   sC     s6{CM*D&8#$G"gdleGWr   c           
      `   |dk  s|dk  rt        d      t        j                  |       st        j                  |      ry| |k(  ryt        j                  |       st        j                  |      ryt	        | |z
        }t        ||t        t	        |       t	        |            z        }||k  S )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.
    r   z%error tolerances must be non-negativeFT)
ValueErrorr   r   isinfr#   r"   )r   ytolrelactual_errorallowed_errors         r   approx_equalr2   R   s    D Qw#'@AAzz!}

1Avzz!}

1 q1u:LSSVSV!445M=((r   c                       e Zd ZdZy)
_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__ r   r   r4   r4      s    "F 	r   r4   
statistics_statistics)blocked)freshc                   J    e Zd ZdgZd Z ej                  ed      d        Zy)TestModules_normal_dist_inv_cdfc                 z    | j                   D ],  }| j                  t        t        |      j                  d       . y Nr:   )
func_namesassertEqualgetattrpy_statisticsr6   selffnames     r   test_py_functionszTestModules.test_py_functions   s4    __ 	UEW]E:EE|T	Ur   requires _statisticsc                 z    | j                   D ],  }| j                  t        t        |      j                  d       . y )Nr;   )rC   rD   rE   c_statisticsr6   rG   s     r   test_c_functionszTestModules.test_c_functions   s4    __ 	UEW\59DDmT	Ur   N)	r5   r6   r7   rC   rJ   unittest
skipUnlessrM   rN   r9   r   r   r?   r?      s6    ()JU X'=>U ?Ur   r?   c                   @    e Zd ZdZdxZZ	 ddZd Zd	dZe	d        Z
y)
NumericTestCasezUnit test class for numeric work.

    This subclasses TestCase. In addition to the standard method
    ``TestCase.assertAlmostEqual``,  ``assertApproxEqual`` is provided.
    r   Nc                    || j                   }|| j                  }t        |t        j                  j
                        r1t        |t        j                  j
                        r| j                  }n| j                  } ||||||       y)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)rH   firstsecondr.   r/   msgchecks          r   assertApproxEqualz!NumericTestCase.assertApproxEqual   sn    > ;((C;((C5+//":":;6;??#;#;<**E**EeVS#s+r   c           	         t        |      t        |      k7  r<dt        |      t        |      fz  }| j                  ||      }| j                  |      t        t	        ||            D ]  \  }\  }}	| j                  ||	||||         y )Nz0sequences differ in length: %d items != %d items)len_formatMessagefailureException	enumerateziprX   )
rH   rY   rZ   r.   r/   r[   standardMsgir   es
             r   rW   z!NumericTestCase._check_approx_seq   s    u:V$Bu:s6{+,  %%c;7C'',,!#eV"45 	;HAu!""1ac3:	;r   c                     t        ||||      ry | j                  |||||      }| j                  ||      }| j                  |      N)r2   _make_std_err_msgr`   ra   )rH   rY   rZ   r.   r/   r[   idxrd   s           r   rX   z!NumericTestCase._check_approx_num
  sN    vsC0,,UFCcJ!!#{3##C((r   c                 `    | |k7  sJ d}|
d|z  }||z   }t        | |      \  }}|| |||||fz  S )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)   )	rY   rZ   r.   r/   rj   templateheaderr'   r(   s	            r   ri   z!NumericTestCase._make_std_err_msg  s^     ' 	 ?DsJF(H'v65&#sGWEEEr   )NNNrh   )r5   r6   r7   r8   r.   r/   r]   rW   rX   staticmethodri   r9   r   r   rR   rR      s=     MC# :>*,X	;) F Fr   rR   c                       e Zd ZdZd Zy)TestSignz5Test that the helper function sign() works correctly.c                 p    | j                  t        d      d       | j                  t        d      d       y )N        r
   g       )rD   r   rH   s    r   
testZeroeszTestSign.testZeroes+  s*    cB'dR(r   N)r5   r6   r7   r8   ru   r9   r   r   rp   rp   )  s
    ?)r   rp   c                   $    e Zd Zd Zd Zd Zd Zy)ApproxEqualSymmetryTestc                     dddt        d      t        dd      g}ddd	t        d
      t        dd      g}t        |      t        |      k(  sJ t        ||      D ]  \  }}| j	                  ||        y )Ni	  gfffffB@gfffff(z2.54   6   i	  gB@gR(z2.59   )r   r   r_   rc   do_relative_symmetry)rH   args1args2r   r   s        r   test_relative_symmetryz.ApproxEqualSymmetryTest.test_relative_symmetry6  sz     tVWV_hr26FGtVWV_hr26FG5zSZ'''u% 	,DAq%%a+	,r   c                    t        ||      t        ||      }}||k  sJ ||z
  }t        ||z        t        ||z        }}||z   dz  }| j                  t	        ||d|             | j                  t	        ||d|             y )Nr   r   r.   r/   )minr"   r#   
assertTruer2   )rH   r   r   deltarel_err1rel_err2r/   s          r   r|   z,ApproxEqualSymmetryTest.do_relative_symmetryF  s    1ay#a)11uuA q\3uQw<(("A% 	Qqc:;Qqc:;r   c           	      (   g d}d}|D ]  }t         t        t        t        fD ]  } ||      dz  }||z   }t	        |t        ||      z        }| j                  ||||       | j                  |||dz   d|z         | j                  |||dz
  |dz         | j                  ||||dz         | j                  |||dz
  |       | j                  |||dz
  d|z         | j                  ||dd       | j                  ||dd        	 y )N)i   k   im r   d   r   r
   r   )intr   r   r   r#   r"   do_symmetry_test)rH   argsr   r   type_r   r-   rs           r   test_symmetryz%ApproxEqualSymmetryTest.test_symmetryR  s7   ' 	:Augx8 :!HSLIc!Qi( %%a1%=%%aaQqS%A%%aaQqS%A%%a1Q3%?%%aaQ%?%%aaQqS%A%%aq%9%%aq%9#:	:r   c           
          d}t        ||||      }t        ||||      }| j                  |||j                  ||||f             y )Nz+approx_equal comparisons don't match for %r)r2   rD   format)rH   r   r   r.   r/   rl   flag1flag2s           r   r   z(ApproxEqualSymmetryTest.do_symmetry_testj  sK    @Q3,Q3,x1c37G'HIr   N)r5   r6   r7   r   r|   r   r   r9   r   r   rw   rw   3  s    , 
<:0Jr   rw   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)ApproxEqualExactTestc                     t        ||||      }| j                  |d|z         t        | | ||      }| j                  |d| z         y )Nr   zequality failure for x=%r)r2   r   )rH   r   r.   r/   results        r   do_exactly_equal_testz*ApproxEqualExactTest.do_exactly_equal_testw  sP    a5 ;a ?@qb1"#37 ;qb @Ar   c                 8    dD ]  }| j                  |dd        y )N)*   iM  i~:     i  iU
 i  r   r   rH   r   s     r   test_exactly_equal_intsz,ApproxEqualExactTest.test_exactly_equal_ints}  s#    = 	0A&&q!Q/	0r   c                 8    dD ]  }| j                  |dd        y )N)gzG?g/$?ge@g      7@g     pf@g!rhQ@gB`"KB@r   r   rH   r   s     r   test_exactly_equal_floatsz.ApproxEqualExactTest.test_exactly_equal_floats  s#    E 	0A&&q!Q/	0r   c           	          t         } |dd       |d       |dd       |dd       |dd	       |dd      fD ]  }| j                  |dd        y )
Nr
   r   r   r      	      #   $   )r   r   rH   Ffs      r   test_exactly_equal_fractionsz1ApproxEqualExactTest.test_exactly_equal_fractions  sW    Aq'1Q41a!Aq'1R9a1gF 	0A&&q!Q/	0r   c                 t    t         }t        |dj                               D ]  }| j                  |dd        y )Nz8.2 31.274 912.04 16.745 1.2047r   )r   mapsplitr   )rH   Dds      r   test_exactly_equal_decimalsz0ApproxEqualExactTest.test_exactly_equal_decimals  s9    Q9??AB 	0A&&q!Q/	0r   c                     dD ]J  }| j                  |dd       | j                  |dz  dd       t        |d      }| j                  |dd       L y )N)   i  i\  i  i     {Gz?r   
   i  )r   r   )rH   r   r   s      r   test_exactly_equal_absolutez0ApproxEqualExactTest.test_exactly_equal_absolute  sW    / 	3A&&q$2&&qtT15D!A&&q$2	3r   c                     | j                  t        d      t        d      d       | j                  t        d       t        d      d       y )Nz3.5710.01r   z81.3971)r   r   rt   s    r   $test_exactly_equal_absolute_decimalsz9ApproxEqualExactTest.test_exactly_equal_absolute_decimals  s;    ""77#3WV_aH""GI$6#6Kr   c                     dddt        dd      fD ]  }| j                  |dd        | j                  t        d      dt        d	             y )
Ni   g33333SY@gzGr      r   r   z11.68r   r   r   r   r   s     r   test_exactly_equal_relativez0ApproxEqualExactTest.test_exactly_equal_relative  sM    x!R9 	3A&&q!T2	3""77#3QHr   c                     dddt        dd      fD ]  }| j                  |dd        t        }| j                   |d       |d	       |d
             y )Ni9  gˡE0@g\(hr      皙?r   z7.2z0.1r   r   )rH   r   r   s      r   test_exactly_equal_bothz,ApproxEqualExactTest.test_exactly_equal_both  sU    (1a.9 	5A&&q#t4	5""1U8QuXqyAr   N)r5   r6   r7   r   r   r   r   r   r   r   r   r   r9   r   r   r   r   q  s3    B0
0
00	3L
IBr   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)ApproxEqualUnequalTestc                 f    || fD ])  }t        ||dz   dd      }| j                  |d|z         + y )Nr
   r   r   zinequality failure for x=%r)r2   assertFalse)rH   r   r   r   s       r   do_exactly_unequal_testz.ApproxEqualUnequalTest.do_exactly_unequal_test  sC    aR 	HA!!QqSaQ7FV%BQ%FG	Hr   c                 4    dD ]  }| j                  |        y )N)i  i i  i  iXC  r   r   s     r   test_exactly_unequal_intsz0ApproxEqualUnequalTest.test_exactly_unequal_ints  s    / 	,A((+	,r   c                 4    dD ]  }| j                  |        y )N)gQ#@g[@gfffffG@gףp=
W"@g=
ףp=1@r   r   s     r   test_exactly_unequal_floatsz2ApproxEqualUnequalTest.test_exactly_unequal_floats  s    3 	,A((+	,r   c                     t         } |dd       |dd       |dd       |dd      fD ]  }| j                  |        y )	Nr
   r   r   r         e   iς )r   r   r   s      r   test_exactly_unequal_fractionsz5ApproxEqualUnequalTest.test_exactly_unequal_fractions  sE    Aq'1Q7Ab"Iqe}= 	,A((+	,r   c                 l    t        t        dj                               D ]  }| j                  |        y )Nz!3.1415 298.12 3.47 18.996 0.00245)r   r   r   r   rH   r   s     r   test_exactly_unequal_decimalsz4ApproxEqualUnequalTest.test_exactly_unequal_decimals  s0    WAGGIJ 	,A((+	,r   N)r5   r6   r7   r   r   r   r   r   r9   r   r   r   r     s    H
,
,
,,r   r   c                   l    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)ApproxEqualInexactTestc           	          d}||z   ||z
  fD ]X  }|j                  ||      }| j                  t        ||d|z  d      |       | j                  t        |||dz  d      |       Z y )NTest failure for x={!r}, y={!r}r   r   r   r   r   r2   r   rH   r   r   rl   r-   r[   s         r   do_approx_equal_abs_testz/ApproxEqualInexactTest.do_approx_equal_abs_test  sq    4e)QY' 	JA//!Q'COOLA1U7BCH\!QE!GCSI	Jr   c                 Z    dD ]&  }| j                  |d       | j                  |d       ( y )N)iiIir   r   r
   r   %   i  i&  i6jr   r   r   r   s     r   test_approx_equal_absolute_intsz6ApproxEqualInexactTest.test_approx_equal_absolute_ints  s1    J 	0A))!R0))!Q/	0r   c                 ~    dD ]8  }| j                  |d       | j                  |d       | j                  |d       : y )N)	gtqgfffffFXg333333g333333      ?      ?g333333@gQ@gҭ@      ?r   -C6?r   r   s     r   !test_approx_equal_absolute_floatsz8ApproxEqualInexactTest.test_approx_equal_absolute_floats  sA    L 	5A))!S1))!T2))!V4	5r   c                     t        dd      }g d}d |D        D ]/  }| j                  ||       | j                  |t        |             1 y )Nr
      )ir   rs   r   r
   r   ry      "   G   c              3   4   K   | ]  }t        |d         yw)r   Nr   ).0r   s     r   	<genexpr>zNApproxEqualInexactTest.test_approx_equal_absolute_fractions.<locals>.<genexpr>  s     6a(1b/6s   )r   r   r   )rH   r   
numeratorsr   s       r   $test_approx_equal_absolute_fractionsz;ApproxEqualInexactTest.test_approx_equal_absolute_fractions  sJ    B@
6:6 	;A))!U3))!U5\:	;r   c                     t        d      }t        t         dj                               D ]'  }| j                  ||       | j                  | |       ) y )Nr   z1.0 3.5 36.08 61.79 7912.3648)r   r   r   r   )rH   r   r   s      r   #test_approx_equal_absolute_decimalsz:ApproxEqualInexactTest.test_approx_equal_absolute_decimals  sM    W=CCEF 	5A))!U3))1"e4	5r   c                 @    | j                  t        dddd             y )Ngh㈵>gh㈵r   r   r   )r   r2   rt   s    r   test_cross_zeroz&ApproxEqualInexactTest.test_cross_zero  s    T5dBCr   c           
          d}|d|z   z  |d|z
  z  fD ]X  }|j                  ||      }| j                  t        ||dd|z        |       | j                  t        ||d|dz        |       Z y )Nr   r
   r   r   r   r   r   s         r   do_approx_equal_rel_testz/ApproxEqualInexactTest.do_approx_equal_rel_test  sy    4QuW+q!E'{+ 	JA//!Q'COOLA1!E'BCH\!QA57CSI	Jr   c                 0   | j                  t        dddd             | j                  t        dddd             | j                  t        dddd	             | j                  t        d
ddd	             | j                  t        dddd	             y )N@   /   r   g
ףp=
?r   gGz?i  i         ?i  i  )r   r2   r   rt   s    r   test_approx_equal_relative_intsz6ApproxEqualInexactTest.test_approx_equal_relative_ints  sw    R=>R=>S#1%@AS#1%@Ac3A5ABr   c                 Z    dD ]&  }| j                  |d       | j                  |d       ( y )N)g{GJf皙r   r   g\(|B@gʡE>@gx@{Gz?r   )r   r   s     r   !test_approx_equal_relative_floatsz8ApproxEqualInexactTest.test_approx_equal_relative_floats  s1    E 	5A))!T2))!V4	5r   c                     t         }t        dd      } |dd       |dd       |dd       |dd	      fD ]9  }|t        |      fD ]'  }| j                  ||       | j                  | |       ) ; y )
Nr   r   T   ry      1   2   \   U   )r   r   r   )rH   r   r   r   r   s        r   $test_approx_equal_relative_fractionsz;ApproxEqualInexactTest.test_approx_equal_relative_fractions  s|    AAr(Ab"IqRy!B)< 	5AU5\* 5--a3--qb!45	5r   c                     t        t        dj                               D ]9  }| j                  |t        d             | j                  | t        d             ; y )Nz$0.02 1.0 5.7 13.67 94.138 91027.93210.0010.05)r   r   r   r   r   s     r   #test_approx_equal_relative_decimalsz:ApproxEqualInexactTest.test_approx_equal_relative_decimals  sM    WDJJLM 	?A))!WW-=>))1"gfo>	?r   c                 "   |r| j                   n| j                  } |t        |||d             |r| j                   n| j                  } |t        ||d|             |s|r| j                   n| j                  } |t        ||||             y )Nr   r   )r   r   r2   )rH   r   r   r.   r/   tol_flagrel_flagr\   s           r   do_check_bothz$ApproxEqualInexactTest.do_check_both,  sv    #+1A1Al1aSa01#+1A1Al1aQC01$,t?O?Ol1aSc23r   c                 \    | j                  dddddd       | j                  dddd	dd       y )
NR@+@Mbp?W8?Tg?5^Ig%CMb`?g-C6*?r  rt   s    r   test_approx_equal_both1z.ApproxEqualInexactTest.test_approx_equal_both14  s2    5%dC665&$Er   c                 0    | j                  dddddd       y )Nr  r  r  gVF?8?TFr  rt   s    r   test_approx_equal_both2z.ApproxEqualInexactTest.test_approx_equal_both29  s    5%eDr   c                 0    | j                  dddddd       y )Nr  r  MbP?r  FTr  rt   s    r   test_approx_equal_both3z.ApproxEqualInexactTest.test_approx_equal_both3=  s    5%tDr   c                 \    | j                  dddddd       | j                  dddd	dd       y )
Ng=
ףp=@      @r   r  FgQ[@g(\[@r   giUMu>r  rt   s    r   test_approx_equal_both4z.ApproxEqualInexactTest.test_approx_equal_both4A  s2    4tUE5A664ueDr   N)r5   r6   r7   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r!  r9   r   r   r   r     sZ    J05;5DJC55?4F
EEEr   r   c                   $    e Zd Zd Zd Zd Zd Zy)ApproxEqualSpecialsTestc           	         t         t        fD ]  } |d      }| j                  t        ||             | j                  t        ||dd             | j                  t        ||dd             | j                  t        | |              | j	                  t        ||              | j	                  t        |d              y )Nr!   r   r
   r     )r   r   r   r2   r   )rH   r   r!   s      r   test_infz ApproxEqualSpecialsTest.test_infJ  s    W% 	6E,COOLc23OOLc1a89OOLc1d;<OOL#t45\#t45\#t45	6r   c                     t         t        fD ]5  } |d      }| |d      dfD ]  }| j                  t        ||              7 y )Nnanr!   r%  )r   r   r   r2   )rH   r   r(  others       r   test_nanz ApproxEqualSpecialsTest.test_nanT  sN    W% 	;E,CuU|T2 ;  c5!9:;	;r   c                 l    t        j                  dd      }| j                  t        |ddd             y )Nrr   rs   r   r   )r   r   r   r2   rH   nzeros     r   test_float_zeroesz)ApproxEqualSpecialsTest.test_float_zeroesZ  s)    c2&UCScBCr   c                 h    t        d      }| j                  t        |t        d      dd             y )Nz-0.0r   r   r   )r   r   r2   r,  s     r   test_decimal_zeroesz+ApproxEqualSpecialsTest.test_decimal_zeroes^  s&    UGAJCSIJr   N)r5   r6   r7   r&  r*  r.  r0  r9   r   r   r#  r#  G  s    6;DKr   r#  c                       e Zd Zd Zd Zy)TestApproxEqualErrorsc                 @    | j                  t        t        dddd       y )Nr   rs   r   assertRaisesr+   r2   rt   s    r   test_bad_tolz"TestApproxEqualErrors.test_bad_tolf  s    *lCb#Fr   c                 @    | j                  t        t        dddd       y )Nr   r
   r   r4  rt   s    r   test_bad_relz"TestApproxEqualErrors.test_bad_relj  s    *lCaFr   N)r5   r6   r7   r6  r8  r9   r   r   r2  r2  c  s    GGr   r2  c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestNumericTestCasec                 x    t        j                  | } | j                  | }|D ]  }| j                  ||        y rh   )rR   ri   generate_substringsassertIn)rH   r   
actual_msgr%   	substrings        r   do_testzTestNumericTestCase.do_testz  sA    $66=
+4++T2! 	1IMM)Z0	1r   c                 ^    | j                  t        t        t        j                               y rh   )r   
issubclassrR   rO   TestCasert   s    r    test_numerictestcase_is_testcasez4TestNumericTestCase.test_numerictestcase_is_testcase  s    
?H4E4EFGr   c                 *    d}| j                  |       y )N)      @      @r         ?Nr@  rH   r   s     r   test_error_msg_numericz*TestNumericTestCase.test_error_msg_numeric  s    *Tr   c                 *    d}| j                  |       y )N)      @g      @g      ?r   r   rI  rJ  s     r   test_error_msg_sequencez+TestNumericTestCase.test_error_msg_sequence  s    )Tr   c                 t    t        ||      \  }}d|z  d|z  d|z  d|z  g}||j                  d|z         |S )z5Return substrings we expect to see in error messages.ztol=%rzrel=%rzabsolute error = %rzrelative error = %rzdiffer at index %d)r)   append)	rH   rY   rZ   r.   r/   rj   r'   r(   
substringss	            r   r<  z'TestNumericTestCase.generate_substrings  sY    'v633%/%/	
 ?2S89r   N)r5   r6   r7   r@  rD  rK  rN  r<  r9   r   r   r:  r:  t  s    1H

r   r:  c                   $    e Zd ZeZddgZd Zd Zy)GlobalsTestr8   __all__c                 x    | j                   D ]+  }| j                  t        | j                  |      d|z         - y )Nz%s not present)expected_metadatar   hasattrmodule)rH   metas     r   	test_metazGlobalsTest.test_meta  s8    ** 	5DOOGDKK6,t35	5r   c                     | j                   }|j                  D ]E  }| j                  |j                  d      d|z         | j	                  t        ||      d|z         G y )N_zprivate name "%s" in __all__zmissing name "%s" in __all__)rX  rT  r   
startswithr   rW  )rH   rX  names      r   test_check_allzGlobalsTest.test_check_all  sb    NN 	CDT__S1;dBD OOGFD1:TAC	Cr   N)r5   r6   r7   r:   rX  rV  rZ  r_  r9   r   r   rS  rS    s    F"I.5	Cr   rS  c                   l    e Zd Z ej                  ej                  j                  dk\  d      d        Zy)DocTestsr   z)Docstrings are omitted with -OO and abovec                     t        j                  t        t         j                        \  }}| j	                  |d       | j                  |d       y )N)optionflagsr   )doctesttestmodr:   ELLIPSISassertGreaterrD   )rH   failedtrieds      r   test_doc_testszDocTests.test_doc_tests  s>      
@P@PQ5!$#r   N)	r5   r6   r7   rO   skipIfsysflagsoptimizerj  r9   r   r   ra  ra    s5    X__SYY''1,@B$B$r   ra  c                       e Zd Zd Zy)StatisticsErrorTestc                     d}| j                  t        t        d             | j                  t        t        j                  t
              |t        j                  j                  z         y )NzNExpected StatisticsError to be a ValueError, but got a subclass of %r instead.StatisticsError)r   rW  r:   rB  rr  r+   __base__)rH   errmsgs     r   test_has_exceptionz&StatisticsErrorTest.test_has_exception  sR    + 	 	
,=>?:55zB33<<<	r   N)r5   r6   r7   ru  r9   r   r   rp  rp    s    	r   rp  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ExactRatioTestc                 `    dD ])  }| j                  t        j                  |      |df       + y )N)ir   r   c   l      Fx:^V r
   )rD   r:   _exact_ratio)rH   re   s     r   test_intzExactRatioTest.test_int  s2    , 	AAZ44Q7!Q@	Ar   c                 |    d}|D ]5  }t        |d      }| j                  t        j                  |      |df       7 y )N)r
   r   &   r   )r   rD   r:   r{  )rH   r   r   r   s       r   test_fractionzExactRatioTest.test_fraction  sB    $
 	BABAZ44Q7!RA	Br   c                 b   | j                  t        j                  d      d       | j                  t        j                  d      d       t        d      D cg c]  }t	        j
                  dd       }}|D ]/  }t        j                  |      \  }}| j                  |||z         1 y c c}w )Nr   r
   r         ?)r   r   r   )rD   r:   r{  rangerandomuniform)rH   r\  datar   numdens         r   
test_floatzExactRatioTest.test_float  s    007@007@38:>atS)>> 	)A!..q1HCQC(	) ?s   B,c                     t         }t        j                  }| j                   | |d            d       | j                   | |d            d       | j                   | |d            d       y )Nz0.125r  z12.345)i	     z-1.98)ir  )r   r:   r{  rD   )rH   r   r{  s      r   test_decimalzExactRatioTest.test_decimal  s]    !..aj16:ak2K@aj19=r   c                 |   t        d      } G d dt               } G d dt              }|| fD ]  }t         |t        |fD ]x  } ||      }t        j                  |      }| j	                  ||d f       | j	                  t        |d         |       | j                  t        j                  |d                z  y )NINFc                       e Zd Zy)(ExactRatioTest.test_inf.<locals>.MyFloatNr5   r6   r7   r9   r   r   MyFloatr        r   r  c                       e Zd Zy)*ExactRatioTest.test_inf.<locals>.MyDecimalNr  r9   r   r   	MyDecimalr    r  r   r  r   )	r   r   r:   r{  rD   r   r   r   r,   )rH   r  r  r  r!   r   r   ratios           r   r&  zExactRatioTest.test_inf  s    El	e 		 	#; 	6C'9= 6#J"//2  D	2  eAh7

58 456	6r   c                 F   t        d      } G d dt               }| ||      fD ]z  }t        j                  |      }| j                  t	        j
                  |d                | j                  |d   d        | j                  t        |d         t        |             | y )NNANc                       e Zd Zy).ExactRatioTest.test_float_nan.<locals>.MyFloatNr  r9   r   r   r  r    r  r   r  r   r
   )	r   r:   r{  r   r   r   assertIsrD   r   )rH   r  r  r(  r  s        r   test_float_nanzExactRatioTest.test_float_nan  s    El	e 	& 	8C++C0EOODJJuQx01MM%(D)T%(^T#Y7		8r   c                 Z   t        d      }t        d      } G d dt               }| ||      | ||      fD ]q  }t        j                  |      }| j                  t	        |d   |             | j                  |d   d        | j                  t        |d         t        |             s y )Nr  sNANc                       e Zd Zy)2ExactRatioTest.test_decimal_nan.<locals>.MyDecimalNr  r9   r   r   r  r    r  r   r  r   r
   )r   r:   r{  r   r   r  rD   r   )rH   r  r  r  r(  r  s         r   test_decimal_nanzExactRatioTest.test_decimal_nan  s    env	 	3y? 	8C++C0EOOJuQx56MM%(D)T%(^T#Y7		8r   N)
r5   r6   r7   r|  r  r  r  r&  r  r  r9   r   r   rw  rw    s'    AB)>68	8r   rw  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)DecimalToRatioTestc                     t        d      }| j                  t        j                  |      |d f       | j                  t        j                  |       | d f       y )Nr  )r   rD   r:   r{  )rH   r!   s     r   test_infinityz DecimalToRatioTest.test_infinity  sM    en005T{C00#6#tEr   c                     t        d      t        d      fD ]G  }t        j                  |      \  }}| j                  t	        ||             | j                  |d        I y )Nr  r  )r   r:   r{  r   r   r  )rH   r(  r  r  s       r   r*  zDecimalToRatioTest.test_nan  sU    ENGFO4 	%C!..s3HC OOJsC01MM#t$	%r   c                 >   t        d      t        d      g}|D ]  }|dkD  sJ t        j                  |      \  }}| j                  |d       | j	                  |d       t        j                  |       \  }}| j                  |d       | j	                  |d        y )Nz	9.8765e12z
9.8765e-12r   )r   r:   r{  assertGreaterEqualrg  assertLessEqual)rH   numbersr   r  r  s        r   	test_signzDecimalToRatioTest.test_sign!  s    ;')>? 		'Aq5L5!..q1HC##C+sA&!..r2HC  a(sA&		'r   c                 d    t        j                  t        d            }| j                  |d       y )Nz0.1234)ii    r:   r{  r   rD   rH   ts     r   test_negative_exponentz)DecimalToRatioTest.test_negative_exponent/  s'    ##GH$56K(r   c                 d    t        j                  t        d            }| j                  |d       y )Nz1.234e7)i K r
   r  r  s     r   test_positive_exponentz)DecimalToRatioTest.test_positive_exponent4  s'    ##GI$67M*r   c                     t        j                  t        d            }| j                  |d       t        j                  t        d            }| j                  |d       y )N1e2)r   r
   z1.47e5)i8> r
   r  r  s     r   test_regression_20536z(DecimalToRatioTest.test_regression_205369  sM     ##GEN3H%##GH$56K(r   N)	r5   r6   r7   r  r*  r  r  r  r  r9   r   r   r  r    s!    F%')
+
)r   r  c                       e Zd Zd Zd Zd Zy)IsFiniteTestc                     dt        dd      dt        d      fD ]&  }| j                  t        j                  |             ( y )Nr   r
   r   rF  5.5)r   r   r   r:   	_isfiniter   s     r   test_finitezIsFiniteTest.test_finiteE  s;    Xa^S'%.9 	5AOOJ0034	5r   c                     t        d      t        d      fD ]&  }| j                  t        j                  |             ( y Nr!   r   r   r   r:   r  r   s     r   r  zIsFiniteTest.test_infinityJ  s7    ,/ 	6AZ11!45	6r   c                     t        d      t        d      t        d      fD ]&  }| j                  t        j                  |             ( y Nr(  r  r  r  r   s     r   r*  zIsFiniteTest.test_nanO  s=    ,@ 	6AZ11!45	6r   N)r5   r6   r7   r  r  r*  r9   r   r   r  r  B  s    5
6
6r   r  c                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)
CoerceTestc                     t         t        t        t        fD ]a  }| j	                  t        j                  |t              |        G d d|      }| j	                  t        j                  |t              |       c y )Nc                       e Zd Zy)%CoerceTest.test_bool.<locals>.MyClassNr  r9   r   r   MyClassr  p      r   r  )r   r   r   r   r  r:   _coercebool)rH   Tr  s      r   	test_boolzCoerceTest.test_boolj  s\     uh0 	FAMM*,,Q5q9"!"MM*,,Wd;WE	Fr   c                     | j                  t        j                  ||      |       | j                  t        j                  ||      |       y)z Assert that type A coerces to B.N)r  r:   r  rH   ABs      r   assertCoerceTozCoerceTest.assertCoerceTos  s8    j((A.2j((A.2r   c                     | j                  ||        G d d|      }| j                  ||        G d d|      }| j                  ||       | j                  ||       y)z6Checks that type A coerces to B, including subclasses.c                       e Zd Zy)/CoerceTest.check_coerce_to.<locals>.SubclassOfANr  r9   r   r   SubclassOfAr  }  r  r   r  c                       e Zd Zy)/CoerceTest.check_coerce_to.<locals>.SubclassOfBNr  r9   r   r   SubclassOfBr    r  r   r  N)r  )rH   r  r  r  r  s        r   check_coerce_tozCoerceTest.check_coerce_tox  sT     	Aq!"!"K+"!"A{+K5r   c                     | j                  t        t        j                  ||f       | j                  t        t        j                  ||f       y)z=Assert that coercing A to B, or vice versa, raises TypeError.N)r5  	TypeErrorr:   r  r  s      r   assertCoerceRaiseszCoerceTest.assertCoerceRaises  s:    )Z%7%7!Q@)Z%7%7!Q@r   c                 J   |t         usJ | j                  t        j                  ||      |        G d d|      } G d d|      } G d d|      }|||fD ]  }| j	                  ||        | j	                  ||       | j                  ||       | j                  ||       y)z>Check that type T coerces correctly with subclasses of itself.c                       e Zd Zy)*CoerceTest.check_type_coercions.<locals>.UNr  r9   r   r   Ur    r  r   r  c                       e Zd Zy)*CoerceTest.check_type_coercions.<locals>.VNr  r9   r   r   Vr    r  r   r  c                       e Zd Zy)*CoerceTest.check_type_coercions.<locals>.WNr  r9   r   r   Wr    r  r   r  N)r  r  r:   r  r  r  )rH   r  r  r  r  typs         r   check_type_coercionszCoerceTest.check_type_coercions  s    }}j((A.2q!9 	(C3'	(Aq!1%1%r   c                     | j                  t               t        t        t        fD ]  }| j                  t        |        y rh   )r  r   r   r   r   r  )rH   r  s     r   r|  zCoerceTest.test_int  s6    !!#&8W- 	+C  c*	+r   c                 b    | j                  t               | j                  t        t               y rh   )r  r   r  r   rt   s    r   r  zCoerceTest.test_fraction  s     !!(+Xu-r   c                 .    | j                  t               y rh   )r  r   rt   s    r   r  zCoerceTest.test_decimal  s    !!'*r   c                 .    | j                  t               y rh   )r  r   rt   s    r   r  zCoerceTest.test_float  s    !!%(r   c                     t         t        t        d       t        t        fD ]/  }t
        t        t        t        fD ]  }| j                  ||        1 y rh   )
strlistr   tupledictr   r   r   r   r  )rH   bad_type	good_types      r   test_non_numeric_typesz!CoerceTest.test_non_numeric_types  sH    dDJt< 	=H!5(G< =	''	8<=	=r   c                     t         t        fD ]9  } G d d|      }| j                  |t               | j                  |t               ; y )Nc                       e Zd Zy)6CoerceTest.test_incompatible_types.<locals>.MySubclassNr  r9   r   r   
MySubclassr    r  r   r  )r   r   r  r   )rH   r  r  s      r   test_incompatible_typesz"CoerceTest.test_incompatible_types  s>    " 	9A%Q%##Aw/##J8	9r   N)r5   r6   r7   r  r  r  r  r  r|  r  r  r  r  r  r9   r   r   r  r  U  s;    *F3

6A
& +.
+)=
9r   r  c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
ConvertTestc                 p    | j                  ||       | j                  t        |      t        |             y)z5Check that x equals y, and has the same type as well.N)rD   r  r   rH   r   r-   s      r   check_exact_equalzConvertTest.check_exact_equal  s(    Ad1gtAw'r   c                     t        j                  t        d      t              }| j	                  |d        G d dt              }t        j                  t        d      |      }| j	                  | |d             y )Nr   c                       e Zd Zy)#ConvertTest.test_int.<locals>.MyIntNr  r9   r   r   MyIntr    r  r   r  ry   )r:   _convertr   r   r  )rH   r   r  s      r   r|  zConvertTest.test_int  sZ    c2q"%Ce4q%),r   c                    t        j                  t        dd      t              }| j                  |t        dd              G d dt              }t        j                  t        dd      |      }| j                  | |dd             y )N_   rz  c                        e Zd Z fdZ xZS )-ConvertTest.test_fraction.<locals>.MyFractionc                 @    | j                  t        | 	  |            S rh   	__class__super__truediv__rH   r)  r  s     r   r  z9ConvertTest.test_fraction.<locals>.MyFraction.__truediv__      ~~eg&9%&@AAr   r5   r6   r7   r  __classcell__r  s   @r   
MyFractionr
        B Br   r  r      )r:   r  r   r  )rH   r   r  s      r   r  zConvertTest.test_fraction  sr    R 0(;q(2r"23	B 	B R 0*=q*R"45r   c                     t        j                  t        dd      t              }| j	                  |d        G d dt              }t        j                  t        dd      |      }| j	                  | |d             y )	Nrs   r   g      c                        e Zd Z fdZ xZS )'ConvertTest.test_float.<locals>.MyFloatc                 @    | j                  t        | 	  |            S rh   r  r  s     r   r  z3ConvertTest.test_float.<locals>.MyFloat.__truediv__  r  r   r  r  s   @r   r  r    r  r   r  r   r   r  )r:   r  r   r   r  )rH   r   r  s      r   r  zConvertTest.test_float  sf    Q7q$'	Be 	B A8q'%.1r   c                    t        j                  t        dd      t              }| j	                  |t        d              G d dt              }t        j                  t        dd      |      }| j	                  | |d             y )	Nr
   (   z0.025c                        e Zd Z fdZ xZS )+ConvertTest.test_decimal.<locals>.MyDecimalc                 @    | j                  t        | 	  |            S rh   r  r  s     r   r  z7ConvertTest.test_decimal.<locals>.MyDecimal.__truediv__  r  r   r  r  s   @r   r  r    r  r   r  r   r   z-0.9375)r:   r  r   r   r  )rH   r   r  s      r   r  zConvertTest.test_decimal  sm    B9q''"23	B 	B b 19=q)I"67r   c                     t        d      t        d      fD ]=  }|| fD ]3  }t        j                  |t	        |            }| j                  ||       5 ? y r  )r   r   r:   r  r   r  )rH   r  r!   r   s       r   r&  zConvertTest.test_inf  sY    %L'%.1 	/CcT{ /''T#Y7&&q#./	/r   c                     t        d      t        d      t        d      fD ]<  }t        j                  |t	        |            }| j                  t        ||             > y r  )r   r   r:   r  r   r   r   )rH   r(  r   s      r   r*  zConvertTest.test_nan  sM    %L'%.'&/B 	0C##Cc3AOOJq#./	0r   c                     | j                  t              5  t        j                  d t               d d d        y # 1 sw Y   y xY wrh   )r5  r  r:   r  r   rt   s    r   test_invalid_input_typez#ConvertTest.test_invalid_input_type  s5    y) 	-e,	- 	- 	-s	   :AN)r5   r6   r7   r  r|  r  r  r  r&  r*  r$  r9   r   r   r  r    s*    (
-628/0
-r   r  c                   "    e Zd ZdZd Zd Zd Zy)FailNegTestz Test _fail_neg private function.c                     ddt        d      t        d      g}t        t        j                  |            }| j                  ||       y Nr
          @r   r   )r   r   r  r:   	_fail_negrD   )rH   valuesnews      r   test_pass_throughzFailNegTest.test_pass_through  s=    S(1+wqz2:''/0%r   c                     ddt        d      t        d      fD ]@  }| g}t        j                  |      }| j	                  t        j
                  t        |       B y r(  )r   r   r:   r*  r5  rr  next)rH   r   seqits       r   test_negatives_raisez FailNegTest.test_negatives_raise   sU    S(1+wqz2 	DA2$C%%c*Bj88$C	Dr   c                    dt        j                  dd      z  }	 t        t        j                  dg|             | j                  d       | j                  |       y # t        j                  $ r}|j                  d   }Y d }~:d }~ww xY w)Nzbadness #%d'  i rs   z(expected exception, but it didn't happenr   )	r  randintr/  r:   r*  failrr  r   rD   )rH   r[   rf   rt  s       r   test_error_msgzFailNegTest.test_error_msg  sx    fnnUE::	B%%rdC01 II@A%	 )) 	VVAYF	s    A B2BBN)r5   r6   r7   r8   r-  r2  r7  r9   r   r   r&  r&    s    *&D	&r   r&  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)UnivariateCommonMixinc                 D    | j                  t        | j                         y rh   r5  r  funcrt   s    r   test_no_argsz"UnivariateCommonMixin.test_no_args  s    )TYY/r   c                     g dt        g       fD ]-  }| j                  t        j                  | j                  |       / y )Nr9   )iterr5  r:   rr  r<  )rH   emptys     r   test_empty_dataz%UnivariateCommonMixin.test_empty_data  s:    "d2h' 	LEj88$))UK	Lr   c                     t        t        d            }|t        |      k(  r$t        j                  |       |t        |      k(  r$|S )z"Return int data for various tests.r   )r  r  sortedr  shufflerH   r  s     r   prepare_dataz"UnivariateCommonMixin.prepare_data!  s:    E"IfTl"NN4  fTl"r   c                     | j                         }t        |      dk7  sJ |t        |      k7  sJ |d d  }||usJ | j                  |      }| j	                  ||d       y )Nr
   zdata has been modified)rF  r_   rC  r<  assertListEqual)rH   r  savedr\  s       r   test_no_inplace_modificationsz3UnivariateCommonMixin.test_no_inplace_modifications(  si      "4yA~~vd|###Q5   IIdOT5*BCr   c                     g ddz  }| j                  |      }t        j                  |       | j                  |      }| j                  ||       y )N)r
   r   r   r   r   r   r      r   )r<  r  rD  rD   )rH   r  r%   r$   s       r   test_order_doesnt_matterz.UnivariateCommonMixin.test_order_doesnt_matter2  sD     (+99T?t46*r   c                     G d dt               } G d dt              }d }| j                         }| j                  |      }t         t        t        |||fD ]+  }| j                   ||            }| j                  ||       - y )Nc                       e Zd Zy)BUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyListNr  r9   r   r   MyListrP  A  r  r   rQ  c                       e Zd Zy)CUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyTupleNr  r9   r   r   MyTuplerS  C  r  r   rT  c                     d | D        S )Nc              3       K   | ]  }|  y wrh   r9   )r   objs     r   r   zXUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator.<locals>.<genexpr>F  s     (CC(s   r9   r  s    r   	generatorzEUnivariateCommonMixin.test_type_of_data_collection.<locals>.generatorE  s    (4((r   )r  r  rF  r<  r?  rD   )rH   rQ  rT  rY  r  r%   kindr   s           r   test_type_of_data_collectionz2UnivariateCommonMixin.test_type_of_data_collection?  sx    	T 		e 		)  "99T?5$C 	/DYYtDz*FVX.	/r   c                     t        ddd      }| j                  t        |            }| j                  | j                  |      |       y N   r  r   )r  r<  r  rD   rH   r  r%   s      r   test_range_dataz%UnivariateCommonMixin.test_range_dataM  s:    RQ99T$Z(4(3r   c                     | j                  d        | j                  d       | j                  d       | j                  t                      y )Nr   g      E@)check_for_type_errorobjectrt   s    r   test_bad_arg_typesz(UnivariateCommonMixin.test_bad_arg_typesS  s>     	!!$'!!"%!!$'!!&(+r   c                 H     | j                   t        | j                  g|  y rh   r;  rJ  s     r   rb  z*UnivariateCommonMixin.check_for_type_errorb  s    )TYY66r   c                 *    G d dt               }| j                         }| j                  |      }t         |t        t        fD ]I  }|D cg c]
  } ||       }} t        |      | j                  |            }| j                  ||       K y c c}w )Nc                   ,     e Zd Z fdZ fdZeZ xZS )@UnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloatc                 @     t        |       t        | 	  |            S rh   r   r  r  r  s     r   r  zLUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__truediv__j      !tDz%'"5e"<==r   c                 @     t        |       t        | 	  |            S rh   r   r  __add__r  s     r   rn  zHUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__add__l      !tDz%'/%"899r   )r5   r6   r7   r  rn  __radd__r  r  s   @r   r  rh  i  s    >:Hr   r  )r   rF  r<  r   r   r   rD   )rH   r  rawr%   rZ  r   r  r   s           r   test_type_of_data_elementz/UnivariateCommonMixin.test_type_of_data_elemente  s    	e 	 !99S>GWh7 	/D%()DG)D)#T(^DIIdO4FVX.	/)s   
BN)r5   r6   r7   r=  rA  rF  rJ  rM  r[  r`  rd  rb  rr  r9   r   r   r9  r9    s6    0L
D+/4,7/r   r9  c                       e Zd ZdZd Zd Zy)UnivariateTypeMixinam  Mixin 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.
    c                 D     G d dt               }t         t        t        |fS )z4Return the types which are expected to be conserved.c                   b     e Zd Z fdZ fdZ fdZ fdZ fdZ fdZeZ	 fdZ
e
Z xZS )HUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloatc                 @     t        |       t        | 	  |            S rh   rj  r  s     r   r  zTUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__truediv__  rk  r   c                 @     t        |       t        | 	  |            S rh   )r   r  __rtruediv__r  s     r   rz  zUUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rtruediv__  s    !tDz%'"6u"=>>r   c                 @     t        |       t        | 	  |            S rh   )r   r  __sub__r  s     r   r|  zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__sub__  ro  r   c                 @     t        |       t        | 	  |            S rh   )r   r  __rsub__r  s     r   r~  zQUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rsub__  s    !tDz%'"25"9::r   c                 @     t        |       t        | 	  |            S rh   )r   r  __pow__r  s     r   r  zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__pow__  ro  r   c                 @     t        |       t        | 	  |            S rh   rm  r  s     r   rn  zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__add__  ro  r   c                 @     t        |       t        | 	  |            S rh   )r   r  __mul__r  s     r   r  zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__mul__  ro  r   )r5   r6   r7   r  rz  r|  r~  r  rn  rp  r  __rmul__r  r  s   @r   r  rw    s0    >?:;::H:Hr   r  )r   r   r   )rH   r  s     r   #prepare_types_for_conservation_testz7UnivariateTypeMixin.prepare_types_for_conservation_test  s    	e 	" w'22r   c                     | j                         }| j                         D ]C  }|D cg c]
  } ||       }}| j                  |      }| j                  t	        |      |       E y c c}w rh   )rF  r  r<  r  r   )rH   r  rZ  r   r   r   s         r   test_types_conservedz(UnivariateTypeMixin.test_types_conserved  sc       "<<> 	.D"&'Qa'A'YYq\FMM$v,-	.'s   A(N)r5   r6   r7   r8   r  r  r9   r   r   rt  rt  x  s    3*.r   rt  c                       e Zd Zd Zy)TestSumCommonc                     d }|| _         y )Nc                  Z    t        j                  |  \  }}}t        j                  ||      S rh   )r:   _sumr  )r   r  valuer   s       r   simplified_sumz+TestSumCommon.setUp.<locals>.simplified_sum  s)    $//40KAua%%eQ//r   )r<  )rH   r  s     r   setUpzTestSumCommon.setUp  s    	0 #	r   N)r5   r6   r7   r  r9   r   r   r  r    s    
#r   r  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestSumc                 .    t         j                  | _        y rh   )r:   r  r<  rt   s    r   r  zTestSum.setUp      OO	r   c                     g dt        g       fD ]3  }| j                  | j                  |      t        t	        d      df       5 y )Nr9   r   )r?  rD   r<  r   r   rE  s     r   rA  zTestSum.test_empty_data  sA    T"X& 	EDTYYt_sHQK.CD	Er   c                 j    | j                  | j                  g d      t        t        d      df       y )N)r
   r   r   ir^  r   r
   <   r   )rD   r<  r   r   rt   s    r   	test_intszTestSum.test_ints  s*    #?@x|Q/	1r   c                 n    | j                  | j                  dgdz        t        t        d      df       y )NrH  r^        @)rD   r<  r   r   rt   s    r   test_floatszTestSum.test_floats  s/    D6"9-#3	5r   c                     | j                  | j                  t        dd      gdz        t        t        dd      df       y )Nr
   r%    r   )rD   r<  r   rt   s    r   test_fractionszTestSum.test_fractions  s:    HQ$5#6s#:;"HQNC8	:r   c           
          t         } |d       |d       |d       |d       |d       |d       |d       |d      g}| j                  | j                  |      t         t        d	      d
f       y )Nr  z5.246z1.702z-0.025z3.974z2.328z4.617z2.843z20.686r   )r   rD   r<  rH   r   r  s      r   test_decimalszTestSum.test_decimals  si    '
AgJ'
AhK'
AgJ'
AgJ 	4!78#4a8	:r   c                     t        d      D cg c]  }t        j                  dd       }}| j                  t	        | j                  |      d         t        j                  |      d       y c c}w )Nr%  r  r
   gؗҬ<r/   )r  r  r  r]   r   r<  r   fsum)rH   r\  r  s      r   test_compare_with_math_fsumz#TestSum.test_compare_with_math_fsum  s[     5:$K@qtT*@@uTYYt_Q%78$))D/uU As   A0c                     | j                  t        | j                  g dd       | j                  t        | j                  g d       y )Nr
   r   r   999)r
   r   r   r  r;  rt   s    r   test_strings_failzTestSum.test_strings_fail  s1    )TYY	5A)TYY0@Ar   c                     | j                  t        | j                  g dd       | j                  t        | j                  g d       y )Nr     999)r
   r   r   r  r;  rt   s    r   test_bytes_failzTestSum.test_bytes_fail  s1    )TYY	6B)TYY0ABr   c           	          | j                  t        | j                  ddt        d      g       | j                  t        | j                  ddgt        d             y )Nr
   r)  )r5  r  r<  r   rt   s    r   test_mixed_sumzTestSum.test_mixed_sum  sE     	)TYYC0DE)TYYC'!*Er   N)r5   r6   r7   r  rA  r  r  r  r  r  r  r  r  r9   r   r   r  r    s9    
$E
15::VB
C
Fr   r  c                       e Zd Zd Zy)SumTortureTestc                    | j                  t        j                  g ddz        t        t	        d      df       | j                  t        j                  g ddz        t        t	        d      df       t        j                  g ddz        \  }}}| j                  |t               | j                  |d       | j                  t        |      dd	       y )
N)r
   }Ô%ITr
   }Ô%Ir4  g     @i@  )r  r
   r
   r  )0.++r
   r  rs   g^,gV瞯<r  )rD   r:   r  r   r   r  r]   )rH   r  r  counts       r   test_torturezSumTortureTest.test_torture  s    )>u)DE'!2E:	<)>u)DE'!2E:	<"(?(EF3a&uSz7>r   N)r5   r6   r7   r  r9   r   r   r  r    s    	?r   r  c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)SumSpecialValuesc                     t         t        fD ]d  } |d      }t        j                  d|dg      d   }| j	                  t        |      |       | j                  t        j                  |             f y )Nr(  r
   r   )	r   r   r:   r  r  r   r   r   r   )rH   r   r(  r   s       r   r*  zSumSpecialValues.test_nan  s_    W% 	0E,C__aa[1!4FMM$v,.OODJJv./		0r   c                     | j                  t        j                  |             | j                  t	        |      t	        |             | j                  |dkD  |dkD         ||k(  sJ y)z8Check x is an infinity of the same type and sign as inf.r   N)r   r   r,   r  r   rD   )rH   r   r!   s      r   check_infinityzSumSpecialValues.check_infinity  sO    

1&d1gtCy)Qa(Cxxr   c                     t        j                  dd|dg      d   }| j                  ||       t        j                  dd|d|dg      d   }| j                  ||       y )Nr
   r   r   r   )r:   r  r  rH   r!   r   s      r   do_test_infzSumSpecialValues.do_test_inf  s]    !QQ03FC(!QQQ!78;FC(r   c                 P    t        d      }dD ]  }| j                  ||z          y Nr!   r
   rs   )r   r  rH   r!   r   s      r   test_float_infzSumSpecialValues.test_float_inf  s,    El 	'DT#X&	'r   c                 P    t        d      }dD ]  }| j                  ||z          y r  )r   r  r  s      r   test_decimal_infz!SumSpecialValues.test_decimal_inf  s,    en 	'DT#X&	'r   c                     t        d      }t        j                  dd|d| dg      d   }| j                  t	        j
                  |             y Nr!   r
   r   r   r   )r   r:   r  r   r   r   r  s      r   test_float_mismatched_infsz+SumSpecialValues.test_float_mismatched_infs  sB    El!QQa!89!<

6*+r   c                    t        d      }dd|d| dg}t        j                  t        j                        5  | j	                  t        j                  t        j                  |      d                d d d        y # 1 sw Y   y xY wr  )	r   decimallocalcontextExtendedContextr   r   r   r:   r  rH   r!   r  s      r   3test_decimal_extendedcontext_mismatched_infs_to_nanzDSumSpecialValues.test_decimal_extendedcontext_mismatched_infs_to_nan  so    en1c1sdA&!!'"9"9: 	BOODJJzt'<Q'?@A	B 	B 	Bs   ;A<<Bc                     t        d      }dd|d| dg}t        j                  t        j                        5  | j	                  t        j
                  t        j                  |       d d d        y # 1 sw Y   y xY wr  )r   r  r  BasicContextr5  InvalidOperationr:   r  r  s      r   0test_decimal_basiccontext_mismatched_infs_to_nanzASumSpecialValues.test_decimal_basiccontext_mismatched_infs_to_nan%  sh    en1c1sdA&!!'"6"67 	Og66
N	O 	O 	Os   0A11A:c                     t        d      }d|dg}| j                  t        j                  t        j
                  |       y )Nr  r
   r   )r   r5  r  r  r:   r  )rH   r  r  s      r   test_decimal_snan_raisesz)SumSpecialValues.test_decimal_snan_raises,  s2    v4|'22JOOTJr   N)r5   r6   r7   r*  r  r  r  r  r  r  r  r  r9   r   r   r  r    s2    0)'
'
,BOKr   r  c                       e Zd Zd Zd Zd Zy)AverageMixinc                     dddt        dd      t        d      fD ]$  }| j                  | j                  |g      |       & y Nr   g     @E@g  X_yCr{      z0.28r   r   rD   r<  r   s     r   test_single_valuezAverageMixin.test_single_value8  sA    dFHR$4gfoF 	0ATYYs^Q/	0r   c                 6    dddt        dd      t        d      fS )N      @ry    7y!C=   C   z4.9712r   r   rt   s    r   'prepare_values_for_repeated_single_testz4AverageMixin.prepare_values_for_repeated_single_test=  s    R"b!1783DEEr   c                     | j                         D ]L  }dD ]E  }| j                  ||      5  |g|z  }| j                  | j                  |      |       d d d        G N y # 1 sw Y   TxY w)Nr   r   r   r^  )r   r  )r  subTestrD   r<  rH   r   r  r  s       r   test_repeated_single_valuez'AverageMixin.test_repeated_single_value@  sv    ==? 	9A' 9\\AU\3 93u9D$$TYYt_a89 99	99 9s   (A!!A*N)r5   r6   r7   r  r  r  r9   r   r   r  r  5  s    0
F9r   r  c                   Z    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)TestMeanc                 .    t         j                  | _        y rh   )r:   meanr<  rt   s    r   r  zTestMean.setUpJ  r  r   c                 J    | j                  | j                  g d      d       y )N)r  r
   r   r  r
   rD   r<  rt   s    r   test_torture_pepzTestMean.test_torture_pepM  s    #891=r   c                 x    g d}t        j                  |       | j                  | j                  |      d       y )N)r   r
   r   r   r   r   r   r   r   rL  r   r   r   r   r   r   g     @@r  rD  rD   r<  rE  s     r   r  zTestMean.test_intsQ  s+    ?t4&1r   c                 x    g d}t        j                  |       | j                  | j                  |      d       y )N)g     @1@g     3@      4@g     5@g     5@g     @7@g      9@g     ;@g     6@r  rE  s     r   r  zTestMean.test_floatsW  s+    Et4)4r   c                     t         } |d       |d       |d       |d       |d      g}t        j                  |       | j                  | j	                  |       |d             y )Nz1.634z2.517z3.912z4.072z5.813z3.5896)r   r  rD  rD   r<  r  s      r   r  zTestMean.test_decimals]  sS    '
AgJ'
AgJ'
Kt4!H+6r   c           
          t         } |dd       |dd       |dd       |dd       |dd       |dd       |dd      g}t        j                  |       | j                  | j	                  |       |d	d
             y )Nr
   r   r   r   r   rL  r   r   i  i  r   r  rD  rD   r<  rH   r   r  s      r   r  zTestMean.test_fractionsd  so    !Q1a!Aq'1Q7AaGQq!Wa1gNt4!D$-8r   c                     g d}t         t        fD ]a  }dD ]Z  } |d      |z  }||gz   }| j                  |      }| j                  t	        j
                  |             | j                  ||       \ c y )Nr
   r   r   r   r   r  r!   )r   r   r<  r   r   r,   rD   )rH   rq  rZ  r   r!   r  r   s          r   r&  zTestMean.test_infk  su    G$ 	.D .5k$&cU{4

6 23  -.	.r   c           
          dddt        d      dddt        d      g}| j                  |      }| j                  t        j                  |             y )	Nr   r   rL  r!   r
   r   r   z-inf)r   r<  r   r   r   rH   r  r   s      r   test_mismatched_infszTestMean.test_mismatched_infsv  sB    1auq!Qf>4

6*+r   c                     g d}t         t        fD ]E  } |d      }||gz   }| j                  |      }| j                  t	        j
                  |             G y )Nr  r(  )r   r   r<  r   r   r   )rH   rq  rZ  r!   r  r   s         r   r*  zTestMean.test_nan|  sQ    G$ 	0Du+C#;DYYt_FOODJJv./		0r   c                     d}g d}| j                  |      |z   }||k7  sJ | j                  |D cg c]  }||z   	 c}      }| j                  ||       y c c}w )Ng    eA	333333@      @g@g@g333333@@g       @g333333 @g"@r<  rD   rH   cr  r%   r   r   s         r   test_big_datazTestMean.test_big_data  s\    <99T?Q&1}}.AAaC./* /s   Ac                     t        d      D cg c]  }t        j                  dd       }}| j                  |      }| j                  |dz        }| j	                  ||       y c c}w )Nr%  ry  r   r   r  r  r  r<  r]   rH   r\  r  r%   r$   s        r   test_doubled_datazTestMean.test_doubled_data  sX    /4T{;!r1%;;99T?46"vx0 <   A%c                 f    t        d      }| j                  t        j                  |g      |       y )N1e4)r   rD   r:   r  r   s     r   test_regression_20561zTestMean.test_regression_20561  s(     EN!-q1r   c                    | j                  t        j                  ddg      d       d}d}dD ]T  }| j                  t        j                  |g|z        |       | j                  t        j                  |g|z        |       V y )Ngg      g       )r   r   r   r  )rD   r:   r  )rH   bigtinyr   s       r   test_regression_25177zTestMean.test_regression_25177  s     	#%:;=!	# $ 	>AZ__cU1W5s;Z__dVAX6=	>r   N)r5   r6   r7   r  r  r  r  r  r  r&  r  r*  r  r	  r  r  r9   r   r   r  r  I  sC    $>2579	.,0+12>r   r  c                   x     e Zd Zd Z fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Z xZS )TestHarmonicMeanc                 .    t         j                  | _        y rh   )r:   harmonic_meanr<  rt   s    r   r  zTestHarmonicMean.setUp  s    ,,	r   c                 F    t         |          }|j                  d       |S )Nr   )r  rF  remove)rH   r+  r  s     r   rF  zTestHarmonicMean.prepare_data  s!    %'ar   c                 6    dddt        dd      t        d      fS )Nr  ry   r  r  r  z4.125r  rt   s    r   r  z8TestHarmonicMean.prepare_values_for_repeated_single_test  s    R"b!1773CDDr   c                 N    g d}| j                  | j                  |      d       y )N)r
   r   r   r   r  rH   r+  s     r   	test_zerozTestHarmonicMean.test_zero  s     6*A.r   c                     t         j                  }dgg dfD ]:  }| j                  |      5  | j                  || j                  |       d d d        < y # 1 sw Y   GxY w)Nrs   )r
   r   r   )r+  )r:   rr  r  r5  r<  )rH   excr+  s      r   test_negative_errorz$TestHarmonicMean.test_negative_error  sa    ((tZ( 	:FV, :!!#tyy&9: :	:: :s   AA	c                     dgg dg dg dfD ]L  }| j                  |      5  | j                  t              5  | j                  |       d d d        d d d        N y # 1 sw Y   xY w# 1 sw Y   exY w)Nz3.14)123)r
   r!  r   4r   )gffffff@r  r   z5.6rX  )r  r5  r  r<  rE  s     r   test_invalid_type_errorz(TestHarmonicMean.test_invalid_type_error  s{     H"	
 	$D 4( $&&y1 $IIdO$$ $	$$ $$ $s"   A*AA*A'#A**A3	c                 x    g d}t        j                  |       | j                  | j                  |      d       y )N)r   r   r   r   r   r   g333333@r  rE  s     r   r  zTestHarmonicMean.test_ints  s+    #t4%0r   c                     g d}t        j                  |       | j                  | j                  |      d       | j                  | j                  g d      d       y )N)r   rH  rH  r   r   rH  )rH  r   r   r   r   r  rE  s     r   test_floats_exactz"TestHarmonicMean.test_floats_exact  sE    (t4#.#893?r   c                 j    t        dd      D ]$  }| j                  | j                  |g      |       & y )Nr
   r   r  rD   r<  r   s     r   test_singleton_listsz%TestHarmonicMean.test_singleton_lists  s1    q# 	0ATYYs^Q/	0r   c           
         t         }| j                  | j                   |d       |d       |d       |d      g       |d              |d       |d       |d       |d      g}t        j                  |       | j                  | j                  |       |d              |d       |d       |d	       |d
      g}t        j                  |       | j                  | j                  |       |d      dz         y )Nr{   r  r  r  z0.10z0.20z1.68z0.32z5.94z2.75i iC )r   rD   r<  r  rD  r  s      r   test_decimals_exactz$TestHarmonicMean.test_decimals_exact  s    AbE1R5!B%2#?@!B%H&	1V9ai6;t4!F)4&	1V9ai6;t4!E(5.9r   c           
          t         } |dd       |dd       |dd       |dd       |dd       |dd       |dd      g}t        j                  |       | j                  | j	                  |       |d	d
             y )Nr
   r   r   r   r   rL  r   r   i|  i  r  r  s      r   r  zTestHarmonicMean.test_fractions  so    !Q1a!Aq'1Q7AaGQq!Wa1gNt4!E4.9r   c                 b    dt        d      dg}| j                  | j                  |      d       y )Nr)  r!   r   )r   rD   r<  r  s     r   r&  zTestHarmonicMean.test_inf  s+    uU|S)6*C0r   c                     dt        d      dg}| j                  t        j                  | j	                  |                   y )Nr)  r(  r   )r   r   r   r   r<  r  s     r   r*  zTestHarmonicMean.test_nan  s0    uU|S)

499V#456r   c                     d}g d}| j                  |      |z  }| j                  |D cg c]  }||z  	 c}      }| j                  ||       y c c}w )No   r  r  r  s         r   test_multiply_data_pointsz*TestHarmonicMean.test_multiply_data_points  sP    <99T?1$.AAaC./* /s   Ac                     t        d      D cg c]  }t        j                  dd       }}| j                  |      }| j                  |dz        }| j	                  ||       y c c}w )Nr%  r
   r   r   r  r  s        r   r	  z"TestHarmonicMean.test_doubled_data  sX    .3Dk:q!$::99T?46"vx0 ;r
  c           
         | j                  | j                  ddgddg      d       | j                  | j                  ddgddg      d       | j                  | j                  t        ddg      t        ddg            d       | j                  | j                  t        dd      t        d	d      t        d
d      gg d      | j                  t        dd      gdz  t        d	d      gdz  z   t        d
d      gdz  z                | j                  | j                  dgd
g      d       | j	                  t
              5  | j                  g dg d       d d d        | j	                  t        j                        5  | j                  g dddg       d d d        | j	                  t        j                        5  | j                  dgdg       d d d        | j	                  t        j                        5  | j                  ddgddg       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   `xY w# 1 sw Y   y xY w)Nr  r  r   r  g      L@)weightsr   r   r   r   r   )r   r   r   r  )r
   r9   r   r
   r   r^  )rD   r<  r?  r   r5  r  r:   rr  rt   s    r   test_with_weightsz"TestHarmonicMean.test_with_weights  s   B8aW5t<B8,-r7 # 459	;4R>#'B=237	9IIxAQ!QH*UIIxA'!+A'!+,1~&+, -	.
 	B4!-r2y) 	-IIi,	-z99: 	)IIi!Q(	)z99: 	!IIrdQC 	!z99: 	(IIr2hA'	( 	(	- 	-	) 	)	! 	!	( 	(s0   HH'?H3;H?H$'H03H<?I)r5   r6   r7   r  rF  r  r  r  r$  r  r'  r*  r,  r  r&  r*  r2  r	  r6  r  r  s   @r   r  r    sU    -E/
:
$1@0
	::1
7
+1(r   r  c                   H     e Zd Zd Z fdZd Zd Zd Zd Zd Z	d Z
 xZS )	
TestMedianc                 .    t         j                  | _        y rh   r:   medianr<  rt   s    r   r  zTestMedian.setUp$      %%	r   c                 h    t         |          }t        |      dz  dk7  r|j                  d       |S )+Overload method from UnivariateCommonMixin.r   r
   )r  rF  r_   rP  )rH   r  r  s     r   rF  zTestMedian.prepare_data'  s0    w#%t9Q;!KKNr   c                 t    g d}t        |      dz  dk(  sJ | j                  | j                  |      d       y )Nr
   r   r   r   r   rL  r   r   r  r_   rD   r<  rE  s     r   test_even_intszTestMedian.test_even_ints.  s5    !4y{a4#.r   c                 t    g d}t        |      dz  dk(  sJ | j                  | j                  |      d       y )N)r
   r   r   r   r   rL  r   r   r
   r   rA  rE  s     r   test_odd_intszTestMedian.test_odd_ints4  s5    $4y{a4!,r   c                    t         } |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |dd             y )Nr
   r   r   r   r   r   r   r_   r  rD  rD   r<  r  s      r   test_odd_fractionszTestMedian.test_odd_fractions:  su    !Q1a!Aq'1Q7AaG<4y{at4!Aq'2r   c           	         t         } |dd       |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |dd             y 	Nr
   r   r   r   r   r   rL  r   rF  r  s      r   test_even_fractionszTestMedian.test_even_fractionsB  }    !Q1a!Aq'1Q7AaGQq!WE4y{at4!Aq'2r   c                     t         } |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |d             y )N2.53.14.25.75.8r   r
   r   r_   r  rD  rD   r<  r  s      r   test_odd_decimalszTestMedian.test_odd_decimalsJ  si    %!E(AeHah%A4y{at4!E(3r   c                    t         } |d       |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |d	             y )
Nz1.2rM  rN  rO  rP  rQ  r   r   z3.65rR  r  s      r   test_even_decimalszTestMedian.test_even_decimalsR  so    %!E(AeHah%!E(K4y{at4!F)4r   )r5   r6   r7   r  rF  rB  rD  rG  rJ  rS  rU  r  r  s   @r   r8  r8  "  s+    &/-3345r   r8  c                       e Zd Zd Zd Zy)TestMedianDataTypec                 .    t         j                  | _        y rh   r:  rt   s    r   r  zTestMedianDataType.setUp]  r<  r   c                     t        t        d            }t        |      dz  dk(  sJ |t        |      k(  r$t	        j
                  |       |t        |      k(  r$|S )Nr{   r   r
   )r  r  r_   rC  r  rD  rE  s     r   rF  zTestMedianDataType.prepare_data`  sP    E"I4y{afTl"NN4  fTl"r   N)r5   r6   r7   r  rF  r9   r   r   rW  rW  [  s    &r   rW  c                   $    e Zd Zd Zd Zd Zd Zy)TestMedianLowc                 .    t         j                  | _        y rh   )r:   
median_lowr<  rt   s    r   r  zTestMedianLow.setUpi  s    ))	r   c                 t    g d}t        |      dz  dk(  sJ | j                  | j                  |      d       y )Nr@  r   r   r   rA  rE  s     r   rB  zTestMedianLow.test_even_intsl  5    !4y{a4!,r   c           	         t         } |dd       |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |dd             y rI  rF  r  s      r   rJ  z!TestMedianLow.test_even_fractionsr  rK  r   c                    t         } |d       |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |d             y 	Nz1.1z2.2z3.3z4.4r  z6.6r   r   rR  r  s      r   rU  z TestMedianLow.test_even_decimalsz  o    %!E(AeHah%!E(K4y{at4!E(3r   Nr5   r6   r7   r  rB  rJ  rU  r9   r   r   r[  r[  h  s    *-34r   r[  c                   $    e Zd Zd Zd Zd Zd Zy)TestMedianHighc                 .    t         j                  | _        y rh   )r:   median_highr<  rt   s    r   r  zTestMedianHigh.setUp  s    **	r   c                 t    g d}t        |      dz  dk(  sJ | j                  | j                  |      d       y )Nr@  r   r   r   rA  rE  s     r   rB  zTestMedianHigh.test_even_ints  r_  r   c           	         t         } |dd       |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |dd             y rI  rF  r  s      r   rJ  z"TestMedianHigh.test_even_fractions  rK  r   c                    t         } |d       |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |       |d             y rb  rR  r  s      r   rU  z!TestMedianHigh.test_even_decimals  rc  r   Nrd  r9   r   r   rf  rf    s    +-34r   rf  c                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)TestMedianGroupedc                 .    t         j                  | _        y rh   )r:   median_groupedr<  rt   s    r   r  zTestMedianGrouped.setUp  s    --	r   c                    g d}t        |      dz  dk(  sJ | j                  | j                  |      d       g d}t        |      dz  dk(  sJ | j                  | j                  |      d       g d}t        |      dz  dk(  sJ | j                  | j                  |d      d	       g d
}t        |      dz  dk(  sJ | j                  | j                  |d      dd       y )N)r   r     rq  rq  r{   r{   r   r
   rq  )r   r  rq  rq  rq  rq  r{   g     +@)r   r   r   r{   r^  r^  r^  r^     rr  r  r   g     `3@)r      rs  rs  rs  r^  r^  r^     rt  rt     ru        g4@:0yE>r.   )r_   rD   r<  r]   rE  s     r   test_odd_number_repeatedz*TestMedianGrouped.test_odd_number_repeated  s    +4y{a4"-+4y{a4&1:4y{a4+V4K4y{atyyq1;DIr   c                    g d}t        |      dz  dk(  sJ | j                  | j                  |d      dd       g d}t        |      dz  dk(  sJ | j                  | j                  |      d	d       g d
}t        |      dz  dk(  sJ | j                  | j                  |      d       g d}t        |      dz  dk(  sJ | j                  | j                  |      d       y )N)
r   r   r   r{   r^  r^  r^  rr  rr  r  r   r   r   g*3@rx  ry  )r   r   r   r   r   r   g["8@)r   r   r   r   r   r   r   r   r   r   rL  rL  r   )
r   r   r   r   r   r   r   r   rL  rL        @)r_   r]   r<  rD   rE  s     r   test_even_number_repeatedz+TestMedianGrouped.test_even_number_repeated  s    64y{atyyq1;DI!4y{atyy
E34y{a4#.-4y{a4$/r   c                     dddt        dd      t        d      fD ]9  }dD ]2  }|g|z  }| j                  | j                  |      t	        |             4 ; y )N333333@D   g ޗCr   r   z32.9714r  r   r   rD   r<  r   r  s       r   r  z,TestMedianGrouped.test_repeated_single_value  s`     r68B#4gi6HI 	<A' <s5y  4%(;<	<r   c                     dddt        dd      t        d      fD ]-  }| j                  | j                  |g      t	        |             / y r  r  r   s     r   r  z#TestMedianGrouped.test_single_value  sG     dFHR$4gfoF 	7ATYYs^U1X6	7r   c                     t         } |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |      d       y )	Nr   r   r   r  ry   r   r
         @rF  r  s      r   rG  z$TestMedianGrouped.test_odd_fractions  so    !Q1a!B(Ab!HaAh?4y{at4#.r   c           	         t         } |dd       |dd       |dd       |dd       |dd       |dd      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |      d       y )	Nr   r   r   r  ry   r   r         
@rF  r  s      r   rJ  z%TestMedianGrouped.test_even_fractions  sw    !Q1a!B(Ab!HaAh"aI4y{at4$/r   c                     t         } |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |      d       y )Nr  6.57.58.5r   r
   g      @rR  r  s      r   rS  z#TestMedianGrouped.test_odd_decimals  se    %!E(AeHah%A4y{at4$/r   c                    t         } |d       |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |      d        |d       |d       |d       |d       |d       |d      g}t        |      dz  dk(  sJ t        j                  |       | j	                  | j                  |      d       y )	Nr  r  r  r  r   r         @      @rR  r  s      r   rU  z$TestMedianGrouped.test_even_decimals  s    %!E(AeHah%!E(K4y{at4#.%!E(AeHah%!E(K4y{at4#.r   c                     g d}| j                  | j                  |d      d       g d}| j                  | j                  |d      dd       g d}| j                  | j                  |d	      d
       y )N)
      @rF  rF  r   r   r  r  r  r  rM  rH  g      @)r  rF  rF  r   r   r   r  r  r  r  rM  g["8@rx  ry  )   r       r  r  r    r  ,  @  iT  r^  g     p@)rD   r<  r]   rE  s     r   test_intervalzTestMedianGrouped.test_interval  sg    F4.6Ltyyt4jdKK4,e4r   c                 8   g d}| j                  t        | j                  |       g d}| j                  t        | j                  |       g d}d}| j                  t        | j                  ||       g d}d}| j                  t        | j                  ||       y )N) r  r  )r   r   r   r  r  r   r;  )rH   r  intervals      r   test_data_type_errorz&TestMedianGrouped.test_data_type_error  s|    )TYY5)TYY5)TYYh?)TYYh?r   N)r5   r6   r7   r  rz  r}  r  r  rG  rJ  rS  rU  r  r  r9   r   r   rm  rm    s;    .J$0$<7/00/5@r   rm  c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestModec                 .    t         j                  | _        y rh   )r:   moder<  rt   s    r   r  zTestMode.setUp  r  r   c                 
    g dS )r>  )r
   r
   r
   r
   r   r   r   r   r   r   r   r9   rt   s    r   rF  zTestMode.prepare_data  s
     10r   c                 `    t        ddd      }| j                  | j                  |      d       y r]  r)  rE  s     r   r`  zTestMode.test_range_data   s(    RQ4"-r   c                     d}| j                  | j                  |      d       dj                         }| j                  | j                  |      d       y )Nabcbdbr   zfe fi fo fum fi fifi)rD   r<  r   rE  s     r   test_nominal_datazTestMode.test_nominal_data%  sE    4#.#))+4$/r   c                     t        t        d            }t        d      D ]>  }||gz   }t        j                  |       | j	                  | j                  |      |       @ y Nr   r  r  r  rD  rD   r<  )rH   r  re   r   s       r   test_discrete_datazTestMode.test_discrete_data,  sQ    E"Ir 	.As
ANN1TYYq\1-	.r   c                     g d}|j                  d      |j                  d      cxk(  rdk(  sJ  J | j                  | j                  |      d       y )N)r
   r
   r   r   r   r   r   r   r   rL  rL  rL  rL  r   r   r   r   r   rL  r   )r  rD   r<  rE  s     r   test_bimodal_datazTestMode.test_bimodal_data4  sH    Bzz!}

12222224!,r   c                 n    t        t        d            }| j                  | j                  |      d       y )Nr   r   )r  r  rD   r<  rE  s     r   test_unique_datazTestMode.test_unique_data;  s'    E"I4!,r   c                 F    | j                  t        | j                  d        y rh   r;  rt   s    r   test_none_datazTestMode.test_none_dataA  s    
 	)TYY5r   c                 t    t        j                  dd      }| j                  | j                  |      d       y )Nr
   r   )r   r   r   )rT   CounterrD   r<  )rH   r  s     r   test_counter_datazTestMode.test_counter_dataH  s0    
 !q) 	1s+r   N)r5   r6   r7   r  rF  r`  r  r  r  r  r  r  r9   r   r   r  r    s/    $1
.
0.--6,r   r  c                       e Zd Zd Zy)TestMultiModec                     t         j                  }| j                   |d      dg       | j                   |d      g d       | j                   |d      g        y )Naabbbbbbbbccr   aabbbbccddddeeffffgg)r   r   r   r  )r:   	multimoderD   )rH   r  s     r   test_basicszTestMultiMode.test_basicsU  sN    ((	>2SE:#9:OL2+r   N)r5   r6   r7   r  r9   r   r   r  r  S  s    ,r   r  c                   $    e Zd Zd Zd Zd Zd Zy)	TestFMeanc           
         t         j                  }t        }t        }g dddf |d       |d       |d      gddf |dd	       |d
d       |dd
      gddfg dddfdd
 |dd
      gddfdt	        g d      ddffD ]A  \  }}} ||      }| j                  t        |      t        |       | j                  |||       C y )Nr  rG        @      @floats3.54.05.25decimalsr   r   r   r
   r   	fractions)TFTTF333333?booleansr  mixed types)r  r  r  iterator)	r:   fmeanr   r   r?  r  r   r   rD   )rH   r  r   r   r  expected_meanrZ  actual_means           r   r  zTestFMean.test_basics^  s      tX.h%!F),dJ?1gqAw"a)4=-tZ@1aAh}5-"#T:6* 	?%D-  +KMM${+UD9[->	?r   c                    t         j                  }t         j                  }| j                  |      5   |g        d d d        | j                  |      5   |t	        g              d d d        | j                  t
              5   |d        d d d        | j                  t
              5   |g d       d d d        | j                  t
              5   |        d d d        | j                  t
              5   |g dd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   |xY w# 1 sw Y   cxY w# 1 sw Y   y xY w)Nr   Nr^  r   r^  r  F   )r:   r  rr  r5  r?  r  rH   r  rr  s      r   test_error_caseszTestFMean.test_error_caseso  s     $44/ 	"I	/ 	$r(O	y) 	$K	y) 	".!	"y) 	G	y) 	$,#	$ 	$	 		 		 		" 	"	 		$ 	$sG   	DD	D#)D/D;6EDD #D,/D8;EEc                    t         j                  }t        d      }t        d      }| j                  t	        j
                   |d|g            d       | j                  t	        j
                   |||g            d       | j                  t	        j                   |d|g            d       | j                  t              5   ||| g       d d d        y # 1 sw Y   y xY wNNanInfr   r(  znan and infinityinfinity)	r:   r  r   r   r   r   r,   r5  r+   )rH   r  NaNr  s       r   test_special_valueszTestFMean.test_special_values  s      ElEl

5"c#34e<

5#s#457IJ

5"c#34jAz* 	3+	 	 	   CC!c           	      *   t         j                  }t         j                  }| j                   |g ddgdz         |g d             | j                   |g dg d       |g d             | j                   |t	        g d      t	        g d             |g d             | j                  |      5   |g ddd	g       d d d        | j                  |      5   |t	        g d      t	        dd	g             d d d        | j                  |      5   |d
dgddg       d d d        | j                  |      5   |t	        d
dg      t	        ddg             d d d        y # 1 sw Y   xY w# 1 sw Y   vxY w# 1 sw Y   [xY w# 1 sw Y   y xY w)N)r   r   r   r  rH  r   )r   r   r^  )rH  rH  r   )r   r   r^  r^  r   r^  r  r
   r   r   r^  rs   )r:   r  rr  rD   r?  r5  r  s      r   test_weightszTestFMean.test_weights  sv     $44"TFQJ/"#	% 	, 23"#	% 	$|$d+=&>?"#	% / 	(,A'	(/ 	4$|$dAq6l3	4/ 	%2r(RG$	%/ 	1$Bx.$Aw-0	1 	1	( 	(	4 	4	% 	%	1 	1s0   5E% E1E=< F	%E.1E:=F	FN)r5   r6   r7   r  r  r  r  r9   r   r   r  r  \  s    ?"$ 	1r   r  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	VarianceStdevMixin-q=c                     dddt        dd      t        d      fD ]$  }| j                  | j                  |g      d       & y )Nr   g3@g  %Br   r   z8.392r   r  r   s     r   r  z$VarianceStdevMixin.test_single_value  sB    dFHR$4gg6FG 	0ATYYs^Q/	0r   c                     dddt        dd      t        d      fD ]0  }dD ])  }|g|z  }| j                  | j                  |      d       + 2 y )	Nr  r  g @6<Cr   r   z62.4802)r   r   r   r{   r   r  r  s       r   r  z-VarianceStdevMixin.test_repeated_single_value  sY    r68Aq>793EF 	5A& 5s5y  4!45	5r   c                 ~    dgdz  }| j                  |      }| j                  |dd       | j                  |d       y )Ng.F7ݚ?r4  rr   gؗҌ<ry  r   )r<  r]   r  r  s      r   test_domain_error_regressionz/VarianceStdevMixin.test_domain_error_regression  sE     ""5( 4vs6*r   c                     g d}| j                  |      }d}|D cg c]  }||z   	 }}| j                  | j                  |      |       y c c}w )N)
g{Gz?gRQ?g
ףp=
?gRQ @gp=
ף@gQ	@r|  gQ@gGz@gQ@g     j@)r<  r]   rH   rq  r%   shiftr   r  s         r   test_shift_dataz"VarianceStdevMixin.test_shift_data  sP     K99S>#&'aE	''tyy9 (s   Ac                     g d}t        d |D              sJ | j                  |      }d}|D cg c]  }||z   	 }}| j                  | j                  |      |       y c c}w )N)
r
   r   r   r   r   r   r   r   r   r   c              3   8   K   | ]  }|t        |      k(    y wrh   )r   )r   r   s     r   r   z;VarianceStdevMixin.test_shift_data_exact.<locals>.<genexpr>  s     *1c!f9*s   i ʚ;)allr<  rD   r  s         r   test_shift_data_exactz(VarianceStdevMixin.test_shift_data_exact  sa    /*c****99S>#&'aE	''4(3 (s   A c                     t        d      D cg c]  }t        j                  dd       }}| j                  |      }| j	                  | j                  t        |            |       y c c}w )Nr%  ry  r   )r  r  r  r<  rD   r?  rH   r\  r  r%   s       r   test_iter_list_samez&VarianceStdevMixin.test_iter_list_same  sU     05T{;!r1%;;99T?4:.9 <s   A)N)
r5   r6   r7   r/   r  r  r  r  r  r  r9   r   r   r  r    s'     C0
5+:4
:r   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestPVariancec                 .    t         j                  | _        y rh   )r:   	pvariancer<  rt   s    r   r  zTestPVariance.setUp  s    ((	r   c                     t        t        d            }t        j                  |       d}| j	                  | j                  |      |       y )Nr4  g   P_Ar  r_  s      r   test_exact_uniformz TestPVariance.test_exact_uniform  s9    E%L!t$4(3r   c                 R    g d}d}| j                  | j                  |      |       y )Nr   r   r  r   g     6@r  rH   r  exacts      r   r  zTestPVariance.test_ints  s$    4%0r   c                     t         } |dd       |dd       |dd       |dd      g} |dd      }| j                  |      }| j                  ||       | j                  |t                y )Nr
   r   r   r   r   r   r<  rD   assertIsInstancerH   r   r  r  r   s        r   r  zTestPVariance.test_fractions  e    !Q1a!Aq'1Q73!Q4'fh/r   c                     t         } |d       |d       |d       |d      g} |d      }| j                  |      }| j                  ||       | j                  |t                y )Nz12.1z12.2z12.5z12.9z0.096875r   r<  rD   r  rH   r   r  r  r   s        r   r  zTestPVariance.test_decimals  s[    &	1V9ai6;*4'fg.r   c                     g d}d}| j                  |      }| j                  ||       | j                  |t               y )N)r   r   r
   gqq?r<  rD   r  r   rH   r  r  r   s       r   test_accuracy_bug_20499z%TestPVariance.test_accuracy_bug_20499  9    4'fe,r   N)	r5   r6   r7   r  r  r  r  r  r  r9   r   r   r  r    s     )410/-r   r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestVariancec                 .    t         j                  | _        y rh   )r:   variancer<  rt   s    r   r  zTestVariance.setUp  s    ''	r   c                     dddt        dd      t        d      fD ].  }| j                  t        j                  | j
                  |g       0 y )Nr   g333338@g (G!=Cr  r  z4.2084r   r   r5  r:   rr  r<  r   s     r   r  zTestVariance.test_single_value  sH    dFHR$4gh6GH 	JAj88$))aSI	Jr   c                 R    g d}d}| j                  | j                  |      |       y )Nr  r  r  r  s      r   r  zTestVariance.test_ints  s$    4%0r   c                     t         } |dd       |dd       |dd       |dd      g} |dd      }| j                  |      }| j                  ||       | j                  |t                y )Nr
   r   r   r   r   r  r  s        r   r  zTestVariance.test_fractions   r  r   c                     t         } |d       |d       |d       |d      g}d |d      z   |d      z  }| j                  |      }| j                  ||       | j                  |t                y )Nr   r   r   r   z9.5r   r  r   s        r   r  zTestVariance.test_decimals)  sg    !adAaD!A$'!E(
1Q44'fg.r   c                     d}| j                  | j                  |      d       | j                  | j                  |d      d       y )Nr   r)  r   r)  xbarr   r  rE  s     r   test_center_not_at_meanz$TestVariance.test_center_not_at_mean2  s<    4#.4c2C8r   c                     g d}d}| j                  |      }| j                  ||       | j                  |t               y )N)r   r   r   gUUUUUU?r  r  s       r   r  z$TestVariance.test_accuracy_bug_204997  r  r   N)
r5   r6   r7   r  r  r  r  r  r  r  r9   r   r   r  r    s&    (J
10/9
-r   r  c                       e Zd Zd Zd Zd Zy)
TestPStdevc                 .    t         j                  | _        y rh   )r:   pstdevr<  rt   s    r   r  zTestPStdev.setUp@  r<  r   c                     t        d      D cg c]  }t        j                  dd       }}t        j                  t        j                  |            }| j                  | j                  |      |       y c c}w )Nr%  iru  )	r  r  r  r   sqrtr:   r  rD   r<  r  s       r   test_compare_to_variancez#TestPStdev.test_compare_to_varianceC  sZ    16t=AsB'==99Z11$784(3 >   A7c                     d}| j                  | j                  |      d       | j                  | j                  |d      d       y )N)r   rL  r   r   rF  r   )mur  r  rE  s     r   r  z"TestPStdev.test_center_not_at_meanI  s<    4#.4C0#6r   N)r5   r6   r7   r  r  r  r9   r   r   r  r  >  s    &47r   r  c                   R    e Zd Zd Ze ej                  d      d               Zd Zy)TestSqrtHelpersc                 b   t        j                  t        d      t        dd            D ]  \  }}t        j                  ||      }| j                  |t               ||z  |z  |k(  r>| j                  |dz  d       | j                  ||dz
  dz  z  |cxk  xr ||dz   dz  z  k  nc         y )Nr   r
   r%  r   )		itertoolsproductr  r:   _integer_sqrt_of_frac_rtor  r   rD   r   )rH   r   mr   s       r   test_integer_sqrt_of_frac_rtoz-TestSqrtHelpers.test_integer_sqrt_of_frac_rtoQ  s    %%eCj%4.A 		ADAq44Q:A!!!S)s1uzQqS!$OOAQ
NQ?a!eaZ?@		Ar   cpuc                    dt         dt        dt        fd}t        j                  }t        d      D ]}  } |d |d      z        } |d |d      z        dz   }| j                  ||	      5  t        ||      }t        j                  ||      }| j                   |||             d d d         | j                  t        j                  d
d      d       | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd
       d d d        | j                  t        j                  dd      t        j                  dd             y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ixY w)Nr   rootreturnc                 H   | s|dk(  S t        j                  |t         j                        }t        j                  |t         j                         }||cxk  r|k  sJ  J t        |      }|t        |      z   dz  }|t        |      z   dz  }|dz  | cxk  xr |dz  k  S c S )Nrr   r   )r   	nextafterr!   r   )r   r)  r_upr_down	frac_roothalf_way_uphalf_way_downs          r   is_root_correctly_roundedzJTestSqrtHelpers.test_float_sqrt_of_frac.<locals>.is_root_correctly_roundeda  s    s{" ..txx8D NN4$((;FD'4''''' #+4.I%.$%?1$DK'08F3C'Cq&HM !A%>kQ.>>>>>r   i`  r   r  r
   )	numeratordenonimatorr   rr   rs   r   r   )r   r   r  r  	randranger  r  r:   _float_sqrt_of_fracr   rD   r5  r+   ZeroDivisionError)rH   r2  r5  re   r3  r4  r   r)  s           r   test_float_sqrt_of_fracz'TestSqrtHelpers.test_float_sqrt_of_frac]  s   	? 	? 	?4 	?$ $$	v 	DA&rYr]':;I(y})<=AK	{K D&y+>(<<YT 9!T BCD D	D 	771=sCz* 	2**2q1	2z* 	2**1b1	2 01 	1**1a0	1 	77B?A_A_`acdAef#D D	2 	2	2 	2	1 	1s0   -;F/-F<!GG/F9	<GGGc                 B   t        d      ddft        d      ddft        d      ddffD ]  \  }}}t        j                  t        j                        5  | j	                  t        j                  ||      |       d d d        t        j                  t        j                        5 }|xj                  dz  c_        t        |      t        |      z  }t        j                  |_	        |j                         }d d d        t        j                  t        j                        5  }d d d        | j	                  |        | j	                  t        j                  d	d
      d       | j                  t        j                        5  t        j                  dd
       d d d        | j                  t        j                        5  t        j                  d
d       d d d        | j                  t              5  t        j                  d
d	       d d d        | j	                  t        j                  dd      t        j                  dd
             y # 1 sw Y   xY w# 1 sw Y   lxY w# 1 sw Y   JxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nz0.4481904599041192673635338663l   :jt9)4]! l       73Me'z0.7924949131383786609961759598l   Q_Ar,NE*z0.8500554152289934068192208727l   kr"-D9}ZGr   r   r
   rr   rs   r   r   )r   r  r  DefaultContextrD   r:   _decimal_sqrt_of_fracprec
ROUND_05UProundingr  r5  r  r7  )rH   r)  r3  denominatorctxhigh_prec_ratiohigh_prec_roottarget_roots           r   test_decimal_sqrt_of_fracz)TestSqrtHelpers.test_decimal_sqrt_of_frac  s?    568VXwx568VXwx568VXwx-
 	0(D)[
 %%g&<&<= a  !A!A)[!Y[_`a %%g&<&<= 8A"))"4w{7K"K&11!0!5!5!7	8
 %%g&<&<= .-o.T;/!	0& 	99!Q?Ew778 	4,,R3	4w778 	4,,Q3	4 01 	3,,Q2	3 	99"bA:CcCcdeghCij3a a8 8
. .	4 	4	4 	4	3 	3sI   'I'AI#$I0
I=J	<JI 	#I-	0I:	=J	JJN)	r5   r6   r7   r&  r   r   requires_resourcer8  rD  r9   r   r   r   r   O  s:    
A Wu%*g & *gX#kr   r   c                   $    e Zd Zd Zd Zd Zd Zy)	TestStdevc                 .    t         j                  | _        y rh   )r:   stdevr<  rt   s    r   r  zTestStdev.setUp  s    $$	r   c                     dddt        dd      t        d      fD ].  }| j                  t        j                  | j
                  |g       0 y )NQ   gHzwi@g  f7?+Br   r   z35.719r  r   s     r   r  zTestStdev.test_single_value  sG    ffhq"owx7HI 	JAj88$))aSI	Jr   c                     t        d      D cg c]  }t        j                  dd       }}t        j                  t        j                  |            }| j                  | j                  |      |       y c c}w )Nr%  r   r   )	r  r  r  r   r  r:   r	  assertAlmostEqualr<  r  s       r   r  z"TestStdev.test_compare_to_variance  sZ    /4T{;!r1%;;99Z0067tyy9 <r  c                 N    d}| j                  | j                  |d      d       y )Nr  r)  r  r   r  rE  s     r   r  z!TestStdev.test_center_not_at_mean  s$    4c2C8r   N)r5   r6   r7   r  r  r  r  r9   r   r   rG  rG    s    %J
:9r   rG  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestGeometricMeanc                 v   t         j                  }| j                   |g d      d       | j                   |ddg      d       | j                   |dg      d       t        j                  d       t        dd	      t        dd
      t        dd      t        ddd      t        ddd      g dt        d
      D cg c]  }t        j                  d       c}t        d      D cg c]  }t        j                  dd       c}t        d      D cg c]  }t        j                  ddd       c}f	D ]s  }t        j                  t        t        |            t        d      t        |      z  z  } ||      }| j                  t        j                  |t!        |                   u y c c}w c c}w c c}w )N)rz   ru  r         B@rG  g      "@g      @g     1@l   ; r
   r   r%  r4  r  r   ry  )r   ry   r  r   x   r         I@  r  r  i  i  )r:   geometric_meanrM  r  seedr  expovariatelognormvariate
triangularr   prodr   r   r_   r   iscloser   )rH   rV  re   rng
gm_decimalgm_floats         r   r  zTestGeometricMean.test_basics  s`   #22~l;TB~sCj93?~vh7@N#aaa c61%fc2&'38<@a##D)@;@<Ha&&tS1H>CElK""4t4K
 	GC 3w#45'!*s3x:OPJ%c*HOODLL53DEF	G AHKs   <F,'F1F6c           	      t   t         j                  }t        }t        }d}g ddf |d       |d       |d      gdf |dd	       |d
d       |dd
      gdfdd
 |dd
      gdfdt	        g d      dffD ]A  \  }} ||      }| j                  t        |      t        |       | j                  ||d       C y )Ngd@r  r  r  r  r  r  r   r   r   r
   r   r  r  r  )r  r  r  r   places)	r:   rV  r   r   r?  r  r   r   rM  )rH   rV  r   r   r  r  rZ  r  s           r   test_various_input_typesz*TestGeometricMean.test_various_input_types  s    #22x(h%!F),j91gqAw"a);71aAh/'"#Z0 
	IJD$ ).KMM${+UD9"";a"H
	Ir   c                    t         j                  }d} |d|z  d|z  d|z  g      }| j                  t        j                  |d|z               | j                  t        j                  |             d} |d|z  d|z  d|z  g      }| j                  t        j                  |d|z               | j                  |d       y )Ng      p~g      K@g      8@rR  g      prr   )r:   rV  r   r   r\  r   r,   assertNotEqual)rH   rV  largebig_gmsmallsmall_gms         r   test_big_and_smallz$TestGeometricMean.test_big_and_small  s    #22 te|TE\ JKVTE\:;F+, !4%<te|"LMXte|<=Hc*r   c                 j   t         j                  }t         j                  }| j                  |      5   |g        d d d        | j                  |      5   |g d       d d d        | j                  |      5   |g d       d d d        | j                  |      5   |t	        g              d d d        | j                  t
              5   |d        d d d        | j                  t
              5   |g d       d d d        | j                  t
              5   |        d d d        | j                  t
              5   |g dd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   }xY w# 1 sw Y   y xY w)N)r  rr   r  )r  g      r  r  r  r  )r:   rV  rr  r5  r?  r  )rH   rV  rr  s      r   r  z"TestGeometricMean.test_error_cases  s{   #22$44/ 	2	/ 	-+,	-/ 	.,-	./ 	%48$	%y) 	!4 	!y) 	+>*	+y) 		y) 	-<,	- 	-	 		- 	-	. 	.	% 	%	! 	!	+ 	+	 		- 	-s_   	EE 8E-E9	F1FF>F)E E*-E69FFFF&)F2c                    t         j                  }t        d      }t        d      }| j                  t	        j
                   |d|g            d       | j                  t	        j
                   |||g            d       | j                  t	        j                   |d|g            d       | j                  t              5   ||| g       d d d        y # 1 sw Y   y xY wr  )	r:   rV  r   r   r   r   r,   r5  r+   )rH   rV  r  r  s       r   r  z%TestGeometricMean.test_special_values	  s    #22ElEl

>2s)#<=uE

>3*#=>@RS

>2s)#<=zJz* 	(C#;'	( 	( 	(r  c                     t         j                  }d}g dg dg dg dg dg}|D ]9  }| j                  |      5   ||      }| j                  ||d	       d d d        ; y # 1 sw Y   FxY w)
NgY};t@)r   r   r   r   )r   r   r   r  )r   r   r  r  )r   r  r  r  )r)  r  r  r  )vr   ra  )r:   rV  r  rM  )rH   rV  r  r+  rn  r  s         r   test_mixed_int_and_floatz*TestGeometricMean.test_mixed_int_and_float	  s    #22( 
  	MA" M,Q/&&{M!&LM M	MM Ms   A##A,	N)	r5   r6   r7   r  rc  rj  r  r  ro  r9   r   r   rP  rP    s#    G,I$+-(	(Mr   rP  c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestQuantilesc                    t         j                  }g d}t        j                  |       dg fddgfdddgfdg d	fd
g dfdg dfdg dfdg dfdg dfdg dff
D ]  \  }}| j	                  | |||             | j	                  t         |||            |dz
         t        t        t        fD ]U   |t        |      |      }| j                  fd|D               | j	                  |t        t        |                   W t        |      dk\  r| j	                   |||      |       t        |      }d|d   z  |d   z
  }d|d   z  |d   z
  }|||gz   }	| j	                   |||       ||	|d      ||f       d }
t        t        |
|            } |t        |
|      |      }| j                  t        d t        ||      D                      t        dd      D ]S  }t        j                   t        d       |!      } ||      \  }}}| j	                  |t        j"                  |             U y )"N)rS  r     r  i^  r
   r        @o@r         i@      t@r   )      d@rt       t@r   )      a@     k@     @r@     u@rL  )      ^@ru  rt  rv       u@r   )      Y@rw  g     j@rt  g     r@rx  g     Xv@r   )	g      V@ry  g      g@rz  rt  r{  g     `t@r|  g     v@r   )      T@r}  rw  ru        l@rt  g     q@rv  rx  r~  g     v@r{   )g      R@g      Z@ry  g      e@ru  rz        n@g     p@r{  rv  g     t@r|  g     @v@g      w@r   c              3   L   K   | ]  }t        t        |      k(          y wrh   r  r   r   r   datatypes     r   r   z4TestQuantiles.test_specific_cases.<locals>.<genexpr>I	       IQDGx$7 8I   !$r   rs   r   	inclusiver   methodc                     d| z  dz
  S Nr  g3333J@r9   r   s    r   r   z,TestQuantiles.test_specific_cases.<locals>.f[	      Qw))r   c              3   N   K   | ]  \  }}t        j                  ||        y wrh   r   r\  r   rf   r   s      r   r   z4TestQuantiles.test_specific_cases.<locals>.<genexpr>_	       Mtq!Q 2M   #%r  r   k)r:   	quantilesr  rD  rD   r_   r   r   r   r   r   r  rC  r  rc   r  choicesr;  )rH   r  r  r   r%   r   sdatalohipadded_datar   expactr  q1q2q3r  s                    @r   test_specific_casesz!TestQuantiles.test_specific_cases0	  s]    ((	(tGL%&,-34ABOP   ! 5 6 )	OKAx Xy';<S41!56A>"GX6 H"3x#6!<I&II  c(H.E)FGH
 8}!  8q!98D 4LEU1Xa(BU2Yr*B"b/K$!$+;?D	*s1h'(CC4LA.COOCMs3}MMNS)	OV q" 	:A>>%*2D"4JBBR!2!24!89	:r   c                 @   t         j                  }g d}t        j                  |       dg fddgfdddgfdg d	fd
g dfdg dfdg dfdg dfdg dfdg dff
D ]
  \  }}| j	                  | |||d             | j	                  t         |||d            |dz
         t        t        t        fD ]V   |t        |      |d      }| j                  fd|D               | j	                  |t        t        |                   X d }t        t        ||            } |t        ||      |d      }| j                  t        d t        ||      D                      | j	                   |ddgdd      g d       | j	                   |t        dd      dd      g d       t        d      D 	cg c]  }	t        j                  d        }}	 ||d!d      }
|j!                  t#        |             |j!                  t%        |              ||d!"      }| j	                  ||
       t        dd#      D ]U  }t        j&                  t        d      |$      } ||d%      \  }}}| j	                  |t        j(                  |             W y c c}	w )&N)r   r  i  i   r
   r        r@r   ru        y@r   )     e@r       @@r   )rw  r       v@     @rL  )     b@ru  r  r       @r   )g     0a@   r  r  g     pw@r  g     P@r   )	g     @`@rw  g     g@r  r  r  g     {@r  g     @@r   )g     @_@r  r  ru  rt  r  r~  r  r  r  g     @r{   )r}  g     a@rw  g     f@ru  r  g     q@rv  r  r  g      ~@r  g      @g     @r  r  c              3   L   K   | ]  }t        t        |      k(          y wrh   r  r  s     r   r   z>TestQuantiles.test_specific_cases_inclusive.<locals>.<genexpr>	  r  r  c                     d| z  dz
  S r  r9   r   s    r   r   z6TestQuantiles.test_specific_cases_inclusive.<locals>.f	  r  r   c              3   N   K   | ]  \  }}t        j                  ||        y wrh   r  r  s      r   r   z>TestQuantiles.test_specific_cases_inclusive.<locals>.<genexpr>	  r  r  r   r   )	      $@r  g      >@g      D@rT  g      N@g     Q@r  g     V@r   i  r4      r  r  r  r  )r:   r  r  rD  rD   r_   r   r   r   r   r   r  r  rc   r  r5  r  r   r"   r  r;  )rH   r  r  r   r%   r   r   r  r  re   r$   r  r  r  r  r  s                  @r   test_specific_cases_inclusivez+TestQuantiles.test_specific_cases_inclusivef	  s    ((	#tGL%&,-34>?PQ ' ( 5 6 	OKAx Xy;'OPS41[!IJAPQER"GX6 H"3x#6!KPI&II  c(H.E)FGH
*s1h'(CC4LAkBCOOCMs3}MMN5	O8 	As8r+FO	Q5C=B{KO	Q
 38*=Q  (==42k:CICITR(6*q" 	:A>>%*2D"4<JBBR!2!24!89	: >s   =Jc                     t         j                  }t        dd      D ]>  }dg|z  }| j                   ||      g d       | j                   ||d      g d       @ y )Nr   r   r  )r  r  r  r  r  )r:   r  r  rD   )rH   r  r   r  s       r   test_equal_inputszTestQuantiles.test_equal_inputs	  s\    ((	q" 	0A6A:DYt_.@AYtK@.0	0r   c                    t         j                  }d}t        |      D cg c]  }t        j                  d       }}t        t        |            |k7  r<|j                  t        j                  d             t        t        |            |k7  r<|j                          dD ]W  }||z  }| j                   |||      D cg c]  }t        j                  ||       c}t        t        |||                   Y dD ]r  }||z  ||z  dz   h} |||      D cg c]  }t        j                  ||       }	}t        |	|	dd        D 
ch c]
  \  }
}||
z
   }}
}| j                  ||k         t y c c}w c c}w c c}w c c}}
w )Nr4  皙?)r
   r   r   r   r^  r  r   r  r  r%  rU  r  r4  r  )
r  r  ;   m      i;  i  is  i  i)&  r
   )r:   r  r  r  rX  r_   setrP  sortrD   bisectr  rc   r   )rH   r  totalre   r  r   
group_sizeqgroup_sizespospsizess               r   test_equal_sized_groupsz%TestQuantiles.test_equal_sized_groups	  sj   ((	16u>A""3'>>#d)n%KK**3/0 #d)n%		 O 	<A!J1:411EFAtQ'FU:uj9:<	< E 	2A A:uzA~6K3<TQ3GHa6==q)HCH'*3AB'89tq!QU9E9OOE[01		2 ? G I9s   E5E:
E?Fc                    t         j                  }t         j                  }| j                  t              5   |        d d d        | j                  t              5   |g ddd       d d d        | j                  t              5   |g dd       d d d        | j                  |      5   |g dd       d d d        | j                  |      5   |g dd       d d d        | j                  t              5   |g dd       d d d        | j                  t
              5   |g dd	       d d d        | j                  |      5   |d
gd       d d d        | j                  t              5   |g dd       d d d        y # 1 sw Y   NxY w# 1 sw Y   0xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r  r   r  r   rs   r   Xr  r   )r   Nr  )r:   r  rr  r5  r  r+   )rH   r  rr  s      r   r  zTestQuantiles.test_error_cases	  s   ((	$44y) 	K	y) 	-lB!,	-y) 	'lA&	'/ 	)la(	)/ 	*lb)	*y) 	+lc*	+z* 	0l3/	0/ 	!rda 	!y) 	+n*	+ 	+!	 		- 	-	' 	'	) 	)	* 	*	+ 	+	0 	0	! 	!	+ 	+sk   F
FF$+F1F=;G	%GG!4G-
FF!$F.1F:=G	GG!G*-G6N)r5   r6   r7   r  r  r  r  r  r9   r   r   rq  rq  .	  s    4:l4:l02.+r   rq  c                       e Zd Zd Zd Zy)TestBivariateStatisticsc                    g dddgfddgg dffD ]  \  }}| j                  t        j                        5  t        j                  ||       d d d        | j                  t        j                        5  t        j                  ||       d d d        | j                  t        j                        5  t        j
                  ||       d d d         y # 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   xY w)Nr  r
   r   r5  r:   rr  
covariancecorrelationlinear_regressionr   s      r   test_unequal_size_errorz/TestBivariateStatistics.test_unequal_size_error	  s    AVY
 		3DAq "":#=#=> ,%%a+,"":#=#=> -&&q!,-"":#=#=> 3,,Q23 3		3, ,- -3 3s#   C4C 2C,C	 C)	,C5	c                    g g fg ddgfddgg fdgdgfdgddgfddgdgffD ]  \  }}| j                  t        j                        5  t        j                  ||       d d d        | j                  t        j                        5  t        j                  ||       d d d        | j                  t        j                        5  t        j
                  ||       d d d         y # 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   xY w)Nr
   r   r  r   s      r   test_small_sample_errorz/TestBivariateStatistics.test_small_sample_error	  s   H!QMWbMTA4LTAq7OWqdO
 	3DAq "":#=#=> ,%%a+,"":#=#=> -&&q!,-"":#=#=> 3,,Q23 3	3, ,- -3 3s$   C$C0C<$C-	0C9	<D	N)r5   r6   r7   r  r  r9   r   r   r  r  	  s    
33r   r  c                       e Zd Zd Zd Zd Zy)TestCorrelationAndCovariancec                    g dg ddfg dg ddfg dg ddfg dg ddfg dg dd	ffD ]R  \  }}}| j                  t        j                  ||      |       | j                  t        j                  ||      |       T y )
Nr  r
   rs   r   ry  rs   )r   r   r
   )r
   r   r
   r   )r
   r   r   r   rM  r:   r  r  )rH   r   r-   r   s       r   test_resultsz)TestCorrelationAndCovariance.test_results	  s    	1%b)	2&	1%	3'
 	HLAq& "":#9#9!Q#?H"":#8#8A#>G	Hr   c                 L   g d}g d}| j                  t        j                  ||      d       | j                  t        j                  ||      d       g d}| j                  t        j                  ||      d       | j                  t        j                  ||      d       y )Nr  )r   r  r^  r   r   )r   r  g333333?r
   r   r  r   s      r   test_different_scalesz2TestCorrelationAndCovariance.test_different_scales	  s    z55a;SAz44Q:A>z55a;Q?z44Q:C@r   c                     g d}g d}| j                  t        j                  ||d      d       | j                  t              5  t        j                  ||d       d d d        y # 1 sw Y   y xY w)N)
8   K   -   r   r  r   :   P   L   r  )
B   r  r  r  A   r  r  M   r  ?   rankedr  gl\e?
bad_method)rM  r:   r  r5  r+   )rH   readingmathematicss      r   test_correlation_spearmanz6TestCorrelationAndCovariance.test_correlation_spearman	
  sl     ;>z55g{S[\1	3 z* 	N""7KM	N 	N 	Ns   A((A1N)r5   r6   r7   r  r  r  r9   r   r   r  r  	  s    	HANr   r  c                   $    e Zd Zd Zd Zd Zd Zy)TestLinearRegressionc                     g d}g d}| j                  t        j                        5  t        j                  ||       d d d        y # 1 sw Y   y xY w)N)r
   r
   r
   r  )r5  r:   rr  r  r   s      r   test_constant_input_errorz.TestLinearRegression.test_constant_input_error
  sE    z99: 	/((A.	/ 	/ 	/s   AAc           
         g dg dddfg dg dddfg dg dddfg dg ddd	fg dg d
ddfg dg dddfg dg dddffD ]D  \  }}}}t        j                  ||      \  }}| j                  ||       | j                  ||       F y )Nr  )r   r   r   r   r
   )r   r   r   r   )r   rq  r   r   r   r  rs   )r   rt  r   r^  )gffffff@g@r  r   r   )r:   r  rM  )rH   r   r-   true_intercept
true_slopeslope	intercepts          r   r  z!TestLinearRegression.test_results!
  s    	1a(	1a(a0b!,a,b!,C01
 	6,Aq.*  *;;AqAE9""9n=""5*5	6r   c                     g d}g d}t        j                  ||d      \  }}| j                  |d       | j                  |d       y )N)r   r^  r  r  )   i  ib  i  TproportionalgN4@rr   )r:   r  rM  rD   rH   r   r-   r  r  s        r   test_proportionalz&TestLinearRegression.test_proportional/
  sE     %7714Pyuj1C(r   c                    t        dd      t        dd      g}t        dd      t        dd      g}t        j                  ||      \  }}| j                  t	        |t
                     | j                  t	        |t
                     t        j                  ||d      \  }}| j                  t	        |t
                     | j                  t	        |t
                     y )Nr   r   r   r   rL  Tr  )r   r:   r  r   r   r   r  s        r   test_float_outputz&TestLinearRegression.test_float_output6
  s    a^Xa^,a^Xa^,%771=y
5%01
9e45%7714Py
5%01
9e45r   N)r5   r6   r7   r  r  r  r  r9   r   r   r  r  
  s    /6)6r   r  c                       e Zd Zd Zd Zd Zd Zd Zd Ze	j                   e	j                  d      d               Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestNormalDistc                     | j                   j                  dd      }| j                  t              5  t	        |       d d d        | j                  t        |j                        d       y # 1 sw Y   /xY w)Nr  r   )_mu_sigma)rX  
NormalDistr5  r  varsrD   r  	__slots__rH   nds     r   
test_slotszTestNormalDist.test_slotsI
  s\    [[##C,y) 	H	r||,.?@	 	s   A,,A5c                    | j                   j                  dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                   j                         }| j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  | j                   j                        5  | j                   j                  dd       d d d         G d d| j                   j                        } |d	d
      }| j                  t        |      |       y # 1 sw Y   MxY w)Nr  ry   i!  r   r
   ic                       e Zd Zy)GTestNormalDist.test_instantiation_and_attributes.<locals>.NewNormalDistNr  r9   r   r   NewNormalDistr  `
  r  r   r	  r  r   )	rX  r   rD   r  rI  r	  r5  rr  r   )rH   r  r	  nnds       r   !test_instantiation_and_attributesz0TestNormalDist.test_instantiation_and_attributesO
  s   [[##C,#&2&e, [[##%!$1%d+ t{{::; 	-KK""3,	-	DKK22 	C#cM2	- 	-s   E--E6c                    | j                   j                  }g d}| j                  |j                  |       |dd             | j                  |j                  t	        |             |dd             | j                  |j                  t        |             |dd             | j                  | j                   j                        5  |j                  g        d d d        | j                  | j                   j                        5  |j                  dg       d d d         G d d|      }|j                  |      }| j                  t        |      |       y # 1 sw Y   xY w# 1 sw Y   MxY w)N)`   r   Z   r  n   rz  r   r   c                       e Zd Zy)BTestNormalDist.test_alternative_constructor.<locals>.NewNormalDistNr  r9   r   r   r	  r  u
  r  r   r	  )	rX  r   rD   from_samplesr  r?  r5  rr  r   )rH   r   r  r	  r
  s        r   test_alternative_constructorz+TestNormalDist.test_alternative_constructore
  s,   [[++
%006
2q8IJ00t=z"a?PQ00d<jQ>OPt{{::; 	(##B'	(t{{::; 	*##RD)	*	J 	((.cM2	( 	(	* 	*s   
E	E(E%(E1c                    | j                   j                  }d\  }} |||      }d}|j                  |      }| j                  t	        |      |       | j                  t        t        t        |            t        h       | j                   j                  |      }| j                  ||dz  z
  |cxk  xr ||dz  z   k  nc        d}|j                  |d      }|j                  |d      }	|j                  |d      }
|j                  |d      }| j                  ||
       | j                  |	|       | j                  ||	       y )N)r4  r  r%  r   r   zhappiness and joy)rW  ztrouble and despair)rX  r   samplesrD   r_   r  r   r   r   r  r   re  )rH   r   r  sigmar  r   r  r  data1data2data3data4s               r   test_sample_generationz%TestNormalDist.test_sample_generationz
  s&   [[++
	Er5!yy|TA&St_-w7{{%U1W<U1W<= 		!"5	6		!"7	8		!"5	6		!"7	8&&E5)r   c           	         | j                   j                  } |dd      }| j                  |j                  d      |j                  d             | j                  |j                  d      |j                  d             t	        d      D ]8  }| j                  |j                  d|z
        |j                  d|z                : d}t	        dd      D ]N  }|j                  ||z         |j                  |      z
  |z  }| j                  |j                  |      |d	
       P  |       }t        g d      D ]R  \  }}| j                  |j                  |dz        |d	
       | j                  |j                  | dz        |d	
       T  |dd      }	| j                  | j                   j                        5  |	j                  d       d d d        | j                  |j                  t        d            d       | j                  |j                  t        d            d       | j                  t        j                  |j                  t        d                         y # 1 sw Y   xY w)Nr   r{   rz  r   r  g      P?r  r1  r   ra  )2+ݓ?r  r  ggDio?g?gV}b?gQ|?gFx?ggs?g٬\m?g rh?gK7A`?g|гY?gQ?gQI?gsh|??g=yX5?g|a2U0*?gQ?gN@?g/$?g~k	?g]C?gw/?g~:p?g>W[?gMO?gW[?g鷯?g{Gz?gqh?g|a2U?gK7A?gvq-?gjt?gc]F?g\C?gףp=
?g?ga2U0*?gy):?g(y?gN@a?gfc]F?g"lxz,?gOn?g37?gec]?gn?gT?r  r   -Infrr   r  r  )rX  r   
assertLesspdfr  rM  cdfrb   r5  rr  rD   r   r   r   r   )
rH   r   r  re   dxr   est_pdfZpxYs
             r   test_pdfzTestNormalDist.test_pdf
  s   [[++
sBb	155:.c
AEE#J/r 	CA""155q>155q>B	C r3 	@AuuQV}quuQx/25G""1558WQ"?	@ L  
  	DEAr ""155U#3R"B""155!e#4b"C	D sAt{{::; 	EE"I	 	uV}-s3uU|,c2

155u#678	 	s   <I''I0c           	         | j                   j                  } |dd      }t        dd      D cg c]  }|j                  |       }}| j	                  t        t        t        |            t        h       | j	                  |t        |             | j	                  |j                  d      d        |       }dD ]O  \  }}| j                  |j                  |      |d       | j                  |j                  |       d	|z
  d       Q  |dd
      }| j                  | j                   j                        5  |j                  d       d d d        | j	                  |j                  t        d            d       | j	                  |j                  t        d            d	       | j                  t        j                  |j                  t        d                         y c c}w # 1 sw Y   xY w)Nr   r{   r
   r  r   ))rr   r   )r   gqZ ?)r   gE_A?)gQ?gGɫs?)g(\?g؞Y?)gQ?g9#?)gHzG?g&S?)r  gMbX9?)gQ?gT㥛 ?)g?g??)gffffff @g_xZ?)gQ@g#0?)g)\(@gu<f2?)gףp=
@gVe?)gHzG@g9?r   ra  r   r   r  r  rr   r  r  )rX  r   r  r!  rD   r  r   r   r   rC  rM  r5  rr  r   r   r   )	rH   r   r  r   cdfsr$  zcum_probr&  s	            r   test_cdfzTestNormalDist.test_cdf
  s   [[++
sB"'3-0Qa00St_-w7vd|,sT* L 	HKAx ""1558Xa"@""155!9cHnQ"G	H sAt{{::; 	EE"I	 	uV}-s3uU|,c2

155u#6783 1(	 	s   G&;G++G4r'  c           	      8   | j                   j                  } |dd      }| j                  |j                  d      |j                          |       }dddd}|j                         D ]o  \  }}t        |d	      D ]Z  \  }}|d
| z  z  }	| j                  |j                  |	       |d       d|	z
  }	| j                  |j                  |	      |d       \ q | j                   |dd      j                  d      d       d}
t        d|
      D ]7  }	|	|
z  }	| j                  |j                  |j                  |	            |	       9 t        dd      D ]m  }d| z  }	| j                  |j                  |j                  |	            |	       d|	z
  }	| j                  |j                  |j                  |	            |	       o t        d      D ]4  }| j                  |j                  |j                  |            |d       6 | j                  | j                   j                        5  |j                  d       d d d        | j                  | j                   j                        5  |j                  d       d d d        | j                  | j                   j                        5  |j                  d       d d d        | j                  | j                   j                        5  |j                  d       d d d         |dd      }| j                  |j                  d      d       | j                  t        j                  |j                  t        d                         y # 1 sw Y   .xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nr   r{   r   )
rr   gRQ?gS㥛@gS
@gT㥛 @g^I@g rh@g+N@gC@gV-o@)
g rh?g\(\?g~jt@g+@gMbX9@g(\B@gv@g@gSc@gK7A@)
gPn?gS㥛@gQ@gn@g(\@gPn@g@g r@gˡE@glq@)r  rF  r   r
   )startr  r   ra  r   r  r   g>?g  E@i   3   r)  r  r   rr   r   g?r   r  )rX  r   rD   inv_cdfr  itemsrb   rM  r  r!  r5  rr  r   r   r   r   )rH   r   iqr$  ppr&   rowr  r   r  r   rf   s               r   test_inv_cdfzTestNormalDist.test_inv_cdf
  s,    [[++
 R D)2773
 L777	8  	BID##Cq1 BQ4SD>)&&		!}a&B!G&&qyy|Qq&A	B	B 	z"c2::8DiP q! 	=AFA""266"**Q-#8!<	= q" 	=AA""266"**Q-#8!<aA""266"**Q-#8!<		= s 	GA""2::bffQi#8!A"F	G t{{::; 	JJsO	t{{::; 	JJt	t{{::; 	JJsO	t{{::; 	JJsO	 QC#. 	

199U5\#:;<	 		 		 		 	s0   -M+,M8+N*N+M58NNNc           
          | j                   j                         }dg fddgfdddgfdg dffD ]B  \  }}|j                  |	      }| j                  t	        d
 t        ||      D                     D y )Nr
   r   rr   r   gǘۿgǘ?r   )g/$rr   g/$?r  c              3   R   K   | ]  \  }}t        j                  ||d        ! yw)r   )abs_tolNr  r  s      r   r   z0TestNormalDist.test_quantiles.<locals>.<genexpr>"  s,       ? $1 !%Q6 B B  ?s   %')rX  r   r  r   r  rc   )rH   r$  r   r%   r$   s        r   test_quantileszTestNormalDist.test_quantiles  s    KK""$GJ&!"&'	 	@KAx [[1[%FOOC  ?(+Hf(= ? ? @	@r   c                 x   | j                   j                  } |dd       |dd      df |dd       |dd      dffD ]L  \  }}}| j                  |j                  |      |d       | j                  |j                  |      |d       N dd	d
d} |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      f |dd       |dd      ffD ]Y  \  }}| j                  |j                  |       |||      d	       | j                  |j                  |       |||      d	       [  |       }| j	                  t
              5  |j                          d d d        | j	                  t
              5  |j                  ||       d d d        | j	                  t
              5  |j                  d        d d d        | j	                  | j                   j                        5  |j                   |dd             d d d        | j	                  | j                   j                        5   |dd      j                  |       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   y xY w)Nrr   r)  r   gɎ@?gM-[닄?r   ra  i    r   )stepsr*  c                   t         j                  }| j                  |j                  z   dz  }|t        | j                  |j                        z  }||z
  }d|z  |z  }t        |      D 	cg c]
  }	||	|z  z    }
}	t        t        | j                  |
            }t        t        |j                  |
            }t         ||       ||            } |t        t        ||            |z  S c c}	w )z0Numerical integration cross-check for overlap() r)  )
r   r  r  r"   rI  r  r  r   r   r   )r  r&  r;  r*  r  centerwidthr.  r"  re   x_arrxpypr  s                 r   overlap_numericz4TestNormalDist.test_overlap.<locals>.overlap_numeric1  s    99Dffqvvo,FAGGQWW--EUNEuu$B+0<8aUQrT\8E8c!%%'(Bc!%%'(BR$r(+ECR()E11	 9s   *C+r  r  r  r   r{   r  r  ir      r   r  gjt?g~jth?gjt?ga2U0*3?gMbX?r
   r   )rX  r   rM  overlapr5  r  rr  )rH   r   X1X2published_resultrB  r  s          r   test_overlapzTestNormalDist.test_overlap%  s[   [[++
 C%z#s';WEC%z#s';WE) 	O$B$ ""2::b>3CA"N""2::b>3CA"N	O ,1A 	2 C%z#s';<C%z#s';<C%z#s';<B"Jr3$78C$jb&9:D"%z#r':;D"%z$';<C$jb&9:C$jb&9:C$jb&9:C$jb&9:E5):eU+CDE5):eV+DEE5):eU+CD) 	VFB, ""2::b>?2r3JST"U""2::b>?2r3JST"U/	V4 Ly) 	IIK	y) 	IIaO	y) 	IIdO	t{{::; 	(IIjA&'	(t{{::; 	(q!$$Q'	( 	(	 		 		 		( 	(	( 	(s<   ;L )LLL$L0 L	LL!$L-0L9c                    | j                   j                  } |dd      }| j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d      d       | j	                  t
              5  |j                          d d d        | j	                  t
              5  |j                  dd       d d d        | j	                  t
              5  |j                  d        d d d        | j	                  | j                   j                        5   |dd	      j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   y xY w)
Nr   r{      gffffff@r  gffffffrr   r
   r   )rX  r   rD   zscorer5  r  rr  )rH   r   r  s      r   test_zscorezTestNormalDist.test_zscored  s6   [[++
sB#,"t,#,y) 	HHJ	y) 	HHQN	y) 	HHTN	t{{::; 	)q!##C(	) 	)	 		 		 		) 	)s0   EE#6E/5E;E #E,/E8;Fc                 T   | j                   j                  dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  |j                  d       | j                  |j                  d       y )Nr   r{      )rX  r   rD   r  r;  r  rI  r	  )rH   r  s     r   test_propertieszTestNormalDist.test_propertiess  s|    KK""3+%3'%"%S)r   c                     | j                   j                  } |dd      } |dd      }| j                  ||z    |dd             | j                  ||z
   |dd             y )Nr   r   r  r      r  r  )rX  r   rD   rH   r   r  r&  s       r   'test_same_type_addition_and_subtractionz6TestNormalDist.test_same_type_addition_and_subtraction{  s_    [[++
sBr1Q
3 34Q
2r 23r   c                    | j                   j                  } |dd      }d}| j                  | |dd             | j                  |  |dd             | j                  ||z    |dd             | j                  ||z    |dd             | j                  ||z
   |dd             | j                  ||z
   |dd             | j                  ||z   |dd	             | j                  ||z   |dd	             | j                  ||z   |dd
             | j                  t              5  ||z   d d d        y # 1 sw Y   y xY w)Nr   r{   r   r  r  r  ir%  rC  r   )rX  r   rD   r5  r  )rH   r   r  r-   s       r   test_translation_and_scalingz+TestNormalDist.test_translation_and_scaling  s;   [[++
sB!ZR01!Zb12Q
3 34Q
3 34Q
2r 23Q
3 34Q
4 56Q
4 56Q
2s 34y) 	E	 	 	s   /D>>Ec                    | j                   j                  } |dd      }|}| j                  ||       | j                  |j                  |j                         | j                  |j
                  |j
                         | }| j                  ||       | j                  |j                  |j                          | j                  |j
                  |j
                         y )Nr   r   )rX  r   assertIsNotrD   r  rI  rR  s       r   test_unary_operationsz$TestNormalDist.test_unary_operations  s    [[++
sBBA(!''*BA!&&)!''*r   c                    | j                   j                  } |       } |dd      } |       } |dd      } |dd      } |dd      }| j                  ||       | j                  ||       | j                  ||       | j                  ||       | j                  ||        G d d      } |       }	| j                  |j	                  |	      t
               | j                  ||	k(  d       | j                  |	|k(  d        G d d|      }
 |
d	d
d      } |d	d
      }| j                  ||        G d d      } |d	d
      } |d	d
      }| j                  ||       y )Nr   r   r   c                       e Zd Zd Zy)'TestNormalDist.test_equality.<locals>.Ac                      yr  r9   )rH   r)  s     r   __eq__z.TestNormalDist.test_equality.<locals>.A.__eq__  s    r   N)r5   r6   r7   r]  r9   r   r   r  r[    s    r   r  r   c                        e Zd Z fdZ xZS )5TestNormalDist.test_equality.<locals>.SizedNormalDistc                 4    t         |   ||       || _        y rh   )r  __init__r   )rH   r  r  r   r  s       r   ra  z>TestNormalDist.test_equality.<locals>.SizedNormalDist.__init__  s     U+r   )r5   r6   r7   ra  r  r  s   @r   SizedNormalDistr_    s     r   rb  r   r{   9   c                       e Zd Zd Zy)3TestNormalDist.test_equality.<locals>.LognormalDistc                      || _         || _        y rh   )r  r  )rH   r  r  s      r   ra  z<TestNormalDist.test_equality.<locals>.LognormalDist.__init__  s    "
r   N)r5   r6   r7   ra  r9   r   r   LognormalDistre    s    #r   rg  )rX  r   re  rD   r]  NotImplemented)rH   r   nd1nd2nd3nd4nd5nd6r  r   rb  srg  lndr  s                  r   test_equalityzTestNormalDist.test_equality  s^   [[++
lAlAAAC%c"c"C%C%	 	 CA72&c2&	j 	 CR(b!C 
	# 	# C$R B$r   c                     | j                   j                  dd      }t        j                  |      }| j                  ||       t        j                  |      }| j                  ||       y )N     B@     @)rX  r   copyrD   deepcopy)rH   r  ri  rj  s       r   	test_copyzTestNormalDist.test_copy  sS    [[##D%0iimS!mmBS!r   c                 D   | j                   j                  dd      }t        t        j                  dz         D ]Y  }| j                  |      5  t        j                  t        j                  ||            }| j                  ||       d d d        [ y # 1 sw Y   fxY w)Nrs  rt  r
   )proto)protocol)	rX  r   r  pickleHIGHEST_PROTOCOLr  loadsdumpsrD   )rH   r  ry  pickleds       r   test_picklezTestNormalDist.test_pickle  s    [[##D%0622Q67 	.EE* . ,,v||B'GH  W-. .	.. .s   =BB	c                     | j                   j                  } |dd       |dd       |dd       |dd       |dd      h}| j                  t        |      d       y )Nr   r{   r  g      .@r   r  r   )rX  r   rD   r_   )rH   NDro  s      r   test_hashabilityzTestNormalDist.test_hashability  sS    [[##R["UD/2c2;2r
BsBKPQ#r   c                 r    | j                   j                  dd      }| j                  t        |      d       y )Nrs  rt  z NormalDist(mu=37.5, sigma=5.625))rX  r   rD   reprr  s     r   	test_reprzTestNormalDist.test_repr  s-    [[##D%0b#EFr   N)r5   r6   r7   r  r  r  r  r'  r,  r   skip_if_pgo_taskrE  r5  r9  rH  rL  rO  rS  rU  rX  rq  rw  r  r  r  r9   r   r   r  r  @
  s    A3,3**,%9N9< Wu%?= & ?=B@=(~)*4 
+*%X".$
Gr   r  c                       e Zd ZeZd Zd Zy)TestNormalDistPythonc                 >    | j                   t        j                  d<   y rB   rX  rl  modulesrt   s    r   r  zTestNormalDistPython.setUp      $(KKL!r   c                 2    t         t        j                  d<   y rB   r:   rl  r  rt   s    r   tearDownzTestNormalDistPython.tearDown      $.L!r   N)r5   r6   r7   rF   rX  r  r  r9   r   r   r  r    s    F0/r   r  rK   c                       e Zd ZeZd Zd Zy)TestNormalDistCc                 >    | j                   t        j                  d<   y rB   r  rt   s    r   r  zTestNormalDistC.setUp  r  r   c                 2    t         t        j                  d<   y rB   r  rt   s    r   r  zTestNormalDistC.tearDown  r  r   N)r5   r6   r7   rM   rX  r  r  r9   r   r   r  r    s    F0/r   r  c                 L    |j                  t        j                                |S )z&Used for doctest/unittest integration.)addTestsrd  DocTestSuite)loadertestsignores      r   
load_testsr    s    	NN7'')*Lr   __main__)r  gHz>)Ur   r  rT   collections.abcru  r  rd  r"  r   r{  r  rl  rO   testr   test.supportr   r   r   r  r   r:   r   r   r)   r2   r4   import_fresh_modulerF   rM   rC  r?   rR   rp   rw   r   r   r   r#  r2  r:  rS  ra  rp  rw  r  r  r  r  r&  r9  rt  r  r  r  r  r  r  r  r8  rW  r[  rf  rm  r  r  r  r  r  r  r  r   rG  rP  rq  r  r  r  r  r  rP   r  r  r5   mainr9   r   r   <module>r     s_  
           
   9   
3> 2)t$	 $	V 211,;H/K0}008EH
U(## 
UXFh'' XF~)x   );Jh// ;J|=B8,, =B@,X.. ,>tEX.. tEnKh// K8	GH-- 	G"%(++ %ZC(## C,$x   $
(++ 
=8X&& =8@1)** 1)h68$$ 6&a9"" a9H;-(## ;-|&(## &<`/ `/F'. '.T	#)+> 	#7Fo 7Ft
?_ 
?;K ;K@9( 9(]>.A ]>@v(6I v(r65, 65r
*= 
4J 3 464Z!4 46u@
 u@p:,.A :,z,H%% ,A1!! A1L?:. ?:D)-&9L )-X,-%8K ,-\7#_ 7"_kh'' _kD9"O 9(fM)) fMRa+H%% a+H3h// 3>&N8#4#4 &NP%68,, %6N_G _GJ/8,,n / \#9:/h'' / ;/ zHMMO r   