ó
ŠwÛjc           @   sž   d  Z  d d l Z d d l m Z d „  Z d „  Z d „  Z d „  Z d e f d	 „  ƒ  YZ	 d
 e j
 f d „  ƒ  YZ d Z d „  Z e d k rš e ƒ  n  d S(   s9   Tests for binary operators on subtypes of built-in types.iÿÿÿÿN(   t   test_supportc         C   s"   x |  r | |  |  }  } q W| S(   s1   Greatest common divisor using Euclid's algorithm.(    (   t   at   b(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   gcd   s    	c         C   s   t  |  t ƒ p t  |  t ƒ S(   s5   Test whether an object is an instance of int or long.(   t
   isinstancet   intt   long(   t   x(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   isint   s    c         C   s4   x- t  t t t f D] } t |  | ƒ r d Sq Wd S(   sA   Test whether an object is an instance of a built-in numeric type.i   i    (   R   R   t   floatt   complexR   (   R   t   T(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   isnum   s    c         C   s   t  |  t ƒ S(   s6   Test wheter an object is an instance of the Rat class.(   R   t   Rat(   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   isRat   s    R   c           B   s"  e  Z d  Z d d g Z d d d „ Z d „  Z e e d ƒ Z d „  Z	 e e	 d ƒ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z e Z d „  Z e Z d „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d Z" RS(   s:   Rational number implemented as a normalized pair of longs.t	   _Rat__numt	   _Rat__denl    l    c         C   s‰   t  | ƒ s t d | ‚ n  t  | ƒ s8 t d | ‚ n  | d k rP t d ‚ n  t | | ƒ } t | | ƒ |  _ t | | ƒ |  _ d S(   sd   Constructor: Rat([num[, den]]).

        The arguments must be ints or longs, and default to (0, 1).s&   Rat numerator must be int or long (%r)s(   Rat denominator must be int or long (%r)i    s   zero denominatorN(   R   t	   TypeErrort   ZeroDivisionErrorR   R   R   R   (   t   selft   numt   dent   g(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __init__!   s    c         C   s   |  j  S(   s7   Accessor function for read-only 'num' attribute of Rat.(   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   _get_num0   s    c         C   s   |  j  S(   s7   Accessor function for read-only 'den' attribute of Rat.(   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   _get_den5   s    c         C   s   d |  j  |  j f S(   s<   Convert a Rat to a string resembling a Rat constructor call.s   Rat(%d, %d)(   R   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __repr__:   s    c         C   s   t  t |  ƒ ƒ S(   s=   Convert a Rat to a string resembling a decimal numeric value.(   t   strR	   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __str__>   s    c         C   s   |  j  d |  j S(   s   Convert a Rat to a float.g      ð?(   R   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt	   __float__B   s    c         C   sa   |  j  d k rJ y t |  j ƒ SWqJ t k
 rF t d t |  ƒ ‚ qJ Xn  t d t |  ƒ ‚ d S(   s,   Convert a Rat to an int; self.den must be 1.i   s   %s too large to convert to ints   can't convert %s to intN(   R   R   R   t   OverflowErrort   reprt
   ValueError(   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __int__F   s    c         C   s3   |  j  d k r t |  j ƒ St d t |  ƒ ‚ d S(   s,   Convert a Rat to a long; self.den must be 1.i   s   can't convert %s to longN(   R   R   R   R    R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __long__P   s    c         C   st   t  | ƒ r t | ƒ } n  t | ƒ rV t |  j | j | j |  j |  j | j ƒ St | ƒ rp t |  ƒ | St S(   s$   Add two Rats, or a Rat and a number.(   R   R   R   R   R   R   R	   t   NotImplemented(   R   t   other(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __add__V   s    c         C   st   t  | ƒ r t | ƒ } n  t | ƒ rV t |  j | j | j |  j |  j | j ƒ St | ƒ rp t |  ƒ | St S(   s)   Subtract two Rats, or a Rat and a number.(   R   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __sub__c   s    c         C   st   t  | ƒ r t | ƒ } n  t | ƒ rV t | j |  j |  j | j |  j | j ƒ St | ƒ rp | t |  ƒ St S(   s9   Subtract two Rats, or a Rat and a number (reversed args).(   R   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __rsub__n   s    c         C   sn   t  | ƒ r- t |  j | j |  j | j ƒ St | ƒ rP t |  j | |  j ƒ St | ƒ rj t |  ƒ | St S(   s)   Multiply two Rats, or a Rat and a number.(   R   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __mul__y   s    !c         C   sn   t  | ƒ r- t |  j | j |  j | j ƒ St | ƒ rP t |  j |  j | ƒ St | ƒ rj t |  ƒ | St S(   s'   Divide two Rats, or a Rat and a number.(   R   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __truediv__…   s    !c         C   sn   t  | ƒ r- t | j |  j | j |  j ƒ St | ƒ rP t | |  j |  j ƒ St | ƒ rj | t |  ƒ St S(   s7   Divide two Rats, or a Rat and a number (reversed args).(   R   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __rtruediv__‘   s    !c         C   sC   t  | ƒ r t | ƒ } n t | ƒ s+ t S|  | } | j | j S(   s.   Divide two Rats, returning the floored result.(   R   R   R   R#   R   R   (   R   R$   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __floordiv__�   s    
c         C   s   | |  } | j  | j S(   s>   Divide two Rats, returning the floored result (reversed args).(   R   R   (   R   R$   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __rfloordiv__¦   s    
c         C   sG   t  | ƒ r t | ƒ } n t | ƒ s+ t S|  | } | |  | | f S(   s2   Divide two Rats, returning quotient and remainder.(   R   R   R   R#   (   R   R$   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt
   __divmod__«   s    
c         C   s8   t  | ƒ r t | ƒ } n t | ƒ s+ t St | |  ƒ S(   sB   Divide two Rats, returning quotient and remainder (reversed args).(   R   R   R   R#   t   divmod(   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __rdivmod__´   s
    c         C   s   t  |  | ƒ d S(   s   Take one Rat modulo another.i   (   R.   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __mod__¼   s    c         C   s   t  | |  ƒ d S(   s,   Take one Rat modulo another (reversed args).i   (   R.   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __rmod__À   s    c         C   sv   t  | ƒ r( |  j d k o' |  j | k St | ƒ rV |  j | j k oU |  j | j k St | ƒ rr t |  ƒ | k St S(   s   Compare two Rats for equality.i   (   R   R   R   R   R   R	   R#   (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __eq__Ä   s    "c         C   s   |  | k S(   s    Compare two Rats for inequality.(    (   R   R$   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   __ne__Î   s    N(#   t   __name__t
   __module__t   __doc__t	   __slots__R   R   t   propertyt   NoneR   R   R   R   R   R   R!   R"   R%   t   __radd__R&   R'   R(   t   __rmul__R)   t   __div__R*   t   __rdiv__R+   R,   R-   R/   R0   R1   R2   R3   t   __hash__(    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyR      s>   						
					
	
	
									
	t   RatTestCasec           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s3   Unit tests for Rat class and its support utilities.c         C   s[  |  j  t d d ƒ d ƒ |  j  t d d ƒ d ƒ |  j  t d d ƒ d ƒ |  j  t d d ƒ d ƒ |  j  t d	 d ƒ d
 ƒ |  j  t d d
 ƒ d ƒ |  j  t d	 d
 ƒ d
 ƒ x¥ t d d ƒ D]” } x‹ t d d ƒ D]z } |  j t | | ƒ d k ƒ |  j t | | ƒ d k  ƒ |  j t | | ƒ d k ƒ |  j t | | ƒ d k  ƒ qÕ Wq¿ Wd  S(   Ni
   i   i   i   i   i   i   id   iöÿÿÿiþÿÿÿi   i    (   t   assertEqualR   t   ranget
   assertTrue(   R   t   it   j(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_gcdØ   s    c      	   C   s  t  d d ƒ } |  j | j d ƒ |  j | j d ƒ t  d d ƒ } |  j | j d ƒ |  j | j d ƒ t  d d ƒ } |  j | j d ƒ |  j | j d ƒ t  d	 d ƒ } |  j | j d ƒ |  j | j d ƒ t  d	 d ƒ } |  j | j d ƒ |  j | j d ƒ t  d
 ƒ } |  j | j d
 ƒ |  j | j d ƒ y t  d d ƒ } Wn t k
 ran X|  j d ƒ x– d d d d g  i  d  t  t f	 D]s } y t  | ƒ } Wn t k
 rºn X|  j d | ƒ y t  d | ƒ } Wn t k
 ròq‘X|  j d | ƒ q‘Wd  S(   Ni
   i   i   i   l   
 l    iñÿÿÿiþÿÿÿiöÿÿÿi   i   i    s(   Rat(1, 0) didn't raise ZeroDivisionErrort   0g        y                s   Rat(%r) didn't raise TypeErrors!   Rat(1, %r) didn't raise TypeError(    (	   R   R@   R   R   R   t   failR9   t   unittestR   (   R   R   t   bad(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_constructorç   sD    (c         C   s°   |  j  t d d ƒ t d d ƒ d ƒ |  j  t d d ƒ d t d d ƒ ƒ |  j  d t d d ƒ t d d ƒ ƒ |  j  d t d d ƒ d ƒ |  j  t d d ƒ d d ƒ d  S(   Ni   i   i   i   g      ð?g      ø?(   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_add  s
    &&&c         C   s¹   |  j  t d d ƒ t d d ƒ t d d ƒ ƒ |  j  t d d ƒ d t d d ƒ ƒ |  j  d t d d ƒ t d d ƒ ƒ |  j  t d d ƒ d d	 ƒ |  j  d t d d ƒ d	 ƒ d  S(
   Ni   i   i   i   i
   i   i   g      ð?g      à?(   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_sub  s
    /&&c         C   s§   |  j  t d d ƒ t d d ƒ t d d ƒ ƒ |  j  t d d ƒ d d ƒ |  j  d t d d ƒ d ƒ |  j  t d d ƒ d d ƒ |  j  d t d d ƒ d ƒ d  S(	   Ni   i   i   i   i
   i   g      à?g      ð?(   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_mul  s
    /c         C   s¶   |  j  t d d ƒ t d d ƒ t d d ƒ ƒ |  j  t d d ƒ d t d d ƒ ƒ |  j  d t d ƒ t d d ƒ ƒ |  j  d t d	 d ƒ d
 ƒ |  j  t d	 d ƒ d d
 ƒ d  S(   Ni
   i   i   i   i   i	   i   g      @i   g      ø?(   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_div#  s
    /&#c         C   s~   |  j  t d ƒ t d ƒ d ƒ |  j  t d d ƒ t d d ƒ d ƒ |  j  t d ƒ d d ƒ |  j  d t d ƒ d ƒ d  S(   Ni
   i   i   i   (   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_floordiv*  s     &c         C   s{   |  j  t d ƒ t d d ƒ ƒ |  j  t d ƒ d ƒ |  j  d t d ƒ ƒ |  j  t d ƒ d ƒ |  j  d t d ƒ ƒ d  S(   Ni
   i   i   g      $@(   R@   R   (   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_eq0  s
    c         B   s   e  d  Ud  S(   N(   t   future_test(   R   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   test_future_div7  s    (   R4   R5   R6   RE   RJ   RK   RL   RM   RN   RO   RP   RR   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyR?   Õ   s   		'						s  
from __future__ import division
self.assertEqual(Rat(10, 3) / Rat(5, 7), Rat(14, 3))
self.assertEqual(Rat(10, 3) / 3, Rat(10, 9))
self.assertEqual(2 / Rat(5), Rat(2, 5))
self.assertEqual(3.0 * Rat(1, 2), 1.5)
self.assertEqual(Rat(1, 2) * 3.0, 1.5)
self.assertEqual(eval('1/2'), 0.5)
c           C   s   t  j t ƒ d  S(   N(   R    t   run_unittestR?   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt	   test_mainF  s    t   __main__(   R6   RH   t   testR    R   R   R   R   t   objectR   t   TestCaseR?   RQ   RT   R4   (    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_binop.pyt   <module>   s   				ºo	