B
    u9ac)                @   sP  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
 d dlZdd Zdd Zdd	 Zd_ddZG dd dZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG d d! d!ejZG d"d# d#ejZG d$d% d%ejZG d&d' d'ejZG d(d) d)ejZG d*d+ d+ejZG d,d- d-ejZ G d.d/ d/ejZ!G d0d1 d1ejZ"G d2d3 d3ejZ#G d4d5 d5Z$G d6d7 d7Z%G d8d9 d9e$e%Z&G d:d; d;eZ'G d<d= d=eZ(G d>d? d?eZ)G d@dA dAe$Z*G dBdC dCee*e%Z+G dDdE dEee*e%Z,G dFdG dGee*Z-G dHdI dIee%Z.G dJdK dKe-e%Z/G dLdM dMe-e%Z0G dNdO dOe-Z1G dPdQ dQee*e%Z2G dRdS dSe$Z3G dTdU dUe3ee%Z4G dVdW dWe3ee%Z5G dXdY dYe3eZ6G dZd[ d[e3eZ7d\d] Z8e9d^krLe:  dS )`    N)Decimal)Fractionc             C   s   t d| S )N   )mathcopysign)x r   %/usr/lib/python3.7/test_statistics.pysign   s    r
   c             C   sZ   t | t |k	rdS t| tr2t| o0t|S |  d }| d }||koX|dkS )NF   )nN)type
isinstancefloatr   isnanZas_tuple)abZaexpZbexpr   r   r	   
_nan_equal   s    
r   c             C   s:   t t| t|}t| | }|r*|| ntd}||fS )Ninf)maxabsr   )actualexpectedbaseabs_errrel_errr   r   r	   _calc_errors<   s    
r   -q=Hz>c             C   s   |dk s|dk rt dt| s,t|r0dS | |kr<dS t| sPt|rTdS t| | }t||tt| t| }||kS )Nr   z%error tolerances must be non-negativeFT)
ValueErrorr   r   isinfr   r   )r   ytolrelZactual_errorZallowed_errorr   r   r	   approx_equalL   s    "r%   c               @   s   e Zd ZdS )
_DoNothingN)__name__
__module____qualname__r   r   r   r	   r&      s   $r&   c               @   s<   e Zd Zd ZZdddZdd ZdddZed	d
 Z	dS )NumericTestCaser   Nc             C   sZ   |d kr| j }|d kr| j}t|tjjr@t|tjjr@| j}n| j}|||||| d S )N)r#   r$   r   collectionsabcSequence_check_approx_seq_check_approx_num)selffirstsecondr#   r$   msgcheckr   r   r	   assertApproxEqual   s    z!NumericTestCase.assertApproxEqualc       
   	   C   sr   t |t |kr:dt |t |f }| ||}| |x2tt||D ] \}\}}	| ||	|||| qJW d S )Nz0sequences differ in length: %d items != %d items)len_formatMessagefailureException	enumeratezipr/   )
r0   r1   r2   r#   r$   r3   standardMsgir   er   r   r	   r.      s    
z!NumericTestCase._check_approx_seqc             C   s>   t ||||rd S | |||||}| ||}| |d S )N)r%   _make_std_err_msgr7   r8   )r0   r1   r2   r#   r$   r3   idxr;   r   r   r	   r/      s
    z!NumericTestCase._check_approx_numc       	      C   s>   d}|d k	rd| }|| }t | |\}}|| |||||f 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   )	r1   r2   r#   r$   r?   templateheaderr   r   r   r   r	   r>      s    z!NumericTestCase._make_std_err_msg)NNN)N)
r'   r(   r)   r#   r$   r5   r.   r/   staticmethodr>   r   r   r   r	   r*      s
   
+
	r*   c               @   s   e Zd Zdd ZdS )TestSignc             C   s$   |  tdd |  tdd d S )Ng        r   g       )assertEqualr
   )r0   r   r   r	   
testZeroes  s    zTestSign.testZeroesN)r'   r(   r)   rF   r   r   r   r	   rC     s   rC   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ApproxEqualSymmetryTestc             C   sX   dddt dtddg}ddd	t d
tddg}x"t||D ]\}}| || q<W d S )Ni	  gfffffB@gfffff(z2.54   6   i	  gB@gR(z2.59   )r   r   r:   do_relative_symmetry)r0   Zargs1Zargs2r   r   r   r   r	   test_relative_symmetry  s    
z.ApproxEqualSymmetryTest.test_relative_symmetryc             C   st   t ||t|| }}|| }t|| t||  }}|| d }| t||d|d | t||d|d d S )Nr   r   )r#   r$   )minr   r   
assertTruer%   )r0   r   r   deltaZrel_err1Zrel_err2r$   r   r   r	   rK   -  s    z,ApproxEqualSymmetryTest.do_relative_symmetryc             C   s  dddddg}d}x|D ]}xt tttfD ]}||d }|| }t|t|| }| j||||d | j|||d	 d| d | j|||d	 |d d | j||||d d | j|||d	 |d | j|||d	 d| d | j||d
d
d | j||d
d
d q*W qW d S )Ni   k   im r   d   )r#   r$   r   r   )intr   r   r   r   r   do_symmetry_test)r0   argsrO   r   type_r   r"   rr   r   r	   test_symmetry9  s    
z%ApproxEqualSymmetryTest.test_symmetryc          
   C   s@   d}t ||||}t ||||}| |||||||f d S )Nz+approx_equal comparisons don't match for %r)r%   rE   format)r0   r   r   r#   r$   r@   Zflag1Zflag2r   r   r	   rU   Q  s    z(ApproxEqualSymmetryTest.do_symmetry_testN)r'   r(   r)   rL   rK   rY   rU   r   r   r   r	   rG     s   rG   c               @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )ApproxEqualExactTestc             C   sJ   t ||||d}| |d|  t | | ||d}| |d|   d S )N)r#   r$   zequality failure for x=%r)r%   rN   )r0   r   r#   r$   resultr   r   r	   do_exactly_equal_test^  s    z*ApproxEqualExactTest.do_exactly_equal_testc             C   s    xdD ]}|  |dd qW d S )N)*   iM  i~:     i  iU
 i  r   )r]   )r0   r   r   r   r	   test_exactly_equal_intsd  s    
z,ApproxEqualExactTest.test_exactly_equal_intsc             C   s    xdD ]}|  |dd qW d S )N)gzG?g/$?ge@g      7@g     pf@g!rhQ@gB`"KB@r   )r]   )r0   r   r   r   r	   test_exactly_equal_floatsi  s    
z.ApproxEqualExactTest.test_exactly_equal_floatsc             C   sR   t }xH|dd|d|dd|dd|dd	|ddgD ]}| |dd q8W d S )
Nr   r   r   rQ      	      #   $   )r   r]   )r0   Ffr   r   r	   test_exactly_equal_fractionsn  s    8z1ApproxEqualExactTest.test_exactly_equal_fractionsc             C   s.   t }x$t|d D ]}| |dd qW d S )Nz8.2 31.274 912.04 16.745 1.2047r   )r   mapsplitr]   )r0   Ddr   r   r	   test_exactly_equal_decimalst  s    z0ApproxEqualExactTest.test_exactly_equal_decimalsc             C   sJ   xDdD ]<}|  |dd |  |d dd t|d}|  |dd qW d S )N)   i  i\  i  i     g{Gz?r   
   i  )r]   r   )r0   r   rh   r   r   r	   test_exactly_equal_absolutez  s
    

z0ApproxEqualExactTest.test_exactly_equal_absolutec             C   s2   |  tdtdd |  td tdd d S )Nz3.571z0.01r   z81.3971)r]   r   )r0   r   r   r	   $test_exactly_equal_absolute_decimals  s    z9ApproxEqualExactTest.test_exactly_equal_absolute_decimalsc             C   sD   x(dddt ddgD ]}| |dd qW | tddtd	 d S )
Ni   g33333SY@gzGrQ      r   g{Gz?z11.68z0.01)r   r]   r   )r0   r   r   r   r	   test_exactly_equal_relative  s    z0ApproxEqualExactTest.test_exactly_equal_relativec             C   sL   x(dddt ddgD ]}| |dd qW t}| |d|d	|d
 d S )Ni9  gˡE0@g\(hrb      g?g{Gz?z7.2z0.1z0.01)r   r]   r   )r0   r   rl   r   r   r	   test_exactly_equal_both  s    z,ApproxEqualExactTest.test_exactly_equal_bothN)r'   r(   r)   r]   r`   ra   ri   rn   rr   rs   ru   rw   r   r   r   r	   r[   X  s   r[   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ApproxEqualUnequalTestc             C   s<   x6|| fD ](}t ||d ddd}| |d|  qW d S )Nr   r   )r#   r$   zinequality failure for x=%r)r%   assertFalse)r0   r   r   r\   r   r   r	   do_exactly_unequal_test  s    z.ApproxEqualUnequalTest.do_exactly_unequal_testc             C   s   xdD ]}|  | qW d S )N)i  i i  i  iXC  )rz   )r0   r   r   r   r	   test_exactly_unequal_ints  s    
