Back to index

python3.2  3.2.2
Public Member Functions
test.test_pow.PowTest Class Reference

List of all members.

Public Member Functions

def powtest
def test_powint
def test_powlong
def test_powfloat
def test_other
def test_bug643260
def test_bug705231

Detailed Description

Definition at line 3 of file test_pow.py.


Member Function Documentation

def test.test_pow.PowTest.powtest (   self,
  type 
)

Definition at line 5 of file test_pow.py.

00005 
00006     def powtest(self, type):
00007         if type != float:
00008             for i in range(-1000, 1000):
00009                 self.assertEqual(pow(type(i), 0), 1)
00010                 self.assertEqual(pow(type(i), 1), type(i))
00011                 self.assertEqual(pow(type(0), 1), type(0))
00012                 self.assertEqual(pow(type(1), 1), type(1))
00013 
00014             for i in range(-100, 100):
00015                 self.assertEqual(pow(type(i), 3), i*i*i)
00016 
00017             pow2 = 1
00018             for i in range(0, 31):
00019                 self.assertEqual(pow(2, i), pow2)
00020                 if i != 30 : pow2 = pow2*2
00021 
00022             for othertype in (int,):
00023                 for i in list(range(-10, 0)) + list(range(1, 10)):
00024                     ii = type(i)
00025                     for j in range(1, 11):
00026                         jj = -othertype(j)
00027                         pow(ii, jj)
00028 
00029         for othertype in int, float:
00030             for i in range(1, 100):
00031                 zero = type(0)
00032                 exp = -othertype(i/10.0)
00033                 if exp == 0:
00034                     continue
00035                 self.assertRaises(ZeroDivisionError, pow, zero, exp)
00036 
00037         il, ih = -20, 20
00038         jl, jh = -5,   5
00039         kl, kh = -10, 10
00040         asseq = self.assertEqual
00041         if type == float:
00042             il = 1
00043             asseq = self.assertAlmostEqual
00044         elif type == int:
00045             jl = 0
00046         elif type == int:
00047             jl, jh = 0, 15
00048         for i in range(il, ih+1):
00049             for j in range(jl, jh+1):
00050                 for k in range(kl, kh+1):
00051                     if k != 0:
00052                         if type == float or j < 0:
00053                             self.assertRaises(TypeError, pow, type(i), j, k)
00054                             continue
00055                         asseq(
00056                             pow(type(i),j,k),
00057                             pow(type(i),j)% type(k)
00058                         )

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file test_pow.py.

00098 
00099     def test_bug643260(self):
00100         class TestRpow:
00101             def __rpow__(self, other):
00102                 return None
00103         None ** TestRpow() # Won't fail when __rpow__ invoked.  SF bug #643260.

Definition at line 104 of file test_pow.py.

00104 
00105     def test_bug705231(self):
00106         # -1.0 raised to an integer should never blow up.  It did if the
00107         # platform pow() was buggy, and Python didn't worm around it.
00108         eq = self.assertEqual
00109         a = -1.0
00110         # The next two tests can still fail if the platform floor()
00111         # function doesn't treat all large inputs as integers
00112         # test_math should also fail if that is happening
00113         eq(pow(a, 1.23e167), 1.0)
00114         eq(pow(a, -1.23e167), 1.0)
00115         for b in range(-10, 11):
00116             eq(pow(a, float(b)), b & 1 and -1.0 or 1.0)
00117         for n in range(0, 100):
00118             fiveto = float(5 ** n)
00119             # For small n, fiveto will be odd.  Eventually we run out of
00120             # mantissa bits, though, and thereafer fiveto will be even.
00121             expected = fiveto % 2.0 and -1.0 or 1.0
00122             eq(pow(a, fiveto), expected)
00123             eq(pow(a, -fiveto), expected)
00124         eq(expected, 1.0)   # else we didn't push fiveto to evenness

Here is the call graph for this function:

Definition at line 68 of file test_pow.py.

00068 
00069     def test_other(self):
00070         # Other tests-- not very systematic
00071         self.assertEqual(pow(3,3) % 8, pow(3,3,8))
00072         self.assertEqual(pow(3,3) % -8, pow(3,3,-8))
00073         self.assertEqual(pow(3,2) % -2, pow(3,2,-2))
00074         self.assertEqual(pow(-3,3) % 8, pow(-3,3,8))
00075         self.assertEqual(pow(-3,3) % -8, pow(-3,3,-8))
00076         self.assertEqual(pow(5,2) % -8, pow(5,2,-8))
00077 
00078         self.assertEqual(pow(3,3) % 8, pow(3,3,8))
00079         self.assertEqual(pow(3,3) % -8, pow(3,3,-8))
00080         self.assertEqual(pow(3,2) % -2, pow(3,2,-2))
00081         self.assertEqual(pow(-3,3) % 8, pow(-3,3,8))
00082         self.assertEqual(pow(-3,3) % -8, pow(-3,3,-8))
00083         self.assertEqual(pow(5,2) % -8, pow(5,2,-8))
00084 
00085         for i in range(-10, 11):
00086             for j in range(0, 6):
00087                 for k in range(-7, 11):
00088                     if j >= 0 and k != 0:
00089                         self.assertEqual(
00090                             pow(i,j) % k,
00091                             pow(i,j,k)
00092                         )
00093                     if j >= 0 and k != 0:
00094                         self.assertEqual(
00095                             pow(int(i),j) % k,
00096                             pow(int(i),j,k)
00097                         )

Here is the call graph for this function:

Definition at line 65 of file test_pow.py.

00065 
00066     def test_powfloat(self):
00067         self.powtest(float)

Here is the call graph for this function:

Definition at line 59 of file test_pow.py.

00059 
00060     def test_powint(self):
00061         self.powtest(int)

Here is the call graph for this function:

Definition at line 62 of file test_pow.py.

00062 
00063     def test_powlong(self):
00064         self.powtest(int)

Here is the call graph for this function:


The documentation for this class was generated from the following file: