
    e
                         d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZ dZdZd	Zeeef   Zd
edefdZ G d de	e         Zed
ededee   fd       Zed
ededee   fd       Zd Zy)    )Decimal)fabs)AnyUnionoverload)BaseMatcher)Description)MatcherzJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtvaluereturnc                     t        | t        t        t        f      ry	 t	        |       dz   dz
  dz  }y# t
        $ r Y yt        $ r Y yw xY w)zFConfirm that 'value' can be treated numerically; duck-test accordinglyTr      F)
isinstancefloatcomplexintr   ArithmeticError	Exception)r   _s     C/usr/lib/python3/dist-packages/hamcrest/library/number/iscloseto.py	isnumericr      sR    %%#./%[1_q A%  s   3 	A	A	A	c                   p     e Zd ZdededdfdZdedefdZdedefdZded	e	ddf fd
Z
de	ddfdZ xZS )	IsCloseTor   deltar   Nc                 x    t        |      st        d      t        |      st        d      || _        || _        y )NzIsCloseTo value must be numericzIsCloseTo delta must be numeric)r   	TypeErrorr   r   )selfr   r   s      r   __init__zIsCloseTo.__init__   s8    =>>=>>

    itemc                 V    t        |      sy| j                  |      | j                  k  S )NF)r   _diffr   r   r    s     r   _matcheszIsCloseTo._matches(   s$    zz$4::--r   c                 2    t        || j                  z
        S N)r   r   r#   s     r   r"   zIsCloseTo._diff-   s    D4::%&&r   mismatch_descriptionc                     t        |      st        t        |   ||       y | j	                  |      }|j                  |      j                  d      j                  |       y )Nz differed by )r   superr   describe_mismatchr"   append_description_ofappend_text)r   r    r'   actual_delta	__class__s       r   r*   zIsCloseTo.describe_mismatch1   sQ    )T4T;OP::d+L 66t<HH##L1r   descriptionc                     |j                  d      j                  | j                        j                  d      j                  | j                         y )Nza numeric value within z of )r,   r+   r   r   )r   r/   s     r   describe_tozIsCloseTo.describe_to:   s<     9:PPJJ	

+f
33DJJ?r   )__name__
__module____qualname__Numberr   boolr$   r   r"   r	   r*   r1   __classcell__)r.   s   @r   r   r      st    f V  .V . .
'& 'U '2f 2K 2TX 2@{ @t @r   r   r   c                      y r&    r   r   s     r   close_tor;   @       r   c                      y r&   r9   r:   s     r   r;   r;   E   r<   r   c                     t        | |      S )a  Matches if object is a number close to a given value, within a given
    delta.

    :param value: The value to compare against as the expected value.
    :param delta: The maximum delta between the values for which the numbers
        are considered close.

    This matcher compares the evaluated object against ``value`` to see if the
    difference is within a positive ``delta``.

    Example::

        close_to(3.0, 0.25)

    )r   r:   s     r   r;   r;   J   s      UE""r   N)decimalr   mathr   typingr   r   r   hamcrest.core.base_matcherr   hamcrest.core.descriptionr	   hamcrest.core.matcherr
   
__author____copyright____license__r   r5   r6   r   r   r;   r9   r   r   <module>rH      s      ' ' 2 1 )
-$	ug~	S T @F# @D 
E % GEN  
 
G G 0@  
#r   