home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_pow.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  3.6 KB  |  98 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import sys
  5. import test_support
  6.  
  7. def powtest(type):
  8.     if type != float:
  9.         print '    Testing 2-argument pow() function...'
  10.         for i in range(-1000, 1000):
  11.             if pow(type(i), 1) != type(i):
  12.                 raise ValueError, 'pow(' + str(i) + ',1) != ' + str(i)
  13.             
  14.             if pow(type(0), 1) != type(0):
  15.                 raise ValueError, 'pow(0,' + str(i) + ') != 0'
  16.             
  17.             if pow(type(1), 1) != type(1):
  18.                 raise ValueError, 'pow(1,' + str(i) + ') != 1'
  19.             
  20.         
  21.         for i in range(-100, 100):
  22.             pass
  23.         
  24.         pow2 = 1
  25.         for i in range(0, 31):
  26.             if i != 30:
  27.                 pow2 = pow2 * 2
  28.             
  29.         
  30.     
  31.     print '    Testing 3-argument pow() function...'
  32.     (il, ih) = (-20, 20)
  33.     (jl, jh) = (-5, 5)
  34.     (kl, kh) = (-10, 10)
  35.     compare = cmp
  36.     if type == float:
  37.         il = 1
  38.         compare = test_support.fcmp
  39.     elif type == int:
  40.         jl = 0
  41.     elif type == long:
  42.         (jl, jh) = (0, 15)
  43.     
  44.     for i in range(il, ih + 1):
  45.         for j in range(jl, jh + 1):
  46.             for k in range(kl, kh + 1):
  47.                 pass
  48.             
  49.         
  50.     
  51.  
  52. print 'Testing integer mode...'
  53. powtest(int)
  54. print 'Testing long integer mode...'
  55. powtest(long)
  56. print 'Testing floating point mode...'
  57. powtest(float)
  58. print 'The number in both columns should match.'
  59. print pow(3, 3) % 8, pow(3, 3, 8)
  60. print pow(3, 3) % -8, pow(3, 3, -8)
  61. print pow(3, 2) % -2, pow(3, 2, -2)
  62. print pow(-3, 3) % 8, pow(-3, 3, 8)
  63. print pow(-3, 3) % -8, pow(-3, 3, -8)
  64. print pow(5, 2) % -8, pow(5, 2, -8)
  65. print 
  66. print pow(0x3L, 0x3L) % 8, pow(0x3L, 0x3L, 8)
  67. print pow(0x3L, 0x3L) % -8, pow(0x3L, 0x3L, -8)
  68. print pow(0x3L, 2) % -2, pow(0x3L, 2, -2)
  69. print pow(-0x3L, 0x3L) % 8, pow(-0x3L, 0x3L, 8)
  70. print pow(-0x3L, 0x3L) % -8, pow(-0x3L, 0x3L, -8)
  71. print pow(0x5L, 2) % -8, pow(0x5L, 2, -8)
  72. print 
  73. print pow(3.0, 3.0) % 8, pow(3.0, 3.0, 8)
  74. print pow(3.0, 3.0) % -8, pow(3.0, 3.0, -8)
  75. print pow(3.0, 2) % -2, pow(3.0, 2, -2)
  76. print pow(5.0, 2) % -8, pow(5.0, 2, -8)
  77. print 
  78. for i in range(-10, 11):
  79.     for j in range(0, 6):
  80.         for k in range(-7, 11):
  81.             if j >= 0 and k != 0:
  82.                 o = pow(long(i), j) % k
  83.                 n = pow(long(i), j, k)
  84.                 if o != n:
  85.                     print 'Long mismatch:', i, j, k
  86.                 
  87.             
  88.             if i >= 0 and k != 0:
  89.                 o = pow(float(i), j) % k
  90.                 n = pow(float(i), j, k)
  91.                 if o != n:
  92.                     print 'Float mismatch:', i, j, k
  93.                 
  94.             
  95.         
  96.     
  97.  
  98.