File:  [CENS] / python / pyGiNaC / test4 / test_numeric.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Mon Nov 26 22:37:44 2001 UTC (16 years ago) by pearu
Branches: MAIN
CVS tags: HEAD
See NEWS.txt (impl. matrix)

#!/usr/bin/env python
"""
  test_symbol - run ginac.symbol tests.
  Usage:
    python test_symbol.py [-v]
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.3 $
  $Id: test_numeric.py,v 1.3 2001-11-26 22:37:44 pearu Exp $
 
  Copyright 2001 Pearu Peterson all rights reserved,
  Pearu Peterson <pearu@cens.ioc.ee>
  Permission to use, modify, and distribute this software is given under the
  terms of the LGPL.  See http://www.fsf.org
 
  NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
"""

import test_all
import ginac

class test_numeric(ginac.numeric):
    """
    >>> import math
    >>> a = numeric (2,3)
    >>> b = numeric (-4)
    >>> test_save(math=math,a=a,b=b,s=symbol ('s'),f=numeric ('2.3'))
    """
    def __init__(self):
        """
        >>> numeric()
        numeric('0')
        >>> numeric(2)
        numeric('2')
        >>> numeric(numeric(3))
        numeric('3')
        >>> numeric('3')
        numeric('3')
        >>> numeric(4.0)
        numeric('4.0')
        >>> numeric(5.0j)
        numeric('5.0*I')
        >>> numeric('3.4')
        numeric('3.4')
        >>> numeric('3I')
        numeric('3*I')
        >>> numeric(3,4)
        numeric('3/4')
        >>> numeric('2/4')
        numeric('1/2')
        >>> numeric('I')
        numeric('I')
        >>> numeric('1+I')
        numeric('1+I')
        >>> numeric(3,numeric('4I'))
        numeric('-3/4*I')
        """
    def get_class_name(self):
        """
        >>> numeric().get_class_name()
        'numeric'
        """
    def get_precedence(self):
        """
        >>> numeric().get_precedence()
        30
        >>> numeric(2+5j).get_precedence()
        30
        """
    def extract_archived(self):
        """
        >>> numeric(3).extract_archived()
        {'number': '3', 'class': 'numeric'}
        >>> numeric(3.5).extract_archived()
        {'number': 'R1 16140901064495857664 -62', 'class': 'numeric'}
        >>> numeric(3,5).extract_archived()
        {'number': '3/5', 'class': 'numeric'}
        >>> numeric('3+4*I').extract_archived()
        {'number': '3+4i', 'class': 'numeric'}
        >>> numeric('3.5+4.5*I').extract_archived()
        {'number': 'C1 16140901064495857664 -62 1 10376293541461622784 -61', 'class': 'numeric'}
        """
    def to_context(self):
        """
        >>> numeric(3).to_context(), numeric(3).to_context(context='latex')
        ('3', '3')
        >>> numeric(3).to_context(context='csrc')
        '3.000000e+00'
        >>> numeric(3).to_context(context='csrc_float')
        '3.000000e+00'
        >>> numeric(3).to_context(context='csrc_double')
        '3.000000e+00'
        >>> numeric(3).to_context(context='csrc_cl_N')
        'cln::cl_F(\"3.0\")'
        >>> numeric('1234567890123456789').to_context(context='csrc_cl_N')
        'cln::cl_F(\"1.234567890123456789E18\")'
        """
    def __repr__(self):
        """
        >>> repr(numeric(3,4))
        \"numeric('3/4')\"
        """
    def __str__(self):
        """
        >>> str(numeric(3,4))
        '3/4'
        """
    def __complex__(self):
        """
        >>> complex(numeric(1+2j))
        (1+2j)
        """
    def __float__(self):
        """
        >>> float(numeric(3.5))
        3.5
        >>> float(numeric(2+3j))
        2.0
        """
    def __int__(self):
        """
        >>> int(numeric(3))
        3
        >>> int(numeric(3.4+5.6j))
        3
        """
    def __long__(self):
        """
        >>> long(numeric(3))
        3L
        """
    def csgn(self):
        """
        >>> numeric(3).csgn()
        1
        >>> numeric(-3).csgn()
        -1
        >>> numeric(0).csgn()
        0
        >>> numeric(3-4j).csgn()
        1
        >>> numeric(-3+4j).csgn()
        -1
        """
    def denom(self):
        """
        >>> numeric(3,4).denom()
        numeric('4')
        >>> numeric(3.4).denom()
        numeric('1')
        >>> numeric(3.4j).denom()
        numeric('1')
        """
    def numer(self):
        """
        >>> numeric(3,4).numer()
        numeric('3')
        >>> numeric(3.5).numer()
        numeric('3.5')
        >>> numeric(3.4j).numer()
        numeric('3.4*I')
        """
    def real(self):
        """
        >>> numeric('3+4*I').real()
        numeric('3')
        >>> numeric(3).real()
        numeric('3')
        """
    def imag(self):
        """
        >>> numeric('3+4*I').imag()
        numeric('4')
        >>> numeric(3).imag()
        numeric('0')

        """
    def is_integer(self):
        """
        >>> nums = numeric(2), numeric(2,3), numeric(3.4), numeric(1+2j)
        >>> [n.is_integer() for n in nums]
        [1, 0, 0, 0]
        """
    def is_rational(self):
        """
        >>> nums = numeric(2), numeric(2,3), numeric(3.4), numeric(1+2j)
        >>> [n.is_rational() for n in nums]
        [1, 1, 0, 0]
        """
    def is_real(self):
        """
        >>> nums = numeric(2), numeric(2,3), numeric(3.4), numeric(1+2j)
        >>> [n.is_real() for n in nums]
        [1, 1, 1, 0]
        """
    def is_cinteger(self):
        """
        >>> nums = numeric(2), numeric(2,3), numeric(3.4), numeric(1+2j), numeric('2I')
        >>> [n.is_cinteger() for n in nums]
        [1, 0, 0, 0, 1]
        """
    def is_crational(self):
        """
        >>> nums = numeric(2), numeric(2,3), numeric(3.4), numeric(1+2j), numeric('2I'), numeric('2/3*I')
        >>> [n.is_crational() for n in nums]
        [1, 1, 0, 0, 1, 1]
        """
    def is_even(self):
        """
        >>> [numeric(n).is_even() for n in [2,3,2.4,'1/2',4j, 2+0j]]
        [1, 0, 0, 0, 0, 0]
        """
    def is_odd(self):
        """
        >>> [numeric(n).is_odd() for n in [2,3,2.4,'1/2',4j, 2+0j]]
        [0, 1, 0, 0, 0, 0]
        """
    def is_prime(self):
        """
        >>> [numeric(n).is_prime() for n in range(1,12)]
        [0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
        >>> numeric(3.4).is_prime()
        0
        """
    def is_negative(self):
        """
        >>> [numeric(n).is_negative() for n in [-3,0,4,3j,-3j,-1+2j, -3.4]]
        [1, 0, 0, 0, 0, 0, 1]
        """
    def is_positive(self):
        """
        >>> [numeric(n).is_positive() for n in [-3,0,4,3j,-3j,-1+2j, -3.4]]
        [0, 0, 1, 0, 0, 0, 0]
        """
    def is_pos_integer(self):
        """
        >>> [numeric(n).is_pos_integer() for n in [-3,0,4,3j,-3j,-1+2j, 3.4]]
        [0, 0, 1, 0, 0, 0, 0]
        """
    def is_nonneg_integer(self):
        """
        >>> [numeric(n).is_nonneg_integer() for n in [-3,0,4,3j,-3j,-1+2j, 3.4]]
        [0, 1, 1, 0, 0, 0, 0]
        """
    def is_zero(self):
        """
        >>> [numeric(n).is_zero() for n in [0,0.0,0j,3,-4.5]]
        [1, 1, 1, 0, 0]
        """
    def __nonzero__(self):
        """
        >>> [not numeric(n) for n in [0,0.0,0j,3,-4.5]]
        [1, 1, 1, 0, 0]
        """
    def is_equal(self):
        """
        >>> numeric(3).is_equal(3)
        1
        """
    def __abs__(self):
        """
        >>> [abs(numeric(n)) for n in [-2,3,3-4j]]
        [numeric('2'), numeric('3'), numeric('5.0')]
        """
    def __neg__(self):
        """
        >>> [-numeric(n) for n in [-2,3,3-4j]]
        [numeric('2'), numeric('-3'), numeric('-3.0+4.0*I')]
        """
    def __add__(self):
        """
        >>> numeric(4) + numeric('5I')
        numeric('4+5*I')
        >>> numeric(3) + 2
        numeric('5')
        """
    def __radd__(self):
        """
        >>> 2 + numeric(3)
        numeric('5')
        """
    def __sub__(self):
        """
        >>> numeric(4) - numeric('5I')
        numeric('4-5*I')
        >>> numeric(3) - 2
        numeric('1')
        """
    def __rsub__(self):
        """
        >>> 2 - numeric(3)
        numeric('-1')
        """
    def __mul__(self):
        """
        >>> numeric(4) * numeric('5I')
        numeric('20*I')
        >>> numeric(3) * 2
        numeric('6')
        """
    def __rmul__(self):
        """
        >>> 2 * numeric(3)
        numeric('6')
        """
    def __div__(self):
        """
        >>> numeric(4) / numeric('5I')
        numeric('-4/5*I')
        >>> numeric(3) / 2
        numeric('3/2')
        """
    def __rdiv__(self):
        """
        >>> 2 / numeric(3)
        numeric('2/3')
        """
    def __pow__(self):
        """
        >>> numeric(4) ** numeric('5I')
        numeric('0.79711961721848725724+0.6038214271168690096*I')
        >>> numeric(3) ** 2
        numeric('9')
        """
    def __rpow__(self):
        """
        >>> 2 ** numeric(3)
        numeric('8')
        """
    def inverse(self):
        """
        >>> [numeric(n).inverse() for n in [3,'I']]
        [numeric('1/3'), numeric('-I')]
        >>> numeric(0.0).inverse()
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        """
    def int_length(self):
        """
        >>> [numeric(n).int_length() for n in [0,1,2,3,4,5,6,-1,-2]]
        [0, 1, 2, 2, 3, 3, 3, 0, 1]
        >>> numeric('30I').int_length()
        0
        """
    def compare(self):
        """
        >>> numeric(3).compare(5)
        -1
        >>> numeric(3).compare(-5j)
        1
        
        """
    def __lshift__(self):
        """
        >>> 0 in [(numeric(n)<<m).is_equal(n<<m) for n,m in [(2,3),(-4,5)]]
        0
        >>> numeric(2)<<-3
        numeric('1/4')
        >>> numeric(3.5)<<2
        numeric('14.0')
        >>> numeric('I')<<3
        numeric('8*I')
        """
    def __rshift__(self):
        """
        >>> 0 in [(numeric(n)>>m).is_equal(n>>m) for n,m in [(2,3),(-4,5)]]
        0
        >>> numeric(2)>>-3
        numeric('16')
        >>> numeric(3.5)>>2
        numeric('0.875')
        >>> numeric('I')>>3
        numeric('1/8*I')
        """
    def __pos__(self):
        """
        >>> (+numeric(1+2j)).is_equal(1+2j)
        1
        """
    def __invert__(self):
        """
        >>> ~numeric(3)
        numeric('-4')
        """
    def conjugate(self):
        """
        >>> numeric('3+4I').conjugate()
        numeric('3-4*I')
        """
    def exp(self):
        """
        >>> numeric(1).exp()
        numeric('2.7182818284590452354')
        """
    def gcd(self):
        """
        >>> numeric(45).gcd(9)
        numeric('9')
        """
    def lcm(self):
        """
        >>> numeric(9).lcm(24)
        numeric('72')
        """
    def abs(self):
        """
        >>> numeric(-3).abs()
        numeric('3')
        """
    def Li2(self):
        """
        >>> numeric(5).Li2()
        numeric('1.7837191612666306279-5.056198322111862682*I')
        """
    def sin(self):
        """
        >>> float(numeric(5).sin()) == math.sin(5)
        1
        """
    def cos(self):
        """
        >>> float(numeric(5).cos()) == math.cos(5)
        1
        """
    def tan(self):
        """
        >>> float(numeric(5).tan()) == math.tan(5)
        1
        """
    def asin(self):
        """
        >>> float(numeric(.5).asin()) == math.asin(.5)
        1
        """
    def acos(self):
        """
        >>> float(numeric(.5).acos()) == math.acos(.5)
        1
        """
    def atan(self):
        """
        >>> float(numeric(5).atan()) == math.atan(5)
        1
        """
    def sinh(self):
        """
        >>> float(numeric(5).sinh()) == math.sinh(5)
        1
        """
    def cosh(self):
        """
        >>> float(numeric(5).cosh()) == math.cosh(5)
        1
        """
    def tanh(self):
        """
        >>> float(numeric(5).tanh()) == math.tanh(5)
        1
        """
    def asinh(self):
        """
        >>> float(numeric(5).asinh().sinh()) == 5
        1
        """
    def acosh(self):
        """
        >>> float(numeric(5).acosh().cosh()) == 5
        1
        """
    def atanh(self):
        """
        >>> float(numeric(5).atanh().tanh()) == 5
        1
        """
    def atan2(self):
        """
        >>> float(numeric(5).atan2(4)) == math.atan2(5,4)
        1
        """
    def bernoulli(self):
        """
        >>> [numeric(n).bernoulli() for n in range(5)]
        [numeric('1'), numeric('-1/2'), numeric('1/6'), numeric('0'), numeric('-1/30')]
        """
    def factorial(self):
        """
        >>> [int(numeric(n).factorial()) for n in range(10)]
        [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
        """
    def doublefactorial(self):
        """
        >>> [int(numeric(n).doublefactorial()) for n in range(10)]
        [1, 1, 2, 3, 8, 15, 48, 105, 384, 945]
        """
    def fibonacci(self):
        """
        >>> [int(numeric(n).fibonacci()) for n in range(10)]
        [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
        """
    def sqrt(self):
        """
        >>> float(numeric(5).sqrt()) == math.sqrt(5)
        1
        """
    def isqrt(self):
        """
        >>> numeric(5).isqrt()
        numeric('2')
        """
    def log(self):
        """
        >>> float(numeric(5).log().exp()) == 5
        1
        """
    def binomial(self):
        """
        >>> [int(numeric(5).binomial(n)) for n in range(-5,10)]
        [0, 0, 0, 0, 0, 1, 5, 10, 10, 5, 1, 0, 0, 0, 0]
        """
    def mod(self):
        """
        >>> [int(numeric(5).mod(n)) for n in range(1,15)]
        [0, 1, 2, 1, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5]
        >>> numeric(5).mod(0)
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        """
    def smod(self):
        """
        >>> [int(numeric(5).smod(n)) for n in range(1,15)]
        [1, 1, 2, 1, 0, -1, -2, -3, 5, 5, 5, 5, 5, 5]
        >>> numeric(5).smod(0)
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        """
    def irem(self):
        """
        >>> [int(numeric(5).irem(n)) for n in range(1,15)]
        [0, 1, 2, 1, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5]
        >>> numeric(5).irem(0)
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        """
    def iquo(self):
        """
        >>> [int(numeric(5).iquo(n)) for n in range(1,15)]
        [5, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        >>> numeric(5).iquo(0)
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        """
    def __eq__ (self):
        """
        >>> a==b
        relational(numeric('2/3'),numeric('-4'),'==')
        >>> not a==b
        1
        >>> a==2
        relational(numeric('2/3'),numeric('2'),'==')
        >>> -2==b
        relational(numeric('-4'),numeric('-2'),'==')
        """
    def __ne__ (self):
        """
        >>> a!=b
        relational(numeric('2/3'),numeric('-4'),'!=')
        >>> not a!=b
        0
        """
    def __lt__ (self):
        """
        >>> a<b
        relational(numeric('2/3'),numeric('-4'),'<')
        >>> not a<b
        1
        >>> a<3
        relational(numeric('2/3'),numeric('3'),'<')
        >>> 3<a
        relational(numeric('3'),numeric('2/3'),'<')
        """
    def __le__ (self):
        """
        >>> a<=b
        relational(numeric('2/3'),numeric('-4'),'<=')
        >>> not a<=b
        1
        """
    def __gt__ (self):
        """
        >>> a>b
        relational(numeric('-4'),numeric('2/3'),'<')
        >>> not a>b
        0
        """
    def __ge__ (self):
        """
        >>> a>=b
        relational(numeric('-4'),numeric('2/3'),'<=')
        >>> not a>=b
        0
        """
    def eval (self):
        """
        >>> a.eval ()
        numeric('2/3')
        """
    def evalf (self):
        """
        >>> a.evalf ()
        numeric('0.6666666666666666667')
        """
    def evalm (self):
        """
        >>> a.evalm ()
        numeric('2/3')
        """
    def to_list (self):
        """
        >>> a.to_list ()
        []
        """
    def op (self):
        """
        >>> a.op (0)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        """
    def nops (self):
        """
        >>> a.nops ()
        0
        """
    def numer_denom (seld):
        """
        >>> a.numer_denom ()
        (numeric('2'), numeric('3'))
        >>> numeric ('2.3').numer_denom ()
        (numeric('2.3'), numeric('1'))
        """
    def coeff (self):
        """
        >>> a.coeff (s)
        numeric('0')
        >>> a.coeff (a)
        numeric('0')
        >>> a.coeff (s,0)
        numeric('2/3')
        """
    def lcoeff (self):
        """
        >>> a.lcoeff (s)
        numeric('2/3')
        """
    def tcoeff (self):
        """
        >>> a.tcoeff (s)
        numeric('2/3')
        """
    def degree (self):
        """
        >>> a.degree (a)
        0
        >>> a.degree (s)
        0
        """
    def ldegree (self):
        """
        >>> a.ldegree (s)
        0
        >>> a.degree (a)
        0
        """
    def integer_content (self):
        """
        >>> a.integer_content ()
        numeric('2/3')
        >>> f.integer_content ()
        numeric('2.3')
        """
    def content (self):
        """
        >>> a.content (s)
        numeric('2/3')
        """
    def unit (self):
        """
        >>> a.unit (s)
        numeric('1')
        """
    def primpart (self):
        """
        >>> a.primpart (s)
        numeric('1')
        """
    def has (self):
        """
        >>> a.has (a)
        1
        >>> a.has (numeric (2,3))
        1
        >>> a.has (2)
        0
        >>> a.has (3)
        0
        >>> f.has (2)
        0
        >>> numeric (2).has (2)
        1
        >>> a.has (s)
        0
        """
    def swap (self):
        """
        >>> a.swap (f)
        >>> a,f
        (numeric('2.3'), numeric('2/3'))
        >>> a.swap (f)
        >>> a,f
        (numeric('2/3'), numeric('2.3'))
        """
    def max_coefficient (self):
        """
        >>> a.max_coefficient ()
        numeric('2/3')
        >>> b.max_coefficient ()
        numeric('4')
        >>> f.max_coefficient ()
        numeric('2.3')
        """
    def diff (self):
        """
        >>> a.diff (s)
        numeric('0')
        >>> a.diff (s,0)
        numeric('2/3')
        >>> a.diff (s,-1)
        Traceback (most recent call last):
        ...
        TypeError: diff() method 2nd argument must be positive int
        """
    def get_hash (self):
        """
        >>> type (a.get_hash ()) is type (0)
        1
        """
    def __coerce__ (self):
        """
        >>> coerce (a,2)
        (numeric('2/3'), numeric('2'))
        """
    def psi_fixme (self):
        """
        >>> #numeric (2).psi ()
        
        """
    def is_function (self):
        """
        >>> a.is_function ()
        0
        """
def _test():
    import test_numeric
    return test_all.test(test_numeric)

if __name__ == "__main__":
    _test()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>