B
    u9a                 @   s   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
 ejjZejjZG dd de jZG dd de jZedkre   dS )	    N)Decimal)Fractionc               @   sL   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S )HashTestc             C   s.   |  t|t|d|| |  || d S )Nz&got different hashes for {!r} and {!r})assertEqualhashformat)selfxy r   (/usr/lib/python3.7/test_numeric_tower.pycheck_equal_hash   s    zHashTest.check_equal_hashc             C   s   |  dd |  dd d S )NFr   T   )r   )r   r   r   r   
test_bools   s    zHashTest.test_boolsc             C   s  xBt ddD ]4}| |t| | |t| | |t| qW xt dD ] }d| d }|tt|kr| |t| | | t|  | |t| | |t| | | t|  | | t|  d| }| |t| | | t|  | |t| | |t| | | t|  | | t|  qPW xtt dD ]h}td}td|  d| }| |t| | |t| |tt|kr`| |t| q`W d S )Nii  d      r   i,  
   )ranger   floatDFintrandomZ	randrange)r   in_er   r   r   test_integers   s6    
zHashTest.test_integersc             C   s   |  dd |  dtd |  dtd |  dtd |  dtd |  tdtd |  tdtd xRtdD ]F}t tt d d	  }|  |t| |  |t| q~W d S )
Ng        g       r   z-0.0infz-infi  g      i@g      Y@)	r   r   r   r   r   r   mathZexpZ
from_float)r   r   r	   r   r   r   test_binary_floatsB   s    zHashTest.test_binary_floatsc          	   C   sN   ddddddt dt dg}x,d	D ]$}x|D ]}| |t|| q,W q"W d S )
Ng        g       g      ?g      g      ?g    r   z-inf)g       g        )r   r   complex)r   test_valueszerovaluer   r   r   test_complexW   s
    

zHashTest.test_complexc             C   s   dddddg}x |D ]}|  t|td qW |  tdtd |  td	td |  td
td |  tdtd |  tdtd |  tdtd |  tdtd |  tdtd |  tdtd |  tdtd d S )N0z-0z0.0z-0.0e10z000e-10r   z1.00r   z1.00000z-1.00z-1.00000Z123e2i0  Z1230e1Z12300z12300.0z12300.00z	12300.000)r   r   )r   Zzerosr#   r   r   r   test_decimalsb   s    
zHashTest.test_decimalsc             C   sh   |  ttdtt |  ttddt t  |  ttdt dd |  ttt dd d S )Nr   r'         r   )r   r   r   _PyHASH_MODULUS_PyHASH_INF)r   r   r   r   test_fractionst   s    zHashTest.test_fractionsc             C   s,   G dd d}d| h}|  t|d d S )Nc               @   s   e Zd Zdd Zdd ZdS )z6HashTest.test_hash_normalization.<locals>.HalibutProxyc             S   s   t dS )Nhalibut)r   )r   r   r   r   __hash__   s    z?HashTest.test_hash_normalization.<locals>.HalibutProxy.__hash__c             S   s   |dkS )Nr.   r   )r   otherr   r   r   __eq__   s    z=HashTest.test_hash_normalization.<locals>.HalibutProxy.__eq__N)__name__
__module____qualname__r/   r1   r   r   r   r   HalibutProxy   s   r5   r.   r   )r   len)r   r5   r	   r   r   r   test_hash_normalization|   s    
z HashTest.test_hash_normalizationN)r2   r3   r4   r   r   r   r    r%   r(   r-   r7   r   r   r   r   r      s   &r   c               @   s   e Zd Zdd Zdd ZdS )ComparisonTestc             C   s   t dtddtdddddd	d
tdtdt dtddtdtddtdddtdg}x^t|D ]R\}}xH||d d  D ]4}| || | || | || | || qW qfW d S )Nz-infz-1e425000000gir*   gQ	g        g      Tz1.2z1.3z1.4i_5 i z1.414213562373095048801688724iC i; i:iJ gvܼ5JiZinfinityr   )r   r   r   	enumerateZ
assertLessZassertLessEqualZassertGreaterZassertGreaterEqual)r   r"   r   firstsecondr   r   r   test_mixed_comparisons   s0    
z%ComparisonTest.test_mixed_comparisonsc             C   s  d}d}x:ddt dtdtdfD ]}| || | || q$W xRddt dtdtdfD ]4}| || | || | || | || q`W xxddt dtdtdddt dtdtd|fD ]B}x<tjtjtjtj	fD ]$}| 
t||| | 
t||| qW qW d S )Ny      ?        yQ	@r   g      ?r   g       @)r   r   r!   r   ZassertNotEqualoperatorleltgegtZassertRaises	TypeError)r   zwvopr   r   r   r%      s       zComparisonTest.test_complexN)r2   r3   r4   r=   r%   r   r   r   r   r8      s   r8   __main__)Zunittestr   r   sysr>   decimalr   r   Z	fractionsr   r   	hash_infomodulusr+   r   r,   ZTestCaser   r8   r2   mainr   r   r   r   <module>   s    8