z0ApproxEqualUnequalTest.test_exactly_unequal_intsc             C   s   xdD ]}|  | qW d S )N)gQ#@g[@gfffffG@gףp=
W"@g=
ףp=1@)rz   )r0   r   r   r   r	   test_exactly_unequal_floats  s    
z2ApproxEqualUnequalTest.test_exactly_unequal_floatsc             C   s@   t }x6|dd|dd|dd|ddgD ]}| | q*W d S )	Nr   rQ   rd   rc         e   iς )r   rz   )r0   rg   rh   r   r   r	   test_exactly_unequal_fractions  s    *z5ApproxEqualUnequalTest.test_exactly_unequal_fractionsc             C   s&   x t td D ]}| | qW d S )Nz!3.1415 298.12 3.47 18.996 0.00245)rj   r   rk   rz   )r0   rm   r   r   r	   test_exactly_unequal_decimals  s    z4ApproxEqualUnequalTest.test_exactly_unequal_decimalsN)r'   r(   r)   rz   r{   r|   r   r   r   r   r   r	   rx     s
   rx   c               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"ApproxEqualInexactTestc          	   C   sf   d}x\|| || fD ]H}| ||}| t||d| dd| | t|||d dd| qW d S )NzTest failure for x={!r}, y={!r}r   r   )r#   r$   )rZ   rN   r%   ry   )r0   r   rO   r@   r"   r3   r   r   r	   do_approx_equal_abs_test  s
    z/ApproxEqualInexactTest.do_approx_equal_abs_testc             C   s*   x$dD ]}|  |d |  |d qW d S )N)iiIirP   r   r   rc   %   i  i&  i6jrq   r   )r   )r0   r   r   r   r	   test_approx_equal_absolute_ints  s    
z6ApproxEqualInexactTest.test_approx_equal_absolute_intsc             C   s6   x0dD ](}|  |d |  |d |  |d qW d S )N)	gtqgfffffFXg333333g333333g      ?g      ?g333333@gQ@gҭ@g      ?g{Gz?g-C6?)r   )r0   r   r   r   r	   !test_approx_equal_absolute_floats  s    
z8ApproxEqualInexactTest.test_approx_equal_absolute_floatsc             C   s\   t dd}dddddddd	d
ddg}x2dd |D D ] }| || | |t| q4W d S )Nr      iirP   rD   r   rQ   rH      "   G   c             s   s   | ]}t |d V  qdS )r   N)r   ).0r   r   r   r	   	<genexpr>  s    zNApproxEqualInexactTest.test_approx_equal_absolute_fractions.<locals>.<genexpr>)r   r   r   )r0   rO   
numeratorsrh   r   r   r	   $test_approx_equal_absolute_fractions  s
    
z;ApproxEqualInexactTest.test_approx_equal_absolute_fractionsc             C   s>   t d}x0tt d D ]}| || | | | qW d S )Nz0.01z1.0 3.5 36.08 61.79 7912.3648)r   rj   rk   r   )r0   rO   rm   r   r   r	   #test_approx_equal_absolute_decimals  s    z:ApproxEqualInexactTest.test_approx_equal_absolute_decimalsc             C   s   |  tddddd d S )Ngh㈵>gh㈵g-C6?r   )r#   r$   )rN   r%   )r0   r   r   r	   test_cross_zero  s    z&ApproxEqualInexactTest.test_cross_zeroc          	   C   sn   d}xd|d|  |d|  fD ]H}| ||}| t||dd| d| | t||d|d d| qW d S )NzTest failure for x={!r}, y={!r}r   r   r   )r#   r$   )rZ   rN   r%   ry   )r0   r   rO   r@   r"   r3   r   r   r	   do_approx_equal_rel_test  s
    z/ApproxEqualInexactTest.do_approx_equal_rel_testc             C   sr   |  tddddd |  tddddd |  tdddd	d |  td
