Skip to content

Commit 87882e1

Browse files
committed
tests: Split tests for 2- and 3-arg pow().
1 parent df0117c commit 87882e1

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

tests/basics/builtin_pow.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,7 @@
11
# test builtin pow() with integral values
2-
32
# 2 arg version
3+
44
print(pow(0, 1))
55
print(pow(1, 0))
66
print(pow(-2, 3))
77
print(pow(3, 8))
8-
9-
# 3 arg version
10-
print(pow(3, 4, 7))
11-
print(pow(555557, 1000002, 1000003))
12-
13-
# 3 arg pow is defined to only work on integers
14-
try:
15-
print(pow("x", 5, 6))
16-
except TypeError:
17-
print("TypeError expected")
18-
19-
try:
20-
print(pow(4, "y", 6))
21-
except TypeError:
22-
print("TypeError expected")
23-
24-
try:
25-
print(pow(4, 5, "z"))
26-
except TypeError:
27-
print("TypeError expected")
28-
29-
# Tests for 3 arg pow with large values
30-
31-
# This value happens to be prime
32-
x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849
33-
y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5
34-
35-
print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200
36-
print(hex(pow(2, x-1, x))) # Should be 1, since x is prime
37-
print(hex(pow(y, x-1, x))) # Should be 1, since x is prime
38-
print(hex(pow(y, y-1, x))) # Should be a 'big value'
39-
print(hex(pow(y, y-1, y))) # Should be a 'big value'

tests/basics/builtin_pow3.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# test builtin pow() with integral values
2+
# 3 arg version
3+
4+
try:
5+
print(pow(3, 4, 7))
6+
except NotImplementedError:
7+
import sys
8+
print("SKIP")
9+
sys.exit()
10+
11+
print(pow(555557, 1000002, 1000003))
12+
13+
# 3 arg pow is defined to only work on integers
14+
try:
15+
print(pow("x", 5, 6))
16+
except TypeError:
17+
print("TypeError expected")
18+
19+
try:
20+
print(pow(4, "y", 6))
21+
except TypeError:
22+
print("TypeError expected")
23+
24+
try:
25+
print(pow(4, 5, "z"))
26+
except TypeError:
27+
print("TypeError expected")
28+
29+
# Tests for 3 arg pow with large values
30+
31+
# This value happens to be prime
32+
x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849
33+
y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5
34+
35+
print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200
36+
print(hex(pow(2, x-1, x))) # Should be 1, since x is prime
37+
print(hex(pow(y, x-1, x))) # Should be 1, since x is prime
38+
print(hex(pow(y, y-1, x))) # Should be a 'big value'
39+
print(hex(pow(y, y-1, y))) # Should be a 'big value'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy