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

  $Revision: 1.3 $
  $Id: test_add.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_add(ginac.add):
    """
    >>> test_save (s=symbol ('a')+1,t=symbol ('b')-2,w=2*symbol ('a')+6)
    """
    def __init__(self):
        """
        >>> add()
        numeric('0')
        >>> add(3,4)
        numeric('7')
        >>> add(3,symbol('a'))
        add(symbol('a'),numeric('3'))
        """
    def __repr__(self):
        """See __init__."""
    def __str__(self):
        """
        >>> add(3,symbol('a')).__str__()
        '3+a'
        >>> add(3,-symbol('a')).__str__()
        '3-a'
        >>> add(-3,symbol('a')).__str__()
        '-3+a'
        >>> add(symbol('b'),symbol('a')).__str__()
        'b+a'
        >>> add(-symbol('b'),symbol('a')).__str__()
        '-b+a'
        """
    def to_context(self):
        """
        >>> add(3,symbol('a')).to_context()
        '3+a'
        >>> add(3,symbol('a')).to_context('latex')
        '3+a'
        >>> add(3,symbol('a')).to_context('csrc')
        'a+3.000000e+00'
        """
    def extract_archived(self):
        """
        >>> add(3,symbol('a')).extract_archived()
        {'rest': [{'class': 'symbol', 'name': 'a'}], 'class': 'add', 'overall_coeff': {'number': '3', 'class': 'numeric'}, 'coeff': [{'number': '1', 'class': 'numeric'}]}
        """
    def get_precedence(self):
        """
        >>> add(3,symbol('a')).get_precedence()
        40
        """
    def get_class_name(self):
        """
        >>> add(3,symbol('a')).get_class_name()
        'add'
        """
    def nops(self):
        """
        >>> add(3,symbol('a')).nops()
        2
        """
    def op(self):
        """
        >>> add(3,symbol('a')).op(0)
        symbol('a')
        """
    def is_zero(self):
        """
        >>> add(3,symbol('a')).is_zero()
        0
        """
    def __abs__ (self):
        """
        >>> abs (s)
        abs(add(symbol('a'),numeric('1')))
        """
    def __pos__ (self):
        """
        >>> +s
        add(symbol('a'),numeric('1'))
        """
    def __neg__ (self):
        """
        >>> -s
        add(mul(symbol('a'),numeric('-1')),numeric('-1'))
        """
    def __add__ (self):
        """
        >>> s+1
        add(symbol('a'),numeric('2'))
        """
    def __radd__ (self):
        """
        >>> 2+s
        add(symbol('a'),numeric('3'))
        """
    def __sub__ (self):
        """
        >>> s-3
        add(symbol('a'),numeric('-2'))
        """
    def __rsub__ (self):
        """
        >>> 3-s
        add(mul(symbol('a'),numeric('-1')),numeric('2'))
        """
    def __mul__ (self):
        """
        >>> s*2
        add(mul(symbol('a'),numeric('2')),numeric('2'))
        """
    def __rmul__ (self):
        """
        >>> 2*s
        add(mul(symbol('a'),numeric('2')),numeric('2'))
        """
    def __pow__ (self):
        """
        >>> s**2
        power(add(symbol('a'),numeric('1')),numeric('2'))
        """
    def __rpow__ (self):
        """
        >>> 2**s
        power(numeric('2'),add(symbol('a'),numeric('1')))
        """
    def __div__ (self):
        """
        >>> s/2
        add(mul(symbol('a'),numeric('1/2')),numeric('1/2'))
        """
    def __rdiv__ (self):
        """
        >>> 2/s
        mul(power(add(symbol('a'),numeric('1')),numeric('-1')),numeric('2'))
        """
    def __coerce__ (self):
        """
        >>> coerce (s,1)
        (add(symbol('a'),numeric('1')), numeric('1'))
        """
    def __nonzero__ (self):
        """
        >>> not s
        0
        """
    def __eq__ (self):
        """
        >>> s==3
        relational(add(symbol('a'),numeric('1')),numeric('3'),'==')
        """
    def __ne__ (self):
        """
        >>> 3!=s
        relational(add(symbol('a'),numeric('1')),numeric('3'),'!=')
        """
    def __lt__ (self):
        """
        >>> s<2
        relational(add(symbol('a'),numeric('1')),numeric('2'),'<')
        """
    def __le__ (self):
        """
        >>> s<=2
        relational(add(symbol('a'),numeric('1')),numeric('2'),'<=')
        """
    def __gt__ (self):
        """
        >>> s>2
        relational(numeric('2'),add(symbol('a'),numeric('1')),'<')
        """
    def __ge__ (self):
        """
        >>> s>=2
        relational(numeric('2'),add(symbol('a'),numeric('1')),'<=')
        """
    def to_list (self):
        """
        >>> s.to_list ()
        [symbol('a'), numeric('1')]
        >>> t.to_list ()
        [symbol('b'), numeric('-2')]
        """
    def numer (self):
        """
        >>> s.numer ()
        add(symbol('a'),numeric('1'))
        """
    def denom (self):
        """
        >>> s.denom ()
        numeric('1')
        """
    def numer_denom (self):
        """
        >>> s.numer_denom ()
        (add(symbol('a'),numeric('1')), numeric('1'))
        >>> (s/2).numer_denom ()
        (add(symbol('a'),numeric('1')), numeric('2'))
        """
    def has (self):
        """
        >>> s.has (s)
        1
        >>> s.has (s-1)
        1
        >>> s.has (s-2)
        0
        >>> s.has (symbol ('a'))
        1
        >>> s.has (1)
        1
        >>> s.has (2)
        0
        >>> s.has (symbol ('b'))
        0
        """
    def is_equal (self):
        """
        >>> s.is_equal (s)
        1
        >>> s.is_equal (symbol ('a'))
        0
        >>> s.is_equal (s+1)
        0
        """
    def swap (self):
        """
        >>> s.swap (t)
        >>> s,t
        (add(symbol('b'),numeric('-2')), add(symbol('a'),numeric('1')))
        >>> s.swap (t)
        >>> s,t
        (add(symbol('a'),numeric('1')), add(symbol('b'),numeric('-2')))
        """
    def diff (self):
        """
        >>> s.diff (symbol ('a'))
        numeric('1')
        >>> t.diff (symbol ('a'))
        numeric('0')
        >>> t.diff (symbol ('b'))
        numeric('1')
        """
    def eval (self):
        """
        >>> s.eval ()
        add(symbol('a'),numeric('1'))
        """
    def evalm (self):
        """
        >>> s.evalm ()
        add(symbol('a'),numeric('1'))
        """
    def evalf (self):
        """
        >>> s.evalf ()
        add(symbol('a'),numeric('1.0'))
        """
    def max_coefficient (self):
        """
        >>> w.max_coefficient ()
        numeric('6')
        """
    def integer_content (self):
        """
        >>> w.integer_content ()
        numeric('2')
        """
    def content (self):
        """
        >>> w.content (symbol ('a'))
        numeric('2')
        """
    def degree (self):
        """
        >>> w.degree (symbol ('a'))
        1
        """
    def ldegree (self):
        """
        >>> w.ldegree (symbol ('a'))
        0
        """
    def coeff (self):
        """
        >>> w.coeff (symbol ('a'))
        numeric('2')
        >>> w.coeff (symbol ('a'),0)
        numeric('6')
        >>> w.coeff (symbol ('a'),-1)
        numeric('0')
        """
    def lcoeff (self):
        """
        >>> w.lcoeff (symbol ('a'))
        numeric('2')
        """
    def tcoeff (self):
        """
        >>> w.tcoeff (symbol ('a'))
        numeric('6')
        """
    def primpart (self):
        """
        >>> w.primpart (symbol ('a'))
        add(symbol('a'),numeric('3'))
        """
    def unit (self):
        """
        >>> w.unit (symbol ('a'))
        numeric('1')
        """
    def smod (self):
        """
        >>> w.smod (2)
        numeric('0')
        >>> w.smod (3)
        mul(symbol('a'),numeric('2'))
        >>> w.smod (1)
        add(symbol('a'),numeric('1'))
        >>> w.smod (0)
        Traceback (most recent call last):
        ...
        ZeroDivisionError: division by zero
        >>> w.smod (-2)
        add(mul(symbol('a'),numeric('2')),numeric('2'))
        >>> w.smod (-3)
        add(mul(symbol('a'),numeric('2')),numeric('3'))
        >>> w.smod (-5)
        add(mul(symbol('a'),numeric('2')),numeric('1'))
        >>> w.smod (-12)
        add(mul(symbol('a'),numeric('2')),numeric('6'))
        """
    def get_hash (self):
        """
        >>> s.get_hash ()==(1+symbol ('a')).get_hash ()
        1
        """
    def is_function (self):
        """
        >>> w.is_function ()
        0
        """
def _test():
    import test_add
    return test_all.test(test_add)

if __name__ == "__main__":
    _test()

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