MCPcopy Index your code
hub / github.com/RustPython/RustPython / powtest

Function powtest

extra_tests/snippets/builtin_pow.py:29–79  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

27
28
29def powtest(type):
30 if type != float:
31 for i in range(-1000, 1000):
32 assert_equal(pow(type(i), 0), 1)
33 assert_equal(pow(type(i), 1), type(i))
34 assert_equal(pow(type(0), 1), type(0))
35 assert_equal(pow(type(1), 1), type(1))
36
37 for i in range(-100, 100):
38 assert_equal(pow(type(i), 3), i * i * i)
39
40 pow2 = 1
41 for i in range(0, 31):
42 assert_equal(pow(2, i), pow2)
43 if i != 30:
44 pow2 = pow2 * 2
45
46 for othertype in (int,):
47 for i in list(range(-10, 0)) + list(range(1, 10)):
48 ii = type(i)
49 for j in range(1, 11):
50 jj = -othertype(j)
51 pow(ii, jj)
52
53 for othertype in int, float:
54 for i in range(1, 100):
55 zero = type(0)
56 exp = -othertype(i / 10.0)
57 if exp == 0:
58 continue
59 assert_raises(ZeroDivisionError, pow, zero, exp)
60
61 il, ih = -20, 20
62 jl, jh = -5, 5
63 kl, kh = -10, 10
64 asseq = assert_equal
65 if type == float:
66 il = 1
67 asseq = assert_almost_equal
68 elif type == int:
69 jl = 0
70 elif type == int:
71 jl, jh = 0, 15
72 for i in range(il, ih + 1):
73 for j in range(jl, jh + 1):
74 for k in range(kl, kh + 1):
75 if k != 0:
76 if type == float or j < 0:
77 assert_raises(TypeError, pow, type(i), j, k)
78 continue
79 asseq(pow(type(i), j, k), pow(type(i), j) % type(k))
80
81
82def test_powint():

Callers 2

test_powintFunction · 0.85
test_powfloatFunction · 0.85

Calls 4

assert_equalFunction · 0.90
assert_raisesFunction · 0.90
listClass · 0.85
powFunction · 0.50

Tested by 2

test_powintFunction · 0.68
test_powfloatFunction · 0.68