ddd	d | tdddd	d d S )N@   /   r   g
ףp=
?)r#   r$   gGz?i  i   g      ?i  i  )rN   r%   ry   )r0   r   r   r	   test_approx_equal_relative_ints  s
    z6ApproxEqualInexactTest.test_approx_equal_relative_intsc             C   s*   x$dD ]}|  |d |  |d qW d S )N)g{GJfgg?g      ?g\(|B@gʡE>@gx@g{Gz?g-C6?)r   )r0   r   r   r   r	   !test_approx_equal_relative_floats  s    
z8ApproxEqualInexactTest.test_approx_equal_relative_floatsc             C   sp   t }t dd}x\|dd|dd|dd|dd	gD ]4}x.|t|fD ]}| || | | | qFW q4W d S )
Nrb   rv   T   rH      1   2   \   U   )r   r   r   )r0   rg   rO   rh   rm   r   r   r	   $test_approx_equal_relative_fractions  s    
*z;ApproxEqualInexactTest.test_approx_equal_relative_fractionsc             C   s>   x8t td D ]&}| |td | | td qW d S )Nz$0.02 1.0 5.7 13.67 94.138 91027.9321z0.001z0.05)rj   r   rk   r   )r0   rm   r   r   r	   #test_approx_equal_relative_decimals  s    z:ApproxEqualInexactTest.test_approx_equal_relative_decimalsc             C   st   |r
| j n| j}|t|||dd |r.| j n| j}|t||d|d |sP|rV| j n| j}|t||||d d S )Nr   )r#   r$   )rN   ry   r%   )r0   r   r   r#   r$   Ztol_flagZrel_flagr4   r   r   r	   do_check_both  s    z$ApproxEqualInexactTest.do_check_bothc             C   s,   |  dddddd |  dddd	dd d S )
NgR@g+@gMbp?gW8?Tg?5^Ig%CgMb`?g-C6*?)r   )r0   r   r   r	   test_approx_equal_both1  s    z.ApproxEqualInexactTest.test_approx_equal_both1c             C   s   |  dddddd d S )NgR@g+@gMbp?gVF?8?TF)r   )r0   r   r   r	   test_approx_equal_both2   s    z.ApproxEqualInexactTest.test_approx_equal_both2c             C   s   |  dddddd d S )NgR@g+@gMbP?gW8?FT)r   )r0   r   r   r	   test_approx_equal_both3$  s    z.ApproxEqualInexactTest.test_approx_equal_both3c             C   s,   |  dddddd |  dddd	dd d S )
Ng=
ףp=@g      @g{Gz?gMbP?FgQ[@g(\[@g{Gz?giUMu>)r   )r0   r   r   r	   test_approx_equal_both4(  s    z.ApproxEqualInexactTest.test_approx_equal_both4N)r'   r(   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r     s    		r   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ApproxEqualSpecialsTestc             C   s   xt tfD ]z}|d}| t|| | t||dd | t||dd | t| |  | t||  | t|d q
W d S )Nr   r   r   g{Gz?i  )r   r   rN   r%   ry   )r0   rW   r   r   r   r	   test_inf1  s    z ApproxEqualSpecialsTest.test_infc             C   sF   x@t tfD ]4}|d}x&||ddfD ]}| t|| q&W q
W d S )Nnanr   i  )r   r   ry   r%   )r0   rW   r   otherr   r   r	   test_nan;  s    z ApproxEqualSpecialsTest.test_nanc             C   s&   t dd}| t|dddd d S )Ng        rD   g?)r#   r$   )r   r   rN   r%   )r0   nzeror   r   r	   test_float_zeroesA  s    z)ApproxEqualSpecialsTest.test_float_zeroesc             C   s&   t d}| t|t dddd d S )Nz-0.0r   g?)r#   r$   )r   rN   r%   )r0   r   r   r   r	   test_decimal_zeroesE  s    z+ApproxEqualSpecialsTest.test_decimal_zeroesN)r'   r(   r)   r   r   r   r   r   r   r   r	   r   .  s   
r   c               @   s   e Zd Zdd Zdd ZdS )TestApproxEqualErrorsc             C   s   |  ttdddd d S )NrS   rD   g?)assertRaisesr    r%   )r0   r   r   r	   test_bad_tolM  s    z"TestApproxEqualErrors.test_bad_tolc             C   s   |  ttdddd d S )NrS   r   g)r   r    r%   )r0   r   r   r	   test_bad_relQ  s    z"TestApproxEqualErrors.test_bad_relN)r'   r(   r)   r   r   r   r   r   r	   r   J  s   r   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestNumericTestCasec             C   s2   t j| }| j| }x|D ]}| || qW d S )N)r*   r>   generate_substringsZassertIn)r0   rV   Z
actual_msgr   Z	substringr   r   r	   do_testa  s    


zTestNumericTestCase.do_testc             C   s   |  tttj d S )N)rN   
issubclassr*   unittestTestCase)r0   r   r   r	    test_numerictestcase_is_testcaseg  s    z4TestNumericTestCase.test_numerictestcase_is_testcasec             C   s   d}|  | d S )N)g      @g      @g      ?g      ?N)r   )r0   rV   r   r   r	   test_error_msg_numerick  s    z*TestNumericTestCase.test_error_msg_numericc             C   s   d}|  | d S )N)g      @g      @g      ?g      ?rd   )r   )r0   rV   r   r   r	   test_error_msg_sequencep  s    z+TestNumericTestCase.test_error_msg_sequencec       	      C   sD   t ||\}}d| d| d| d| g}|d k	r@|d|  |S )Nztol=%rzrel=%rzabsolute error = %rzrelative error = %rzdiffer at index %d)r   append)	r0   r1   r2   r#   r$   r?   r   r   Z
substringsr   r   r	   r   u  s    
z'TestNumericTestCase.generate_substringsN)r'   r(   r)   r   r   r   r   r   r   r   r   r	   r   [  s
   r   c               @   s(   e Zd ZeZddgZdd Zdd ZdS )GlobalsTest__doc____all__c             C   s,   x&| j D ]}| t| j|d|  qW d S )Nz%s not present)expected_metadatarN   hasattrmodule)r0   metar   r   r	   	test_meta  s    zGlobalsTest.test_metac             C   sF   | j }x:|jD ]0}| |dd|  | t||d|  qW d S )N_zprivate name "%s" in __all__zmissing name "%s" in __all__)r   r   ry   
startswithrN   r   )r0   r   namer   r   r	   test_check_all  s    
zGlobalsTest.test_check_allN)r'   r(   r)   
statisticsr   r   r   r   r   r   r   r	   r     s   r   c               @   s(   e Zd Zeejjdkddd ZdS )DocTestsr   z)Docstrings are omitted with -OO and abovec             C   s0   t jtt jd\}}| |d | |d d S )N)Zoptionflagsr   )doctestZtestmodr   ELLIPSISassertGreaterrE   )r0   ZfailedZtriedr   r   r	   test_doc_tests  s    zDocTests.test_doc_testsN)	r'   r(   r)   r   ZskipIfsysflagsoptimizer   r   r   r   r	   r     s   r   c               @   s   e Zd Zdd ZdS )StatisticsErrorTestc             C   s4   d}|  ttd |  ttjt|tjj  d S )NzNExpected StatisticsError to be a ValueError, but got a subclass of %r instead.StatisticsError)rN   r   r   r   r   r    __base__)r0   errmsgr   r   r	   test_has_exception  s
    
z&StatisticsErrorTest.test_has_exceptionN)r'   r(   r)   r   r   r   r   r	   r     s   r   c               @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )ExactRatioTestc             C   s(   x"dD ]}|  t||df qW d S )N)ir   rQ   c   l      Fx:^V r   )rE   r   _exact_ratio)r0   r<   r   r   r	   test_int  s    
zExactRatioTest.test_intc             C   s6   d}x,|D ]$}t |d}| t||df q
W d S )N)r   r}   &   r   )r   rE   r   r   )r0   r   r   rh   r   r   r	   test_fraction  s    

zExactRatioTest.test_fractionc             C   sf   |  tdd |  tdd dd tdD }x*|D ]"}t|\}}|  |||  q<W d S )Ng      ?)r   rv   g      ?)rc   rv   c             S   s   g | ]}t d dqS )irS   )randomuniform)r   r   r   r   r	   
<listcomp>  s    z-ExactRatioTest.test_float.<locals>.<listcomp>rS   )rE   r   r   range)r0   datar   numdenr   r   r	   
test_float  s    
zExactRatioTest.test_floatc             C   sJ   t }tj}| ||dd | ||dd | ||dd d S )Nz0.125)r   rv   z12.345)i	     z-1.98)ir   )r   r   r   rE   )r0   rl   r   r   r   r	   test_decimal  s
    zExactRatioTest.test_decimalc             C   s   t d}G dd dt }G dd dt}xr|| fD ]d}x^t |t|fD ]N}||}t|}| ||d f | t|d | | t|d  qFW q4W d S )NINFc               @   s   e Zd ZdS )z(ExactRatioTest.test_inf.<locals>.MyFloatN)r'   r(   r)   r   r   r   r	   MyFloat  s   r   c               @   s   e Zd ZdS )z*ExactRatioTest.test_inf.<locals>.MyDecimalN)r'   r(   r)   r   r   r   r	   	MyDecimal  s   r   r   )	r   r   r   r   rE   r   rN   r   r!   )r0   r   r   r   r   rW   r   ratior   r   r	   r     s    
zExactRatioTest.test_infc             C   sx   t d}G dd dt }xZ|||fD ]J}t|}| t|d  | |d d  | t|d t| q&W d S )NNANc               @   s   e Zd ZdS )z.ExactRatioTest.test_float_nan.<locals>.MyFloatN)r'   r(   r)   r   r   r   r	   r     s   r   r   r   )	r   r   r   rN   r   r   assertIsrE   r   )r0   r   r   r   r   r   r   r	   test_float_nan  s    
zExactRatioTest.test_float_nanc             C   s   t d}t d}G dd dt }xb||||||fD ]J}t|}| t|d | | |d d  | t|d t| q6W d S )Nr   sNANc               @   s   e Zd ZdS )z2ExactRatioTest.test_decimal_nan.<locals>.MyDecimalN)r'   r(   r)   r   r   r   r	   r     s   r   r   r   )r   r   r   rN   r   r   rE   r   )r0   r   r   r   r   r   r   r   r	   test_decimal_nan  s    
zExactRatioTest.test_decimal_nanN)
r'   r(   r)   r   r   r   r   r   r   r   r   r   r   r	   r     s   
r   c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )DecimalToRatioTestc             C   s<   t d}| t||d f | t| | d f d S )Nr   )r   rE   r   r   )r0   r   r   r   r	   test_infinity  s    z DecimalToRatioTest.test_infinityc             C   sH   xBt dt dfD ].}t|\}}| t|| | |d  qW d S )Nr   r   )r   r   r   rN   r   r   )r0   r   r   r   r   r   r	   r     s    zDecimalToRatioTest.test_nanc             C   sp   t dt dg}xZ|D ]R}t|\}}| |d | |d t| \}}| |d | |d qW d S )Nz	9.8765e12z
9.8765e-12r   )r   r   r   assertGreaterEqualr   ZassertLessEqual)r0   Znumbersrm   r   r   r   r   r	   	test_sign  s    
zDecimalToRatioTest.test_signc             C   s   t td}| |d d S )Nz0.1234)ii  i  )r   r   r   rE   )r0   tr   r   r	   test_negative_exponent  s    z)DecimalToRatioTest.test_negative_exponentc             C   s   t td}| |d d S )Nz1.234e7)i K r   )r   r   r   rE   )r0   r   r   r   r	   test_positive_exponent  s    z)DecimalToRatioTest.test_positive_exponentc             C   s8   t td}| |d t td}| |d d S )NZ1e2)rS   r   z1.47e5)i8> r   )r   r   r   rE   )r0   r   r   r   r	   test_regression_20536   s    z(DecimalToRatioTest.test_regression_20536N)	r'   r(   r)   r   r   r   r   r   r   r   r   r   r	   r     s   
r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )IsFiniteTestc             C   s4   x.dt dddtdfD ]}| t| qW d S )NrQ   r   rb   g      @z5.5)r   r   rN   r   	_isfinite)r0   r   r   r   r	   test_finite,  s    zIsFiniteTest.test_finitec             C   s.   x(t dtdfD ]}| t| qW d S )Nr   )r   r   ry   r   r   )r0   r   r   r   r	   r   1  s    zIsFiniteTest.test_infinityc             C   s4   x.t dtdtdfD ]}| t| qW d S )Nr   r   r   )r   r   ry   r   r   )r0   r   r   r   r	   r   6  s    zIsFiniteTest.test_nanN)r'   r(   r)   r   r   r   r   r   r   r	   r   )  s   r   c               @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )
CoerceTestc             C   sR   xLt tttfD ]<}| t|t| G dd d|}| t|t| qW d S )Nc               @   s   e Zd ZdS )z%CoerceTest.test_bool.<locals>.MyClassN)r'   r(   r)   r   r   r   r	   MyClassW  s    r   )rT   r   r   r   r   r   _coercebool)r0   Tr   r   r   r	   	test_boolQ  s    zCoerceTest.test_boolc             C   s,   |  t||| |  t||| d S )N)r   r   r   )r0   ABr   r   r	   assertCoerceToZ  s    zCoerceTest.assertCoerceToc             C   sT   |  || G dd d|}|  || G dd d|}|  || |  || d S )Nc               @   s   e Zd ZdS )z/CoerceTest.check_coerce_to.<locals>.SubclassOfAN)r'   r(   r)   r   r   r   r	   SubclassOfAd  s    r  c               @   s   e Zd ZdS )z/CoerceTest.check_coerce_to.<locals>.SubclassOfBN)r'   r(   r)   r   r   r   r	   SubclassOfBg  s    r  )r  )r0   r   r   r  r  r   r   r	   check_coerce_to_  s    zCoerceTest.check_coerce_toc             C   s,   |  ttj||f |  ttj||f d S )N)r   	TypeErrorr   r   )r0   r   r   r   r   r	   assertCoerceRaisesk  s    zCoerceTest.assertCoerceRaisesc             C   s   |  t||| G dd d|}G dd d|}G dd d|}x|||fD ]}| || qPW | || | || | || d S )Nc               @   s   e Zd ZdS )z*CoerceTest.check_type_coercions.<locals>.UN)r'   r(   r)   r   r   r   r	   Uv  s    r  c               @   s   e Zd ZdS )z*CoerceTest.check_type_coercions.<locals>.VN)r'   r(   r)   r   r   r   r	   Vw  s    r  c               @   s   e Zd ZdS )z*CoerceTest.check_type_coercions.<locals>.WN)r'   r(   r)   r   r   r   r	   Wx  s    r	  )r   r   r   r  r  )r0   r   r  r  r	  typr   r   r	   check_type_coercionsp  s    zCoerceTest.check_type_coercionsc             C   s.   |  t xtttfD ]}| t| qW d S )N)r  rT   r   r   r   r  )r0   r
  r   r   r	   r     s    
zCoerceTest.test_intc             C   s   |  t | tt d S )N)r  r   r  r   )r0   r   r   r	   r     s    
zCoerceTest.test_fractionc             C   s   |  t d S )N)r  r   )r0   r   r   r	   r     s    zCoerceTest.test_decimalc             C   s   |  t d S )N)r  r   )r0   r   r   r	   r     s    zCoerceTest.test_floatc             C   sB   x<t ttd ttfD ]&}x ttttfD ]}| 	|| q&W qW d S )N)
strlistr   tupledictrT   r   r   r   r  )r0   Zbad_typeZ	good_typer   r   r	   test_non_numeric_types  s    z!CoerceTest.test_non_numeric_typesc             C   s>   x8t tfD ],}G dd d|}| |t | |t q
W d S )Nc               @   s   e Zd ZdS )z6CoerceTest.test_incompatible_types.<locals>.MySubclassN)r'   r(   r)   r   r   r   r	   
MySubclass  s    r  )r   r   r  r   )r0   r   r  r   r   r	   test_incompatible_types  s    z"CoerceTest.test_incompatible_typesN)r'   r(   r)   r   r  r  r  r  r   r   r   r   r  r  r   r   r   r	   r   <  s   	r   c               @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )ConvertTestc             C   s$   |  || | t|t| d S )N)rE   r   r   )r0   r   r"   r   r   r	   check_exact_equal  s    zConvertTest.check_exact_equalc             C   sP   t tdt}| |d G dd dt}t td|}| ||d d S )Nr   c               @   s   e Zd ZdS )z#ConvertTest.test_int.<locals>.MyIntN)r'   r(   r)   r   r   r   r	   MyInt  s    r  rH   )r   _convertr   rT   r  )r0   r   r  r   r   r	   r     s
    zConvertTest.test_intc             C   s\   t tddt}| |tdd G dd dt}t tdd|}| ||dd d S )N_   r   c                   s   e Zd Z fddZ  ZS )z-ConvertTest.test_fraction.<locals>.MyFractionc                s   |  t |S )N)	__class__super__truediv__)r0   r   )r  r   r	   r    s    z9ConvertTest.test_fraction.<locals>.MyFraction.__truediv__)r'   r(   r)   r  __classcell__r   r   )r  r	   
MyFraction  s   r  r      )r   r  r   r  )r0   r   r  r   r   r	   r     s
    zConvertTest.test_fractionc             C   sT   t tddt}| |d G dd dt}t tdd|}| ||d d S )	NrD   r   g      c                   s   e Zd Z fddZ  ZS )z'ConvertTest.test_float.<locals>.MyFloatc                s   |  t |S )N)r  r  r  )r0   r   )r  r   r	   r    s    z3ConvertTest.test_float.<locals>.MyFloat.__truediv__)r'   r(   r)   r  r  r   r   )r  r	   r     s   r   rc   rv   g      ?)r   r  r   r   r  )r0   r   r   r   r   r	   r     s
    zConvertTest.test_floatc             C   sX   t tddt}| |td G dd dt}t tdd|}| ||d d S )	Nr   (   z0.025c                   s   e Zd Z fddZ  ZS )z+ConvertTest.test_decimal.<locals>.MyDecimalc                s   |  t |S )N)r  r  r  )r0   r   )r  r   r	   r    s    z7ConvertTest.test_decimal.<locals>.MyDecimal.__truediv__)r'   r(   r)   r  r  r   r   )r  r	   r     s   r   iro   z-0.9375)r   r  r   r   r  )r0   r   r   r   r   r	   r     s
    zConvertTest.test_decimalc             C   sN   xHt dtdfD ]4}x.|| fD ] }t|t|}| || q"W qW d S )Nr   )r   r   r   r  r   r  )r0   r   r   r   r   r   r	   r     s    zConvertTest.test_infc             C   sD   x>t dtdtdfD ]$}t|t|}| t|| qW d S )Nr   r   r   )r   r   r   r  r   rN   r   )r0   r   r   r   r   r	   r     s    zConvertTest.test_nanN)
r'   r(   r)   r  r   r   r   r   r   r   r   r   r   r	   r    s   


r  c               @   s$   e Zd Zdd Zdd Zdd ZdS )FailNegTestc             C   s2   ddt dtdg}tt|}| || d S )Nr   g       @rb   rp   )r   r   r  r   	_fail_negrE   )r0   valuesnewr   r   r	   test_pass_through  s    zFailNegTest.test_pass_throughc             C   sD   x>ddt dtdgD ]&}| g}t|}| tjt| qW d S )Nr   g       @rb   rp   )r   r   r   r   r   r   next)r0   r   seqitr   r   r	   test_negatives_raise  s    
z FailNegTest.test_negatives_raisec          
   C   sp   dt dd }yttdg| W n. tjk
rT } z|jd }W d d }~X Y nX | d | || d S )Nzbadness #%di'  i rD   r   z(expected exception, but it didn't happen)	r   Zrandintr$  r   r   r   rV   ZfailrE   )r0   r3   r=   r   r   r   r	   test_error_msg  s    
zFailNegTest.test_error_msgN)r'   r(   r)   r#  r'  r(  r   r   r   r	   r    s   r  c               @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )UnivariateCommonMixinc             C   s   |  t| j d S )N)r   r  func)r0   r   r   r	   test_no_args  s    z"UnivariateCommonMixin.test_no_argsc             C   s.   x(g dt g fD ]}| tj| j| qW d S )Nr   )iterr   r   r   r*  )r0   emptyr   r   r	   test_empty_data  s    z%UnivariateCommonMixin.test_empty_datac             C   s,   t td}x|t|kr&t| qW |S )Nrq   )r  r   sortedr   shuffle)r0   r   r   r   r	   prepare_data  s    z"UnivariateCommonMixin.prepare_datac             C   s0   |   }|d d  }| |}| ||d d S )Nzdata has been modified)r1  r*  ZassertListEqual)r0   r   Zsavedr   r   r   r	   test_no_inplace_modifications  s    
z3UnivariateCommonMixin.test_no_inplace_modificationsc             C   sF   ddddddddgd }|  |}t| |  |}| || d S )Nr   r   rb   rp   rQ      rS   )r*  r   r0  rE   )r0   r   r   r   r   r   r	   test_order_doesnt_matter  s
    


z.UnivariateCommonMixin.test_order_doesnt_matterc             C   sr   G dd dt }G dd dt}dd }|  }| |}x2t tt|||fD ]}| ||}| || qLW d S )Nc               @   s   e Zd ZdS )zBUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyListN)r'   r(   r)   r   r   r   r	   MyList$  s   r5  c               @   s   e Zd ZdS )zCUnivariateCommonMixin.test_type_of_data_collection.<locals>.MyTupleN)r'   r(   r)   r   r   r   r	   MyTuple&  s   r6  c             S   s   dd | D S )Nc             s   s   | ]
}|V  qd S )Nr   )r   objr   r   r	   r   )  s    zXUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator.<locals>.<genexpr>r   )r   r   r   r	   	generator(  s    zEUnivariateCommonMixin.test_type_of_data_collection.<locals>.generator)r  r  r1  r*  r,  rE   )r0   r5  r6  r8  r   r   kindr\   r   r   r	   test_type_of_data_collection"  s    
z2UnivariateCommonMixin.test_type_of_data_collectionc             C   s0   t ddd}| t|}| | || d S )N   r   rb   )r   r*  r  rE   )r0   r   r   r   r   r	   test_range_data0  s    z%UnivariateCommonMixin.test_range_datac             C   s.   |  d  |  d |  d |  t  d S )Nr   g      E@)check_for_type_errorobject)r0   r   r   r	   test_bad_arg_types6  s    



z(UnivariateCommonMixin.test_bad_arg_typesc             G   s   | j t| jf|  d S )N)r   r  r*  )r0   rV   r   r   r	   r=  E  s    z*UnivariateCommonMixin.check_for_type_errorc                sl   G dd dt }|  }| |}xDt |ttfD ]4  fdd|D }t|| |}| || q0W d S )Nc                   s,   e Zd Z fddZ fddZeZ  ZS )z@UnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloatc                s   t | t |S )N)r   r  r  )r0   r   )r  r   r	   r  M  s    zLUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__truediv__c                s   t | t |S )N)r   r  __add__)r0   r   )r  r   r	   r@  O  s    zHUnivariateCommonMixin.test_type_of_data_element.<locals>.MyFloat.__add__)r'   r(   r)   r  r@  __radd__r  r   r   )r  r	   r   L  s   r   c                s   g | ]} |qS r   r   )r   r   )r9  r   r	   r   V  s    zCUnivariateCommonMixin.test_type_of_data_element.<locals>.<listcomp>)r   r1  r*  r   r   r   rE   )r0   r   rawr   r   r\   r   )r9  r	   test_type_of_data_elementH  s    
z/UnivariateCommonMixin.test_type_of_data_elementN)r'   r(   r)   r+  r.  r1  r2  r4  r:  r<  r?  r=  rC  r   r   r   r	   r)    s   
r)  c               @   s   e Zd Zdd Zdd ZdS )UnivariateTypeMixinc             C   s   G dd dt }t tt|fS )Nc                   s\   e Zd Z fddZ fddZ fddZ fddZ fd	d
Z fddZeZ	  Z
S )zHUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloatc                s   t | t |S )N)r   r  r  )r0   r   )r  r   r	   r  h  s    zTUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__truediv__c                s   t | t |S )N)r   r  __rtruediv__)r0   r   )r  r   r	   rE  j  s    zUUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rtruediv__c                s   t | t |S )N)r   r  __sub__)r0   r   )r  r   r	   rF  l  s    zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__sub__c                s   t | t |S )N)r   r  __rsub__)r0   r   )r  r   r	   rG  n  s    zQUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__rsub__c                s   t | t |S )N)r   r  __pow__)r0   r   )r  r   r	   rH  p  s    zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__pow__c                s   t | t |S )N)r   r  r@  )r0   r   )r  r   r	   r@  r  s    zPUnivariateTypeMixin.prepare_types_for_conservation_test.<locals>.MyFloat.__add__)r'   r(   r)   r  rE  rF  rG  rH  r@  rA  r  r   r   )r  r	   r   g  s   r   )r   r   r   )r0   r   r   r   r	   #prepare_types_for_conservation_teste  s    z7UnivariateTypeMixin.prepare_types_for_conservation_testc                sJ   |   }x<|  D ]0  fdd|D }| |}| t|  qW d S )Nc                s   g | ]} |qS r   r   )r   r   )r9  r   r	   r   }  s    z<UnivariateTypeMixin.test_types_conserved.<locals>.<listcomp>)r1  rI  r*  r   r   )r0   r   rm   r\   r   )r9  r	   test_types_conservedw  s
    
z(UnivariateTypeMixin.test_types_conservedN)r'   r(   r)   rI  rJ  r   r   r   r	   rD  [  s   
rD  c               @   s   e Zd Zdd ZdS )TestSumCommonc             C   s   dd }|| _ d S )Nc              W   s   t j|  \}}}t ||S )N)r   _sumr   )rV   r   valuer   r   r   r	   simplified_sum  s    z+TestSumCommon.setUp.<locals>.simplified_sum)r*  )r0   rN  r   r   r	   setUp  s    zTestSumCommon.setUpN)r'   r(   r)   rO  r   r   r   r	   rK    s   rK  c               @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestSumc             C   s   t j| _d S )N)r   rL  r*  )r0   r   r   r	   rO    s    zTestSum.setUpc             C   st   xng dt g fD ]\}| | |ttddf | | |dttddf | | |dttddf qW d S )Nr   r   r   gffffff@)r,  rE   r*  rT   r   r   )r0   r   r   r   r	   r.    s    zTestSum.test_empty_datac             C   sX   |  | ddddddddgttdd	f |  | d
ddddgdttddf d S )Nr   rQ   rb   ir;  r^   <   rv   rp   r   rd   i  i  )rE   r*  rT   r   )r0   r   r   r	   	test_ints  s    zTestSum.test_intsc             C   sL   |  | dgd ttddf |  | ddddgdttdd	f d S )
Ng      ?r;  g      @g      ?g      ?g      ?g      ?g      	@rp   )rE   r*  r   r   )r0   r   r   r	   test_floats  s    zTestSum.test_floatsc             C   s.   |  | tddgd ttdddf d S )Nr   i  i  r   )rE   r*  r   )r0   r   r   r	   test_fractions  s    zTestSum.test_fractionsc          	   C   sX   t }|d|d|d|d|d|d|d|dg}| | |t t d	d
f d S )Nz0.001z5.246z1.702z-0.025z3.974z2.328z4.617z2.843z20.686rv   )r   rE   r*  )r0   rl   r   r   r   r	   test_decimals  s
    zTestSum.test_decimalsc             C   s:   dd t dD }| jt| |d t|dd d S )Nc             S   s   g | ]}t d dqS )ii  )r   r   )r   r   r   r   r	   r     s    z7TestSum.test_compare_with_math_fsum.<locals>.<listcomp>i  r   gؗҬ<)r$   )r   r5   r   r*  r   Zfsum)r0   r   r   r   r	   test_compare_with_math_fsum  s    z#TestSum.test_compare_with_math_fsumc             C   s|   dd t dD }| |d }| |d | |dd  | |d | |dd  | |td | |dd  d S )	Nc             S   s   g | ]}t d dqS )r   i  )r   r   )r   r   r   r   r	   r     s    z/TestSum.test_start_argument.<locals>.<listcomp>rS   r   r^   r   ig@xD)r   r*  rE   r   )r0   r   r   r   r   r	   test_start_argument  s
    zTestSum.test_start_argumentc             C   s4   |  t| jdddgd |  t| jddddg d S )Nr   r   rb   Z999)r   r  r*  )r0   r   r   r	   test_strings_fail  s    zTestSum.test_strings_failc             C   s4   |  t| jdddgd |  t| jddddg d S )Nr   r   rb   s   999)r   r  r*  )r0   r   r   r	   test_bytes_fail  s    zTestSum.test_bytes_failc             C   s8   |  t| jddtdg |  t| jddgtd d S )Nr   g       @)r   r  r*  r   )r0   r   r   r	   test_mixed_sum  s    zTestSum.test_mixed_sumN)r'   r(   r)   rO  r.  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r   r   r   r	   rP    s   rP  c               @   s   e Zd Zdd ZdS )SumTortureTestc             C   s   |  tddddgd ttddf |  tddddgd ttddf tddddgd \}}}| |t |  |d | jt|d	d
d d S )Nr   g}Ô%ITg}Ô%Ii'  g     @i@  g0.++rD   g^,gV瞯<)r$   )rE   r   rL  r   r   r   r5   )r0   r   r   countr   r   r	   test_torture  s    zSumTortureTest.test_tortureN)r'   r(   r)   r^  r   r   r   r	   r\    s   r\  c               @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )SumSpecialValuesc             C   sR   xLt tfD ]@}|d}td|dgd }| t|| | t| q
W d S )Nr   r   r   )	r   r   r   rL  r   r   rN   r   r   )r0   rW   r   r\   r   r   r	   r     s
    zSumSpecialValues.test_nanc             C   s<   |  t| | t|t| | |dk|dk d S )Nr   )rN   r   r!   r   r   rE   )r0   r   r   r   r   r	   check_infinity  s    zSumSpecialValues.check_infinityc             C   sL   t dd|dgd }| || t dd|d|dgd }| || d S )Nr   r   rb   rp   )r   rL  r`  )r0   r   r\   r   r   r	   do_test_inf  s    zSumSpecialValues.do_test_infc             C   s(   t d}xdD ]}| ||  qW d S )Nr   )r   rD   )r   ra  )r0   r   r
   r   r   r	   test_float_inf  s    
