File: //lib64/python3.6/test/__pycache__/test_statistics.cpython-36.pyc
3
\D) � @ sL d Z ddlZddlZddlZddlZddlZddlZddlZddlmZ ddl m
Z
ddlZdd� Zdd� Z
d d
� Zd`d
d�ZG dd� d�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd � d ej�ZG d!d"� d"ej�ZG d#d$� d$ej�ZG d%d&� d&ej�ZG d'd(� d(ej�ZG d)d*� d*ej�ZG d+d,� d,ej�ZG d-d.� d.ej�Z G d/d0� d0ej�Z!G d1d2� d2ej�Z"G d3d4� d4ej�Z#G d5d6� d6�Z$G d7d8� d8�Z%G d9d:� d:e$e%�Z&G d;d<� d<e�Z'G d=d>� d>e�Z(G d?d@� d@e�Z)G dAdB� dBe$�Z*G dCdD� dDee*e%�Z+G dEdF� dFee*e%�Z,G dGdH� dHee*�Z-G dIdJ� dJee%�Z.G dKdL� dLe-e%�Z/G dMdN� dNe-e%�Z0G dOdP� dPe-�Z1G dQdR� dRee*e%�Z2G dSdT� dTe$�Z3G dUdV� dVe3ee%�Z4G dWdX� dXe3ee%�Z5G dYdZ� dZe3e�Z6G d[d\� d\e3e�Z7d]d^� Z8e9d_k�rHej:� dS )az_Test suite for statistics module, including helper NumericTestCase and
approx_equal function.
� N)�Decimal)�Fractionc C s t jd| �S )z:Return -1.0 for negatives, including -0.0, otherwise +1.0.� )�math�copysign)�x� r �'/usr/lib64/python3.6/test_statistics.py�sign s r
c C sZ t | �t |�k rdS t| t�r2tj| �o0tj|�S | j� d }|j� d }||koX|dkS )a� Return True if a and b are both the same kind of NAN.
>>> _nan_equal(Decimal('NAN'), Decimal('NAN'))
True
>>> _nan_equal(Decimal('sNAN'), Decimal('sNAN'))
True
>>> _nan_equal(Decimal('NAN'), Decimal('sNAN'))
False
>>> _nan_equal(Decimal(42), Decimal('NAN'))
False
>>> _nan_equal(float('NAN'), float('NAN'))
True
>>> _nan_equal(float('NAN'), 0.5)
False
>>> _nan_equal(float('NAN'), Decimal('NAN'))
False
NAN payloads are not compared.
F� �n�N)r r
)�type�
isinstance�floatr �isnanZas_tuple)�a�bZaexpZbexpr r r �
_nan_equal s
r c C s: t t| �t|��}t| | �}|r*|| ntd�}||fS )z�Return the absolute and relative errors between two numbers.
>>> _calc_errors(100, 75)
(25, 0.25)
>>> _calc_errors(100, 100)
(0, 0.0)
Returns the (absolute error, relative error) between the two arguments.
�inf)�max�absr )�actual�expected�base�abs_err�rel_errr r r �_calc_errors; s
r ��-���q=�H�����z>c C s� |dk s|dk rt d��tj| �s,tj|�r0dS | |kr<dS tj| �sPtj|�rTdS t| | �}t||tt| �t|�� �}||kS )a� approx_equal(x, y [, tol [, rel]]) => True|False
Return True if numbers x and y are approximately equal, to within some
margin of error, otherwise return False. Numbers which compare equal
will also compare approximately equal.
x is approximately equal to y if the difference between them is less than
an absolute error tol or a relative error rel, whichever is bigger.
If given, both tol and rel must be finite, non-negative numbers. If not
given, default values are tol=1e-12 and rel=1e-7.
>>> approx_equal(1.2589, 1.2587, tol=0.0003, rel=0)
True
>>> approx_equal(1.2589, 1.2587, tol=0.0001, rel=0)
False
Absolute error is defined as abs(x-y); if that is less than or equal to
tol, x and y are considered approximately equal.
Relative error is defined as abs((x-y)/x) or abs((x-y)/y), whichever is
smaller, provided x or y are not zero. If that figure is less than or
equal to rel, x and y are considered approximately equal.
Complex numbers are not directly supported. If you wish to compare to
complex numbers, extract their real and imaginary parts and compare them
individually.
NANs always compare unequal, even with themselves. Infinities compare
approximately equal if they have the same sign (both positive or both
negative). Infinities with different signs compare unequal; so do
comparisons of infinities with finite numbers.
r z%error tolerances must be non-negativeFT)�
ValueErrorr r �isinfr r )r �y�tol�relZactual_errorZ
allowed_errorr r r �approx_equalK s "r% c @ s e Zd ZdZdS )�
_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 r r r&