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

  $Revision: 1.4 $
  $Id: test_relational.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_relational(ginac.relational):
    def __init__(self):
        """
        >>> relational(1,2)
        relational(numeric('1'),numeric('2'),'==')
        >>> relational (relational(1,2))
        relational(numeric('1'),numeric('2'),'==')
        >>> relational (relational(1,2),oper='<')
        Traceback (most recent call last):
        ...
        ValueError: relational(relational) expects lhs is None and oper=\"==\" but got (None,'<')
        >>> isinstance (relational(1,2),relational)
        1
        >>> isinstance (ex (),relational)
        0
        """
    def extract_archived(self):
        """
        >>> relational(1,2).extract_archived()
        {'op': 0L, 'lh': {'number': '1', 'class': 'numeric'}, 'class': 'relational', 'rh': {'number': '2', 'class': 'numeric'}}
        """
    def get_precedence(self):
        """
        >>> relational(1,2).get_precedence()
        20
        """
    def get_class_name(self):
        """
        >>> relational(1,2).get_class_name()
        'relational'
        """
    def __repr__(self):
        """
        >>> relational(1,2,'!=')
        relational(numeric('1'),numeric('2'),'!=')
        >>> relational(1,2,'<')
        relational(numeric('1'),numeric('2'),'<')
        >>> relational(1,2,'<=')
        relational(numeric('1'),numeric('2'),'<=')
        >>> relational(1,2,'>')
        relational(numeric('1'),numeric('2'),'>')
        >>> relational(1,2,'>=')
        relational(numeric('1'),numeric('2'),'>=')
        """
    def __str__(self):
        """
        >>> str (relational(1,2))
        '1==2'
        >>> str (relational(1,2,'!='))
        '1!=2'
        >>> str (relational(1,2,'<'))
        '1<2'
        >>> str (relational(1,2,'<='))
        '1<=2'
        >>> str (relational(1,2,'>'))
        '1>2'
        >>> str (relational(1,2,'>='))
        '1>=2'
        """
    def to_context(self):
        """
        >>> relational(1,2).to_context()
        '1==2'
        >>> relational(1,2).to_context('latex')
        '1==2'
        """
    def __nonzero__(self):
        """
        >>> not not relational(1,2)
        0
        >>> not not relational(1,2,'<')
        1
        >>> not not relational(1,2,'>')
        0
        >>> not not relational(1,symbol('a'),'>')
        0
        >>> not not relational(1,symbol('a'),'<')
        0
        >>> not not relational(1,symbol('a'),'!=')
        1
        >>> not not relational(symbol('a'),symbol('a'),'==')
        1
        """
    def operator (self):
        """
        >>> relational (1,2).operator ()
        '=='
        >>> relational (1,2,'<').operator ()
        '<'
        """
    def lhs (self):
        """
        >>> relational (3,2).lhs ()
        numeric('3')
        """
    def rhs (self):
        """
        >>> relational (3,2).rhs ()
        numeric('2')
        """
    def relat_ops (self):
        """
        >>> r=relational(1,2)
        >>> s=symbol ('a')
        >>> r<s
        Traceback (most recent call last):
        ...
        TypeError: symbol > relational not defined
        >>> r+s
        Traceback (most recent call last):
        ...
        TypeError: relational + symbol not defined
        >>> s+r
        Traceback (most recent call last):
        ...
        TypeError: symbol + relational not defined
        """
    def op (self):
        """
        >>> relational (2,3).op (0)
        numeric('2')
        >>> relational (2,3).op (1)
        numeric('3')
        >>> relational (2,3).op (2)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        >>> relational (2,3).op (-1)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        """
    def nops (self):
        """
        >>> relational (1,2).nops ()
        2
        """
    def swap (self):
        """
        >>> r = relational (3,4)
        >>> s = numeric ('3.4')
        >>> r.swap (s)
        >>> r
        numeric('3.4')
        >>> s
        relational(numeric('3'),numeric('4'),'==')
        """
    def is_equal (self):
        """
        >>> r = relational (1,2)
        >>> r.is_equal (relational (1,2))
        1
        >>> r.is_equal (relational (2,1))
        1
        >>> a = symbol ('a')
        >>> b = symbol ('b')
        >>> (a<b) .is_equal (a<b)
        1
        >>> (a<b) .is_equal (b>a)
        1
        >>> (a<=b) .is_equal (b>=a)
        1
        >>> (a>b) .is_equal (b<a)
        1
        >>> (a>=b) .is_equal (b<=a)
        1
        >>> (a!=b) .is_equal (b!=a)
        1
        >>> (a==b) .is_equal (b==a)
        1
        >>> (a==b) .is_equal (b==2)
        0
        >>> relational (a,b,'<').is_equal (relational (b,a,'>'))
        1
        >>> relational (a,b,'<').is_equal (relational (b,a,'>='))
        0
        >>> relational (a,b,'<=').is_equal (relational (b,a,'>='))
        1
        >>> relational (a,b,'>').is_equal (relational (b,a,'<'))
        1
        >>> relational (a,b,'>=').is_equal (relational (b,a,'<='))
        1
        >>> relational (a,b,'>=').is_equal (relational (b,a,'<'))
        0
        >>> relational (a,b,'>=').is_equal (relational (b,2,'<='))
        0
        """
    def is_zero (self):
        """
        >>> relational (1,2).is_zero ()
        0
        >>> relational (1,1).is_zero ()
        0
        """
    def eval (self):
        """
        >>> relational (1,2).eval ()
        relational(numeric('1'),numeric('2'),'==')
        """
    def evalf (self):
        """
        >>> relational (1,2).evalf ()
        relational(numeric('1.0'),numeric('2.0'),'==')
        """
    def evalm (self):
        """
        TODO: relational (matrix,matrix).evalm ()

        >>> relational (1,2).evalm ()
        relational(numeric('1'),numeric('2'),'==')
        """
    def get_hash (self):
        """
        >>> type (relational (1,2).get_hash ()) is type (0)
        1
        >>> a,b=symbol ('a'),symbol ('b')
        >>> relational (a,b).get_hash () == relational (b,a).get_hash ()
        1
        >>> relational (a,b,'<').get_hash () == relational (b,a).get_hash ()
        0
        >>> relational (a,b,'<').get_hash () == relational (b,a,'>').get_hash ()
        1
        """
    def to_list (self):
        """
        >>> relational (1,2,'<').to_list ()
        [numeric('1'), numeric('2')]
        """
    def has(self):
        """
        >>> a,b=symbol ('a'),symbol ('b')
        >>> r = relational (2,b)
        >>> r.has (2)
        1
        >>> r.has (3)
        0
        >>> r.has (b)
        1
        >>> r.has (a)
        0
        """
    def is_function (self):
        """
        >>> relational (1,2).is_function ()
        0
        """


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

if __name__ == "__main__":
    _test()

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