zSumSpecialValues.test_float_infc             C   s(   t d}xdD ]}| ||  qW d S )Nr   )r   rD   )r   ra  )r0   r   r
   r   r   r	   test_decimal_inf  s    
z!SumSpecialValues.test_decimal_infc             C   s8   t d}tdd|d| dgd }| t| d S )Nr   r   r   rb   rp   )r   r   rL  rN   r   r   )r0   r   r\   r   r   r	   test_float_mismatched_infs  s    z+SumSpecialValues.test_float_mismatched_infsc          	   C   sP   t d}dd|d| dg}ttj  | tt|d  W d Q R X d S )Nr   r   r   rb   rp   )	r   decimallocalcontextZExtendedContextrN   r   r   r   rL  )r0   r   r   r   r   r	   3test_decimal_extendedcontext_mismatched_infs_to_nan  s    zDSumSpecialValues.test_decimal_extendedcontext_mismatched_infs_to_nanc          	   C   sH   t d}dd|d| dg}ttj | tjtj| W d Q R X d S )Nr   r   r   rb   rp   )r   re  rf  ZBasicContextr   InvalidOperationr   rL  )r0   r   r   r   r   r	   0test_decimal_basiccontext_mismatched_infs_to_nan  s    zASumSpecialValues.test_decimal_basiccontext_mismatched_infs_to_nanc             C   s(   t d}d|dg}| tjtj| d S )Nr   r   r   )r   r   re  rh  r   rL  )r0   r   r   r   r   r	   test_decimal_snan_raises  s    
z)SumSpecialValues.test_decimal_snan_raisesN)r'   r(   r)   r   r`  ra  rb  rc  rd  rg  ri  rj  r   r   r   r	   r_    s   r_  c               @   s$   e Zd Zdd Zdd Zdd ZdS )AverageMixinc             C   s:   x4dddt ddtdfD ]}| | |g| qW d S )Nr   g     @E@g  X_yCrJ      z0.28)r   r   rE   r*  )r0   r   r   r   r	   test_single_value&  s    zAverageMixin.test_single_valuec             C   s   dddt ddtdfS )Ng      @rH   g 7y!C=   C   z4.9712)r   r   )r0   r   r   r	   'prepare_values_for_repeated_single_test+  s    z4AverageMixin.prepare_values_for_repeated_single_testc             C   sZ   xT|   D ]H}xBdD ]:}| j||d" |g| }| | || W d Q R X qW q
W d S )N)r   rQ   rq   r;  )r   r]  )rp  subTestrE   r*  )r0   r   r]  r   r   r   r	   test_repeated_single_value.  s
    

