python-2.5.2/win32/Lib/test/test_cmath.py
changeset 0 ae805ac0140d
equal deleted inserted replaced
-1:000000000000 0:ae805ac0140d
       
     1 #! /usr/bin/env python
       
     2 """ Simple test script for cmathmodule.c
       
     3     Roger E. Masse
       
     4 """
       
     5 import cmath, math
       
     6 from test.test_support import verbose, verify, TestFailed
       
     7 
       
     8 verify(abs(cmath.log(10) - math.log(10)) < 1e-9)
       
     9 verify(abs(cmath.log(10,2) - math.log(10,2)) < 1e-9)
       
    10 try:
       
    11     cmath.log('a')
       
    12 except TypeError:
       
    13     pass
       
    14 else:
       
    15     raise TestFailed
       
    16 
       
    17 try:
       
    18     cmath.log(10, 'a')
       
    19 except TypeError:
       
    20     pass
       
    21 else:
       
    22     raise TestFailed
       
    23 
       
    24 
       
    25 testdict = {'acos' : 1.0,
       
    26             'acosh' : 1.0,
       
    27             'asin' : 1.0,
       
    28             'asinh' : 1.0,
       
    29             'atan' : 0.2,
       
    30             'atanh' : 0.2,
       
    31             'cos' : 1.0,
       
    32             'cosh' : 1.0,
       
    33             'exp' : 1.0,
       
    34             'log' : 1.0,
       
    35             'log10' : 1.0,
       
    36             'sin' : 1.0,
       
    37             'sinh' : 1.0,
       
    38             'sqrt' : 1.0,
       
    39             'tan' : 1.0,
       
    40             'tanh' : 1.0}
       
    41 
       
    42 for func in testdict.keys():
       
    43     f = getattr(cmath, func)
       
    44     r = f(testdict[func])
       
    45     if verbose:
       
    46         print 'Calling %s(%f) = %f' % (func, testdict[func], abs(r))
       
    47 
       
    48 p = cmath.pi
       
    49 e = cmath.e
       
    50 if verbose:
       
    51     print 'PI = ', abs(p)
       
    52     print 'E = ', abs(e)