o
    (]^¶
  ã                   @   sÖ   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d„ZG dd„ de	e ƒZed
ededee fdd„ƒZed
ededee fdd„ƒZdd„ ZdS )é    )ÚDecimal)Úfabs)ÚAnyÚUnionÚoverload)ÚBaseMatcher)ÚDescription)ÚMatcherzJon ReidzCopyright 2011 hamcrest.orgzBSD, see License.txtÚvalueÚreturnc                 C   sN   t | tttfƒr
dS zt| ƒd d d }W dS  ty!   Y dS    Y dS )zKConfirm that 'value' can be treated numerically; duck-test accordingly
    Tr   é   F)Ú
isinstanceÚfloatÚcomplexÚintr   ÚArithmeticError)r
   Ú_© r   úC/usr/lib/python3/dist-packages/hamcrest/library/number/iscloseto.pyÚ	isnumeric   s   r   c                       sv   e Zd Zdededdfdd„Zdedefdd	„Zdedefd
d„Zdede	ddf‡ fdd„Z
de	ddfdd„Z‡  ZS )Ú	IsCloseTor
   Údeltar   Nc                 C   s0   t |ƒstdƒ‚t |ƒstdƒ‚|| _|| _d S )NzIsCloseTo value must be numericzIsCloseTo delta must be numeric)r   Ú	TypeErrorr
   r   )Úselfr
   r   r   r   r   Ú__init__    s   
zIsCloseTo.__init__Úitemc                 C   s   t |ƒsdS |  |¡| jkS )NF)r   Ú_diffr   ©r   r   r   r   r   Ú_matches)   s   zIsCloseTo._matchesc                 C   s   t || j ƒS ©N)r   r
   r   r   r   r   r   .   s   zIsCloseTo._diffÚmismatch_descriptionc                    sB   t |ƒstt| ƒ ||¡ d S |  |¡}| |¡ d¡ |¡ d S )Nz differed by )r   Úsuperr   Údescribe_mismatchr   Úappend_description_ofÚappend_text)r   r   r    Úactual_delta©Ú	__class__r   r   r"   2   s   

ÿzIsCloseTo.describe_mismatchÚdescriptionc                 C   s$   |  d¡ | j¡  d¡ | j¡ d S )Nza numeric value within z of )r$   r#   r   r
   )r   r(   r   r   r   Údescribe_to;   s   
ÿzIsCloseTo.describe_to)Ú__name__Ú
__module__Ú__qualname__ÚNumberr   Úboolr   r   r   r   r"   r)   Ú__classcell__r   r   r&   r   r      s    		r   r   c                 C   ó   d S r   r   ©r
   r   r   r   r   Úclose_toA   ó   r2   c                 C   r0   r   r   r1   r   r   r   r2   F   r3   c                 C   s
   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   r1   r   r   r   r2   K   s   
N)Údecimalr   Úmathr   Útypingr   r   r   Úhamcrest.core.base_matcherr   Úhamcrest.core.descriptionr   Úhamcrest.core.matcherr	   Ú
__author__Ú__copyright__Ú__license__r   r-   r.   r   r   r2   r   r   r   r   Ú<module>   s"    "