z'AverageMixin.test_repeated_single_valueN)r'   r(   r)   rm  rp  rr  r   r   r   r	   rk  #  s   rk  c               @   st   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )TestMeanc             C   s   t j| _d S )N)r   meanr*  )r0   r   r   r	   rO  8  s    zTestMean.setUpc             C   s   |  | ddddgd d S )Ng}Ô%ITr   rb   g}Ô%I)rE   r*  )r0   r   r   r	   test_torture_pep;  s    zTestMean.test_torture_pepc             C   sD   ddddddddddddddd	d
g}t | | | |d d S )Nr   r   r   rb   rp   rQ   r3  rd   rv   rc   g     @@)r   r0  rE   r*  )r0   r   r   r   r	   rS  ?  s    $
zTestMean.test_intsc             C   s4   ddddddddg}t | | | |d	 d S )
Ng     @1@g     3@g      4@g     5@g     5@g     @7@g      9@g     ;@g     6@)r   r0  rE   r*  )r0   r   r   r   r	   rT  E  s    
zTestMean.test_floatsc             C   sJ   t }|d|d|d|d|dg}t| | | ||d d S )Nz1.634z2.517z3.912z4.072z5.813z3.5896)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   rV  K  s    "
zTestMean.test_decimalsc          	   C   sf   t }|dd|dd|dd|dd|dd|dd|ddg}t| | | ||d	d
 d S )Nr   r   rb   rp   rQ   r3  rd   rv   i  i  )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   rU  R  s    <
