File:  [CENS] / python / pyGiNaC / test4 / test_symbol.py
Revision 1.6: 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.6 $
  $Id: test_symbol.py,v 1.6 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_symbol(ginac.symbol):
    """
    >>> symbol._counter = 0
    >>> class symbol (symbol): _cache = {}
    ...

    Define symbols:
    >>> a,ab = symbol(name = 'a'), symbol(name = 'ab', TeX_name = 'b')
    >>> symbol ('a')
    symbol('a')
    >>> symbol('a','aa')
    Traceback (most recent call last):
    ...
    ValueError: symbol 'a' has a TeX_name
    >>> c,cd = symbol('c'), symbol('cd', 'cd')
    >>> e1,e2 = symbol(), symbol() 
    >>> alpha = symbol('alpha')
    >>> test_save(a=a,ab=ab,c=c,cd=cd,e1=e1,e2=e2,alpha=alpha,b=symbol('b'),symbol=symbol)
    >>> symbol (3.4)
    Traceback (most recent call last):
    ...
    TypeError: symbol() expects string name but got <type 'float'>
    >>> symbol (ex ())
    Traceback (most recent call last):
    ...
    TypeError: symbol() expects string name but got <type 'instance'>
    >>> class my_symbol (symbol): _cache = {};_counter=0
    ...
    >>> my_symbol ('a','AA').is_equal (symbol ('a'))
    0
    >>> my_symbol ('a').is_equal (my_symbol ('a'))
    1
    >>> symbol ('a').is_equal (symbol ('a'))
    1
    >>> symbol ()
    symbol('symbol2')
    >>> my_symbol ()
    symbol('symbol0')
    """
    def __init__(self):
        """
        See above.
        """
    def __repr__(self):
        """
        >>> a, ab
        (symbol('a'), symbol('ab','b'))
        >>> c, cd
        (symbol('c'), symbol('cd'))
        >>> e1, e2
        (symbol('symbol0'), symbol('symbol1'))
        >>> alpha
        symbol('alpha')
        """
    def __str__(self):
        """
        >>> map(str,[a,ab,c,cd,e1,e2,alpha])
        ['a', 'ab', 'c', 'cd', 'symbol0', 'symbol1', 'alpha']
        """
    def to_context(self):
        """
        >>> a.to_context(), a.to_context('latex')
        ('a', 'a')
        >>> ab.to_context('context'), ab.to_context('latex')
        ('ab', 'b')
        >>> alpha.to_context(), alpha.to_context('latex')
        ('alpha', '\\\\alpha')
        >>> symbol('\\\\alpha_1').to_context('latex')
        '\\\\alpha_1'
        >>> ab.to_context('csrc')
        'ab'
        >>> type(ab.to_context('tree',level=0))
        <type 'string'>
        >>> import tempfile
        >>> f = tempfile.TemporaryFile()
        >>> ab.to_context(file=f)
        >>> f.seek(0)
        >>> f.read()
        'ab'
        >>> f.close()
        >>> a.to_context ('python')
        'a'
        >>> a.to_context ('python_repr')
        "symbol('a')"
        >>> ab.to_context ('python_repr')
        "symbol('ab','b')"
        >>> alpha.to_context ('python_repr')
        "symbol('alpha')"
        """
    def get_name(self):
        """
        >>> ab.get_name()
        'ab'
        """
    def get_TeX_name(self):
        """
        >>> ab.get_TeX_name()
        'b'
        """
    def set_name(self):
        """
        >>> f = symbol('f')
        >>> f
        symbol('f')
        >>> f.set_name('g')
        >>> f
        symbol('g','f')
        """
    def get_class_name(self):
        """
        >>> a.get_class_name()
        'symbol'
        """
    def get_precedence(self):
        """
        >>> a.get_precedence()
        70
        """
    def extract_archived(self):
        """
        >>> a.extract_archived()
        {'class': 'symbol', 'name': 'a'}
        """
    def __add__(self):
        """
        >>> a + 0
        symbol('a')
        """
    def __radd__(self):
        """
        >>> 0 + a
        symbol('a')
        """
    def __sub__(self):
        """
        >>> a - 0
        symbol('a')
        """
    def __rsub__(self):
        """
        >>> 0 - (-a)
        symbol('a')
        """
    def __mul__(self):
        """
        >>> a * 1
        symbol('a')
        """
    def __rmul__(self):
        """
        >>> 1 * a
        symbol('a')
        """
    def __div__(self):
        """
        >>> a / 1
        symbol('a')
        """
    def __rdiv__(self):
        """
        >>> 1 / (1 / a)
        symbol('a')
        """
    def __pow__ (self):
        """
        >>> a**b
        power(symbol('a'),symbol('b'))
        >>> a**2
        power(symbol('a'),numeric('2'))
        """
    def __rpow__ (self):
        """
        >>> 2**a
        power(numeric('2'),symbol('a'))
        """
    def __neg__(self):
        """
        >>> -(-a)
        symbol('a')
        """
    def __pos__(self):
        """
        >>> +a
        symbol('a')
        """
    def __nonzero__(self):
        """
        >>> not a
        0
        """
    def __abs__ (self):
        """
        >>> abs (a)
        abs(symbol('a'))
        """
    def __eq__ (self):
        """
        >>> a==b
        relational(symbol('a'),symbol('b'),'==')
        """
    def __ne__ (self):
        """
        >>> a!=b
        relational(symbol('a'),symbol('b'),'!=')
        """
    def __lt__ (self):
        """
        >>> a<b
        relational(symbol('a'),symbol('b'),'<')
        """
    def __le__ (self):
        """
        >>> a<=b
        relational(symbol('a'),symbol('b'),'<=')
        """
    def __gt__ (self):
        """
        >>> a>b
        relational(symbol('b'),symbol('a'),'<')
        """
    def __ge__ (self):
        """
        >>> a>=b
        relational(symbol('b'),symbol('a'),'<=')
        """
    def numer (self):
        """
        >>> a.numer ()
        symbol('a')
        """
    def denom (self):
        """
        >>> a.denom ()
        numeric('1')
        """
    def numer_denom (self):
        """
        >>> a.numer_denom ()
        (symbol('a'), numeric('1'))
        """
    def op (self):
        """
        >>> a.op (0)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        """
    def nops (self):
        """
        >>> a.nops ()
        0
        """
    def is_equal (self):
        """
        >>> a.is_equal (a)
        1
        >>> a.is_equal (b)
        0
        >>> a.is_equal (2)
        0
        >>> a.is_equal (symbol ('a'))
        1
        """
    def eval (self):
        """
        >>> a.eval ()
        symbol('a')
        """
    def evalf (self):
        """
        >>> a.evalf ()
        symbol('a')
        """
    def evalm (self):
        """
        >>> a.evalm ()
        symbol('a')
        """
    def is_zero ():
        """
        >>> a.is_zero ()
        0
        """
    def diff (self):
        """
        >>> a.diff (b)
        numeric('0')
        >>> a.diff (a)
        numeric('1')
        >>> a.diff (a,0)
        symbol('a')
        >>> a.diff (a,2)
        numeric('0')
        """
    def has (self):
        """
        >>> a.has (a)
        1
        >>> a.has (2)
        0
        >>> a.has (b)
        0
        >>> a.has (symbol ('a'))
        1
        """
    def swap (self):
        """
        >>> a.swap (b)
        >>> a,b
        (symbol('b'), symbol('a'))
        >>> a.swap (b)
        >>> a,b
        (symbol('a'), symbol('b'))
        """
    def to_list (self):
        """
        >>> a.to_list ()
        []
        """
    def coeff (self):
        """
        >>> a.coeff (a)
        numeric('1')
        >>> a.coeff (a,2)
        numeric('0')
        >>> a.coeff (a,0)
        numeric('0')
        >>> a.coeff (b)
        numeric('0')
        >>> a.coeff (b,3.4)
        Traceback (most recent call last):
        ...
        TypeError: coeff() method 2nd argument must be int but got <type 'float'>
        """
    def lcoeff (self):
        """
        >>> a.lcoeff (a)
        numeric('1')
        >>> a.lcoeff (b)
        symbol('a')
        >>> a.lcoeff (3)
        symbol('a')
        """
    def tcoeff (self):
        """
        >>> a.tcoeff (a)
        numeric('1')
        >>> a.tcoeff (b)
        symbol('a')
        """
    def degree (self):
        """
        >>> a.degree (a)
        1
        >>> a.degree (b)
        0
        >>> a.degree (2)
        0
        """
    def ldegree (self):
        """
        >>> a.ldegree (a)
        1
        >>> a.ldegree (b)
        0
        """
    def integer_content (self):
        """
        >>> a.integer_content ()
        numeric('1')
        """
    def content (self):
        """
        >>> a.content (a)
        numeric('1')
        >>> a.content (b)
        symbol('a')
        >>> a.content (2)
        Traceback (most recent call last):
        ...
        TypeError: content() method argument must be symbol
        """
    def max_coefficient (self):
        """
        >>> a.max_coefficient ()
        numeric('1')
        """
    def primpart (self):
        """
        >>> a.primpart (a)
        symbol('a')
        >>> a.primpart (b)
        numeric('1')
        >>> a.primpart (symbol ('a'))
        symbol('a')
        """
    def unit (self):
        """
        >>> a.unit (a)
        numeric('1')
        >>> a.unit (b)
        numeric('1')
        """
    def smod (self):
        """
        >>> a.smod (2)
        symbol('a')
        >>> a.smod (1)
        symbol('a')
        >>> a.smod (-3)
        symbol('a')
        """
    def get_hash (self):
        """
        >>> type (a.get_hash ()) is type (0)
        1
        """
    def __coerce__ (self):
        """
        >>> coerce (a,3)
        (symbol('a'), numeric('3'))
        """
    def is_function (self):
        """
        >>> symbol ('a').is_function ()
        0
        """

def _test():
    import test_symbol
    return test_all.test(test_symbol)

if __name__ == "__main__":
    _test()


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