File:  [CENS] / python / pyGiNaC / test4 / test_constant.py
Revision 1.4: 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_constant - run ginac.constant tests.
  Usage:
    python test_constant.py [-v]
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.4 $
  $Id: test_constant.py,v 1.4 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_constant(ginac.constant):
    """
    >>> class constant (constant): _cache={}
    ...
    >>> p=constant ('p')
    >>> q=constant ('q',ex(3))
    >>> q
    constant('q',numeric('3'))
    >>> test_save (p=p,q=q,r=constant ('r',2.),s=constant ('s',lambda p=p: p+1),constant=constant)
    """
    def __init__(self):
        """
        >>> constant('a',3)
        constant('a',3)
        >>> constant('a')
        constant('a',3)
        >>> constant('a', 4)
        Traceback (most recent call last):
        ...
        ValueError: constant 'a' has a value or/and TeX_name
        >>> constant('b')
        constant('b')
        >>> print repr (constant('c',lambda:2))[:37]
        constant('c',<function <lambda> at 0x
        >>> def fun(): return 56
        ...
        >>> print repr (constant('d',fun))[:32]
        constant('d',<function fun at 0x
        >>> constant('Pi')
        constant('Pi',TeX_name='\\pi')
        >>> constant('a1',3,'c')
        constant('a1',3,TeX_name='c')
        >>> constant('a2',None,'c')
        constant('a2',TeX_name='c')
        """
    def get_precedence(self):
        """
        >>> constant('a').get_precedence()
        70
        """
    def get_class_name(self):
        """
        >>> constant('a').get_class_name()
        'constant'
        """
    def __repr__(self):
        """See __init__."""
    def __str__(self):
        """
        >>> constant('a').__str__()
        'a'
        """
    def get_name(self):
        """
        >>> constant('a').get_name()
        'a'
        """
    def get_TeX_name(self):
        """
        >>> constant('a').get_TeX_name()
        '\\\\mbox{a}'
        >>> constant('aa',3,'b').get_TeX_name()
        'b'
        >>> constant('Pi').get_TeX_name()
        '\\\\pi'
        """
    def get_init(self):
        """
        >>> constant('aaaa').get_init()
        >>> constant('a').get_init()
        3
        >>> constant('aA', symbol('A')).get_init()
        symbol('A')
        >>> constant('Pi').get_init()
        constant('Pi',TeX_name='\pi')
        >>> type(constant('f',lambda:3).get_init())
        <type 'function'>
        """
    def extract_archived(self):
        """
        >>> constant('a').extract_archived()
        {'class': 'constant', 'name': 'a'}
        >>> constant('a').extract_archived()
        {'class': 'constant', 'name': 'a'}
        >>> constant('aaa',3,'b').extract_archived()
        {'class': 'constant', 'name': 'aaa'}
        """
    def to_context(self):
        """
        >>> constant('a').to_context()
        'a'
        >>> constant('a').to_context('latex')
        '\\\\mbox{a}'
        >>> constant('a').to_context('csrc')
        'a'
        >>> constant('a').to_context('python')
        'a'
        >>> constant('a').to_context('python_repr')
        "constant('a',3)"
        """
    def evalf(self):
        """
        >>> constant('a').evalf()
        constant('a',3)
        >>> constant('a',3).evalf()
        numeric('3.0')
        >>> constant('a',lambda:2).evalf()
        numeric('2.0')
        >>> constant('Pi').evalf()
        numeric('3.1415926535897932385')
        """
    def get_hash(self):
        """
        >>> type (constant ('a').get_hash ()) is type (0)
        1
        """
    def __abs__ (self):
        """
        >>> abs (p)
        abs(constant('p'))
        """
    def __add__ (self):
        """
        >>> p+1
        add(constant('p'),numeric('1'))
        """
    def __radd__ (self):
        """
        >>> 1+p
        add(constant('p'),numeric('1'))
        """
    def __mul__ (self):
        """
        >>> p*2
        mul(constant('p'),numeric('2'))
        """
    def __rmul__ (self):
        """
        >>> 2*p
        mul(constant('p'),numeric('2'))
        """
    def __sub__ (self):
        """
        >>> p-1
        add(constant('p'),numeric('-1'))
        """
    def __rsub__ (self):
        """
        >>> 1-p
        add(mul(constant('p'),numeric('-1')),numeric('1'))
        """
    def __pow__ (self):
        """
        >>> p**2
        power(constant('p'),numeric('2'))
        """
    def __rpow__ (self):
        """
        >>> 2**p
        power(numeric('2'),constant('p'))
        """
    def __div__ (self):
        """
        >>> p/2
        mul(constant('p'),numeric('1/2'))
        """
    def __rdiv__ (self):
        """
        >>> 2/p
        mul(power(constant('p'),numeric('-1')),numeric('2'))
        """
    def __neg__ (self):
        """
        >>> -p
        mul(constant('p'),numeric('-1'))
        """
    def __pos__ (self):
        """
        >>> +p
        constant('p')
        """
    def __nonzero__ (self):
        """
        >>> not p
        0
        """
    def __coerce__ (self):
        """
        >>> coerce (p,1)
        (constant('p'), numeric('1'))
        """
    def __eq__ (self):
        """
        >>> p==q
        relational(constant('p'),constant('q',numeric('3')),'==')
        """
    def __ne__ (self):
        """
        >>> p!=q
        relational(constant('p'),constant('q',numeric('3')),'!=')
        """
    def __lt__ (self):
        """
        >>> p<q
        relational(constant('p'),constant('q',numeric('3')),'<')
        """
    def __le__ (self):
        """
        >>> p<=q
        relational(constant('p'),constant('q',numeric('3')),'<=')
        """
    def __gt__ (self):
        """
        >>> p>q
        relational(constant('q',numeric('3')),constant('p'),'<')
        """
    def __ge__ (self):
        """
        >>> p>=q
        relational(constant('q',numeric('3')),constant('p'),'<=')
        """
    def eval (self):
        """
        >>> p.eval ()
        constant('p')
        >>> q.eval ()
        constant('q',numeric('3'))
        >>> r.eval ()
        constant('r',2.0)
        >>> print repr (s.eval ())[:37]
        constant('s',<function <lambda> at 0x
        """
    def evalm (self):
        """
        >>> p.evalm ()
        constant('p')
        >>> q.evalm ()
        constant('q',numeric('3'))
        >>> r.evalm ()
        constant('r',2.0)
        >>> print repr (s.evalm())[:37]
        constant('s',<function <lambda> at 0x
        """
    def evalf (self):
        """
        >>> p.evalf ()
        constant('p')
        >>> q.evalf ()
        numeric('3.0')
        >>> r.evalf ()
        numeric('2.0')
        >>> s.evalf ()
        add(constant('p'),numeric('1.0'))
        """
    def op (self):
        """
        >>> p.op (0)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        """
    def nops (self):
        """
        >>> p.nops ()
        0
        """
    def to_list (self):
        """
        >>> p.to_list ()
        []
        """
    def is_zero (self):
        """
        >>> p.is_zero ()
        0
        """
    def is_equal (self):
        """
        >>> p.is_equal (1)
        0
        >>> p.is_equal (p)
        1
        >>> p.is_equal (q)
        0
        >>> p.is_equal (constant ('p'))
        1
        """
    def numer (self):
        """
        >>> p.numer ()
        constant('p')
        """
    def denom (self):
        """
        >>> p.denom ()
        numeric('1')
        """
    def numer_denom (self):
        """
        >>> p.numer_denom ()
        (constant('p'), numeric('1'))
        """
    def has (self):
        """
        >>> p.has (p)
        1
        >>> p.has (2)
        0
        """
    def coeff (self):
        """
        >>> p.coeff (p)
        numeric('1')
        >>> p.coeff (symbol ('p'))
        numeric('0')
        """
    def lcoeff (self):
        """
        >>> p.lcoeff (p)
        numeric('1')
        """
    def tcoeff (self):
        """
        >>> p.tcoeff (p)
        numeric('1')
        """
    def degree (self):
        """
        >>> p.degree (p)
        1
        >>> p.degree (symbol ('p'))
        0
        """
    def ldegree (self):
        """
        >>> p.ldegree (p)
        1
        >>> p.degree (symbol ('p'))
        0
        """
    def max_coefficient (self):
        """
        >>> p.max_coefficient ()
        numeric('1')
        """
    def integer_content (self):
        """
        >>> p.integer_content ()
        numeric('1')
        """
    def content (self):
        """
        >>> p.content(symbol ('p'))  # FIXME
        Traceback (most recent call last):
        ...
        RuntimeError: invalid expression in unit()
        """
    def swap (self):
        """
        >>> p,q
        (constant('p'), constant('q',numeric('3')))
        >>> p.swap (q)
        >>> p,q
        (constant('q',numeric('3')), constant('p'))
        >>> p.swap (q)
        >>> p,q
        (constant('p'), constant('q',numeric('3')))
        >>> a=symbol ('a')
        >>> p.swap (a)
        >>> p,a
        (symbol('a'), constant('p'))
        >>> a.swap (p)
        >>> p,a
        (constant('p'), symbol('a'))
        """
    def diff (self):
        """
        >>> p.diff (p)
        Traceback (most recent call last):
        ...
        TypeError: diff() method 1st argument must be symbol
        >>> p.diff (symbol ('p'))
        numeric('0')
        """
    def is_function (self):
        """
        >>> p.is_function ()
        0
        """
def _test():
    import test_constant
    return test_all.test(test_constant)

if __name__ == "__main__":
    _test()

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