zTestMean.test_fractionsc             C   sn   dddddg}xZt tfD ]N}xHdD ]@}|d| }||g }| |}| t| | || q"W qW d S )Nr   rb   rQ   rd   rc   )r   rD   r   )r   r   r*  rN   r   r!   rE   )r0   rB  r9  r
   r   r   r\   r   r   r	   r   Y  s    


zTestMean.test_infc          	   C   s:   dddt ddddt dg}| |}| t| d S )	Nr   rp   r3  r   r   rb   rQ   z-inf)r   r*  rN   r   r   )r0   r   r\   r   r   r	   test_mismatched_infsd  s    
zTestMean.test_mismatched_infsc             C   sP   dddddg}x<t tfD ]0}|d}||g }| |}| t| qW d S )Nr   rb   rQ   rd   rc   r   )r   r   r*  rN   r   r   )r0   rB  r9  r   r   r\   r   r   r	   r   j  s    

zTestMean.test_nanc          	      sP   d dddddddd	d
g	}|  |  }|   fdd|D }| || d S )Ng    eAg333333@g      @g@g@g333333@g@g       @g333333 @g"@c                s   g | ]}|  qS r   r   )r   r   )cr   r	   r   y  s    z*TestMean.test_big_data.<locals>.<listcomp>)r*  rE   )r0   r   r   r\   r   )rw  r	   test_big_datas  s
    zTestMean.test_big_datac             C   s:   dd t dD }| |}| |d }| || d S )Nc             S   s   g | ]}t d dqS )r   rQ   )r   r   )r   r   r   r   r	   r   ~  s    z.TestMean.test_doubled_data.<locals>.<listcomp>i  r   )r   r*  r5   )r0   r   r   r   r   r   r	   test_doubled_data|  s    
zTestMean.test_doubled_datac             C   s    t d}| t|g| d S )NZ1e4)r   rE   r   rt  )r0   rm   r   r   r	   test_regression_20561  s    zTestMean.test_regression_20561c             C   s`   |  tddgd d}d}x<dD ]4}|  t|g| | |  t|g| | q$W d S )Ngg      g       )r   rb   rQ   r   )rE   r   rt  )r0   ZbigZtinyr   r   r   r	   test_regression_25177  s    
zTestMean.test_regression_25177N)r'   r(   r)   rO  ru  rS  rT  rV  rU  r   rv  r   rx  ry  rz  r{  r   r   r   r	   rs  7  s   		rs  c                   s   e Zd Zdd Z fddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )TestHarmonicMeanc             C   s   t j| _d S )N)r   Zharmonic_meanr*  )r0   r   r   r	   rO    s    zTestHarmonicMean.setUpc                s   t   }|d |S )Nr   )r  r1  remove)r0   r!  )r  r   r	   r1    s    

zTestHarmonicMean.prepare_datac             C   s   dddt ddtdfS )Ng      @rH   g 7y!Crn  ro  z4.125)r   r   )r0   r   r   r	   rp    s    z8TestHarmonicMean.prepare_values_for_repeated_single_testc             C   s    dddg}|  | |d d S )Nr   r   r   )rE   r*  )r0   r!  r   r   r	   	test_zero  s    
zTestHarmonicMean.test_zeroc          
   C   sL   t j}x@dgdddgfD ],}| j|d | || j| W d Q R X qW d S )NrD   r   rP   rb   )r!  )r   r   rq  r   r*  )r0   excr!  r   r   r	   test_negative_error  s    z$TestHarmonicMean.test_negative_errorc             C   s0   ddddddg}t | | | |d d S )Nr   rp   rv   ro   g333333@)r   r0  rE   r*  )r0   r   r   r   r	   rS    s    
zTestHarmonicMean.test_intsc             C   sH   dddddg}t | | | |d | | ddddgd d S )Ng      ?g      ?g      ?g      ?)r   r0  rE   r*  )r0   r   r   r   r	   test_floats_exact  s    
z"TestHarmonicMean.test_floats_exactc             C   s,   x&t ddD ]}| | |g| qW d S )Nr   r   )r   rE   r*  )r0   r   r   r   r	   test_singleton_lists  s    z%TestHarmonicMean.test_singleton_listsc          	   C   s   t }| | |d|d|d|dg|d |d|d|d|dg}t| | | ||d |d|d|d	|d
g}t| | | ||dd  d S )NrJ   r   rR  z0.05z0.10z0.20z1.68z0.32z5.94z2.75i iC )r   rE   r*  r   r0  )r0   rl   r   r   r   r	   test_decimals_exact  s    .

z$TestHarmonicMean.test_decimals_exactc          	   C   sf   t }|dd|dd|dd|dd|dd|dd|ddg}t| | | ||d	d
 d S )Nr   r   rb   rp   rQ   r3  rd   rv   i|  i  )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   rU    s    <
zTestHarmonicMean.test_fractionsc             C   s$   dt ddg}| | |d d S )Ng       @r   g      ?)r   rE   r*  )r0   r!  r   r   r	   r     s    zTestHarmonicMean.test_infc             C   s(   dt ddg}| t| | d S )Ng       @r   g      ?)r   rN   r   r   r*  )r0   r!  r   r   r	   r     s    zTestHarmonicMean.test_nanc          	      sP   d dddddddd	d
g	}|  |  }|   fdd|D }| || d S )No   g333333@g      @g@g@g333333@g@g       @g333333 @g"@c                s   g | ]}|  qS r   r   )r   r   )rw  r   r	   r     s    z>TestHarmonicMean.test_multiply_data_points.<locals>.<listcomp>)r*  rE   )r0   r   r   r\   r   )rw  r	   test_multiply_data_points  s
    z*TestHarmonicMean.test_multiply_data_pointsc             C   s:   dd t dD }| |}| |d }| || d S )Nc             S   s   g | ]}t d dqS )r   rQ   )r   r   )r   r   r   r   r	   r     s    z6TestHarmonicMean.test_doubled_data.<locals>.<listcomp>i  r   )r   r*  r5   )r0   r   r   r   r   r   r	   ry    s    
z"TestHarmonicMean.test_doubled_data)r'   r(   r)   rO  r1  rp  r~  r  rS  r  r  r  rU  r   r   r  ry  r  r   r   )r  r	   r|    s   r|  c                   sT   e Zd Zdd Z fddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
  ZS )
TestMedianc             C   s   t j| _d S )N)r   medianr*  )r0   r   r   r	   rO    s    zTestMedian.setUpc                s(   t   }t|d dkr$|d |S )Nr   r   )r  r1  r6   r   )r0   r   )r  r   r	   r1    s    

zTestMedian.prepare_datac             C   s&   ddddddg}|  | |d d S )Nr   r   rb   rp   rQ   r3  g      @)rE   r*  )r0   r   r   r   r	   test_even_ints  s    zTestMedian.test_even_intsc             C   s(   dddddddg}|  | |d d S )Nr   r   rb   rp   rQ   r3  rc   )rE   r*  )r0   r   r   r   r	   test_odd_ints  s    zTestMedian.test_odd_intsc             C   sV   t }|dd|dd|dd|dd|ddg}t| | | ||dd d S )Nr   rd   r   rb   rp   rQ   )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   test_odd_fractions  s    ,
zTestMedian.test_odd_fractionsc             C   s^   t }|dd|dd|dd|dd|dd|ddg}t| | | ||dd d S )Nr   rd   r   rb   rp   rQ   r3  )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   test_even_fractions  s    4
zTestMedian.test_even_fractionsc             C   sJ   t }|d|d|d|d|dg}t| | | ||d d S )Nz2.5z3.1z4.2z5.7z5.8)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   test_odd_decimals  s    "
zTestMedian.test_odd_decimalsc             C   sP   t }|d|d|d|d|d|dg}t| | | ||d d S )Nz1.2z2.5z3.1z4.2z5.7z5.8z3.65)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   test_even_decimals  s    (
zTestMedian.test_even_decimals)r'   r(   r)   rO  r1  r  r  r  r  r  r  r  r   r   )r  r	   r    s   r  c               @   s   e Zd Zdd Zdd ZdS )TestMedianDataTypec             C   s   t j| _d S )N)r   r  r*  )r0   r   r   r	   rO  *  s    zTestMedianDataType.setUpc             C   s,   t td}x|t|kr&t| qW |S )NrJ   )r  r   r/  r   r0  )r0   r   r   r   r	   r1  -  s    zTestMedianDataType.prepare_dataN)r'   r(   r)   rO  r1  r   r   r   r	   r  (  s   r  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestMedianLowc             C   s   t j| _d S )N)r   Z
median_lowr*  )r0   r   r   r	   rO  6  s    zTestMedianLow.setUpc             C   s&   ddddddg}|  | |d d S )Nr   r   rb   rp   rQ   r3  )rE   r*  )r0   r   r   r   r	   r  9  s    zTestMedianLow.test_even_intsc             C   s^   t }|dd|dd|dd|dd|dd|ddg}t| | | ||dd d S )Nr   rd   r   rb   rp   rQ   r3  )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   r  ?  s    4
z!TestMedianLow.test_even_fractionsc             C   sP   t }|d|d|d|d|d|dg}t| | | ||d d S )Nz1.1z2.2z3.3z4.4z5.5z6.6)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   r  G  s    (
z TestMedianLow.test_even_decimalsN)r'   r(   r)   rO  r  r  r  r   r   r   r	   r  5  s   r  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestMedianHighc             C   s   t j| _d S )N)r   Zmedian_highr*  )r0   r   r   r	   rO  Q  s    zTestMedianHigh.setUpc             C   s&   ddddddg}|  | |d d S )Nr   r   rb   rp   rQ   r3  )rE   r*  )r0   r   r   r   r	   r  T  s    zTestMedianHigh.test_even_intsc             C   s^   t }|dd|dd|dd|dd|dd|ddg}t| | | ||dd d S )Nr   rd   r   rb   rp   rQ   r3  )r   r   r0  rE   r*  )r0   rg   r   r   r   r	   r  Z  s    4
z"TestMedianHigh.test_even_fractionsc             C   sP   t }|d|d|d|d|d|dg}t| | | ||d d S )Nz1.1z2.2z3.3z4.4z5.5z6.6)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   r  b  s    (
z!TestMedianHigh.test_even_decimalsN)r'   r(   r)   rO  r  r  r  r   r   r   r	   r  P  s   r  c               @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestMedianGroupedc             C   s   t j| _d S )N)r   Zmedian_groupedr*  )r0   r   r   r	   rO  n  s    zTestMedianGrouped.setUpc             C   s   dddddddg}|  | |d dddddddg}|  | |d ddddddddd	d	d
g}|  | |dd dddddddddddddddg}| j| |dddd d S )Nr}   r     rJ   g     +@rQ   rq   r;     r   g     `3@ro                  r   g4@g:0yE>)r#   )rE   r*  r5   )r0   r   r   r   r	   test_odd_number_repeatedq  s    "z*TestMedianGrouped.test_odd_number_repeatedc             C   s   ddddddddddg
}| j | |dddd	 d
dddddg}| j | |ddd	 d
dddddddddddg}| | |d ddddddddddg
}| | |d d S )NrQ   rq   rJ   r;  r  r   g*3@g:0yE>)r#   r   rb   rp   g["8@r3  g      @g      @)r5   r*  rE   )r0   r   r   r   r	   test_even_number_repeated  s    z+TestMedianGrouped.test_even_number_repeatedc             C   sT   xNdddt ddtdfD ]2}x,dD ]$}|g| }| | |t| q$W qW d S )Ng333333@D   g ޗCr   r   z32.9714)r   rQ   rq   r;  )r   r   rE   r*  r   )r0   r   r]  r   r   r   r	   rr    s    

z,TestMedianGrouped.test_repeated_single_valuec             C   sP   t }|dd|dd|dd|dd|ddg}t| | | |d d S )NrQ   rp   rc   r  rH   g      @)r   r   r0  rE   r*  )r0   rg   r   r   r   r	   r    s    ,
z$TestMedianGrouped.test_odd_fractionsc             C   sX   t }|dd|dd|dd|dd|dd|ddg}t| | | |d d S )NrQ   rp   rc   r  rH   g      
@)r   r   r0  rE   r*  )r0   rg   r   r   r   r	   r    s    4
z%TestMedianGrouped.test_even_fractionsc             C   sF   t }|d|d|d|d|dg}t| | | |d d S )Nz5.5z6.5z7.5z8.5g      @)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   r    s    "
z#TestMedianGrouped.test_odd_decimalsc             C   s   t }|d|d|d|d|d|dg}t| | | |d |d|d|d|d|d|dg}t| | | |d d S )Nz5.5z6.5z7.5z8.5g      @g      @)r   r   r0  rE   r*  )r0   rl   r   r   r   r	   r    s    (
(
z$TestMedianGrouped.test_even_decimalsc             C   s   ddddddddddg
}|  | |dd	 dddddddddddg}| j| |dd
dd ddddddddddddg}|  | |dd d S )Ng      @g      @g      @g      @g      
@g      @g      @g      ?g      @g["8@g:0yE>)r#         i  i  i,  i@  iT  r;  g     p@)rE   r*  r5   )r0   r   r   r   r	   test_interval  s    zTestMedianGrouped.test_intervalc             C   sx   dddg}|  t| j| dddg}|  t| j| dddg}d}|  t| j|| dddg}d}|  t| j|| d S )N     r   r   rb   )r   r  r*  )r0   r   intervalr   r   r	   test_data_type_error  s    



z&TestMedianGrouped.test_data_type_errorN)r'   r(   r)   rO  r  r  rr  r  r  r  r  r  r  r   r   r   r	   r  k  s   		r  c               @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )TestModec             C   s   t j| _d S )N)r   moder*  )r0   r   r   r	   rO    s    zTestMode.setUpc             C   s   dddddddddddgS )	Nr   rb   rp   rd   rc   r   rv   r   r   )r0   r   r   r	   r1    s    zTestMode.prepare_datac             C   s"   t ddd}| tj| j| d S )Nr;  r   rb   )r   r   r   r   r*  )r0   r   r   r   r	   r<    s    zTestMode.test_range_datac             C   s4   d}|  | |d d }|  | |d d S )NZabcbdbr   zfe fi fo fum fi fifi)rE   r*  rk   )r0   r   r   r   r	   test_nominal_data  s    zTestMode.test_nominal_datac             C   sH   t td}x6tdD ]*}||g }t| | | || qW d S )Nrq   )r  r   r   r0  rE   r*  )r0   r   r<   rm   r   r   r	   test_discrete_data  s
    

zTestMode.test_discrete_datac             C   s<   dddddddddddddddd	d	g}|  tj| j| d S )
Nr   r   rb   rp   rQ   r3  rd   rv   rc   )r   r   r   r*  )r0   r   r   r   r	   test_bimodal_data  s    &zTestMode.test_bimodal_datac             C   s"   t td}| tj| j| d S )Nrq   )r  r   r   r   r   r*  )r0   r   r   r   r	   test_unique_data_failure  s    z!TestMode.test_unique_data_failurec             C   s   |  t| jd  d S )N)r   r  r*  )r0   r   r   r	   test_none_data  s    zTestMode.test_none_datac             C   s(   t ddddg}| tj| j| d S )Nr   r   )r+   Counterr   r   r   r*  )r0   r   r   r   r	   test_counter_data  s    zTestMode.test_counter_dataN)r'   r(   r)   rO  r1  r<  r  r  r  r  r  r  r   r   r   r	   r    s   r  c               @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )VarianceStdevMixing-q=c             C   s:   x4dddt ddtdfD ]}| | |gd qW d S )Nr~   g3@g  %Brt   r   z8.392r   )r   r   rE   r*  )r0   r   r   r   r	   rm  !  s    z$VarianceStdevMixin.test_single_valuec             C   sP   xJdddt ddtdfD ].}x(dD ] }|g| }| | |d q$W qW d S )	Ng@r   g @6<Crb   rd   z62.4802)r   rb   rQ   rJ   r   )r   r   rE   r*  )r0   r   r]  r   r   r   r	   rr  &  s    

z-VarianceStdevMixin.test_repeated_single_valuec             C   s4   dgd }|  |}| j|ddd | |d d S )Ng.F7ݚ?i'  g        gؗҌ<)r#   r   )r*  r5   r   )r0   r   r\   r   r   r	   test_domain_error_regression-  s    

z/VarianceStdevMixin.test_domain_error_regressionc          
      sN   ddddddddd	d
g
}|  |}d  fdd|D }| |  || d S )Ng{Gz?gRQ?g
ףp=
?gRQ @gp=
ף@gQ	@g      @gQ@gGz@gQ@g     j@c                s   g | ]}|  qS r   r   )r   r   )shiftr   r	   r   B  s    z6VarianceStdevMixin.test_shift_data.<locals>.<listcomp>)r*  r5   )r0   rB  r   r   r   )r  r	   test_shift_data7  s
    
z"VarianceStdevMixin.test_shift_datac          
      sN   dddddddddd	g
}|  |}d
  fdd|D }| |  || d S )Nr   rb   rp   rQ   rd   rc   rq   r~   ro   i ʚ;c                s   g | ]}|  qS r   r   )r   r   )r  r   r	   r   K  s    z<VarianceStdevMixin.test_shift_data_exact.<locals>.<listcomp>)r*  rE   )r0   rB  r   r   r   )r  r	   test_shift_data_exactE  s
    
z(VarianceStdevMixin.test_shift_data_exactc             C   s6   dd t dD }| |}| | t|| d S )Nc             S   s   g | ]}t d dqS )r   rv   )r   r   )r   r   r   r   r	   r   V  s    z:VarianceStdevMixin.test_iter_list_same.<locals>.<listcomp>i  )r   r*  rE   r,  )r0   r   r   r   r   r	   test_iter_list_sameN  s    
z&VarianceStdevMixin.test_iter_list_sameN)
r'   r(   r)   r$   rm  rr  r  r  r  r  r   r   r   r	   r    s   
	r  c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPVariancec             C   s   t j| _d S )N)r   	pvariancer*  )r0   r   r   r	   rO  ]  s    zTestPVariance.setUpc             C   s0   t td}t| d}| | || d S )Ni'  g   P_A)r  r   r   r0  rE   r*  )r0   r   r   r   r   r	   test_exact_uniform`  s    
z TestPVariance.test_exact_uniformc             C   s&   ddddg}d}|  | || d S )Nrp   rd   r  ro   g     6@)rE   r*  )r0   r   exactr   r   r	   rS  g  s    zTestPVariance.test_intsc             C   sX   t }|dd|dd|dd|ddg}|dd}| |}| || | |t  d S )Nr   rp   rb   rd   rv   )r   r*  rE   assertIsInstance)r0   rg   r   r  r\   r   r   r	   rU  m  s    $

zTestPVariance.test_fractionsc             C   sN   t }|d|d|d|dg}|d}| |}| || | |t  d S )Nz12.1z12.2z12.5z12.9z0.096875)r   r*  rE   r  )r0   rl   r   r  r\   r   r   r	   rV  v  s    
zTestPVariance.test_decimalsN)r'   r(   r)   rO  r  rS  rU  rV  r   r   r   r	   r  [  s
   	r  c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestVariancec             C   s   t j| _d S )N)r   variancer*  )r0   r   r   r	   rO    s    zTestVariance.setUpc             C   s:   x4dddt ddtdfD ]}| tj| j|g qW d S )Nre   g333338@g (G!=Crl  r   z4.2084)r   r   r   r   r   r*  )r0   r   r   r   r	   rm    s    zTestVariance.test_single_valuec             C   s&   ddddg}d}|  | || d S )Nrp   rd   r  ro   r   )rE   r*  )r0   r   r  r   r   r	   rS    s    zTestVariance.test_intsc             C   sX   t }|dd|dd|dd|ddg}|dd}| |}| || | |t  d S )Nr   rp   rb   rd   r   )r   r*  rE   r  )r0   rg   r   r  r\   r   r   r	   rU    s    $

zTestVariance.test_fractionsc             C   sZ   t }|d|d|d|dg}d|d |d }| |}| || | |t  d S )Nr   rd   rc   rp   z9.5rb   )r   r*  rE   r  )r0   rl   r   r  r\   r   r   r	   rV    s    
zTestVariance.test_decimalsN)r'   r(   r)   rO  rm  rS  rU  rV  r   r   r   r	   r    s
   	r  c               @   s   e Zd Zdd Zdd ZdS )
TestPStdevc             C   s   t j| _d S )N)r   Zpstdevr*  )r0   r   r   r	   rO    s    zTestPStdev.setUpc             C   s8   dd t dD }tt|}| | || d S )Nc             S   s   g | ]}t d dqS )ir  )r   r   )r   r   r   r   r	   r     s    z7TestPStdev.test_compare_to_variance.<locals>.<listcomp>i  )r   r   sqrtr   r  rE   r*  )r0   r   r   r   r   r	   test_compare_to_variance  s    z#TestPStdev.test_compare_to_varianceN)r'   r(   r)   rO  r  r   r   r   r	   r    s   r  c               @   s$   e Zd Zdd Zdd Zdd ZdS )	TestStdevc             C   s   t j| _d S )N)r   Zstdevr*  )r0   r   r   r	   rO    s    zTestStdev.setUpc             C   s:   x4dddt ddtdfD ]}| tj| j|g qW d S )NQ   gHzwi@g  f7?+BrQ   rt   z35.719)r   r   r   r   r   r*  )r0   r   r   r   r	   rm    s    zTestStdev.test_single_valuec             C   s8   dd t dD }tt|}| | || d S )Nc             S   s   g | ]}t d dqS )rP   rc   )r   r   )r   r   r   r   r	   r     s    z6TestStdev.test_compare_to_variance.<locals>.<listcomp>i  )r   r   r  r   r  rE   r*  )r0   r   r   r   r   r	   r    s    z"TestStdev.test_compare_to_varianceN)r'   r(   r)   rO  rm  r  r   r   r   r	   r    s   r  c             C   s   | t  |S )N)ZaddTestsr   ZDocTestSuite)loaderZtestsignorer   r   r	   
load_tests  s    r  __main__)r   r   );r+   Zcollections.abcre  r   r   r   r   r   r   Z	fractionsr   r   r
   r   r   r%   r&   r   r*   rC   rG   r[   rx   r   r   r   r   r   r   r   r   r   r   r   r  r  r)  rD  rK  rP  r\  r_  rk  rs  r|  r  r  r  r  r  r  r  r  r  r  r  r  r'   mainr   r   r   r	   <module>   sp   
:+_
>@w-@4d:c'H@`X9r<B%#
