Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7f270ba8
Commit
7f270ba8
authored
Aug 13, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a test specifically to tickle Karatsuba; it costs no appreciable
runtime.
parent
22dae28c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
Lib/test/test_long.py
Lib/test/test_long.py
+26
-0
No files found.
Lib/test/test_long.py
View file @
7f270ba8
...
@@ -99,7 +99,32 @@ def test_division(maxdigits=MAXDIGITS):
...
@@ -99,7 +99,32 @@ def test_division(maxdigits=MAXDIGITS):
for
leny
in
digits
:
for
leny
in
digits
:
y
=
getran
(
leny
)
or
1L
y
=
getran
(
leny
)
or
1L
test_division_2
(
x
,
y
)
test_division_2
(
x
,
y
)
# ------------------------------------------------------------ karatsuba
def
test_karatsuba
():
if
verbose
:
print
"Karatsuba"
digits
=
range
(
1
,
5
)
+
range
(
KARATSUBA_CUTOFF
,
KARATSUBA_CUTOFF
+
10
)
digits
.
extend
([
KARATSUBA_CUTOFF
*
10
,
KARATSUBA_CUTOFF
*
100
])
bits
=
[
digit
*
SHIFT
for
digit
in
digits
]
# Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) ==
# 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check.
for
abits
in
bits
:
a
=
(
1L
<<
abits
)
-
1
for
bbits
in
bits
:
if
bbits
<
abits
:
continue
b
=
(
1L
<<
bbits
)
-
1
x
=
a
*
b
y
=
((
1L
<<
(
abits
+
bbits
))
-
(
1L
<<
abits
)
-
(
1L
<<
bbits
)
+
1
)
check
(
x
==
y
,
"bad result for"
,
a
,
"*"
,
b
,
x
,
y
)
# -------------------------------------------------------------- ~ & | ^
# -------------------------------------------------------------- ~ & | ^
def
test_bitop_identities_1
(
x
):
def
test_bitop_identities_1
(
x
):
...
@@ -403,6 +428,7 @@ def test_logs():
...
@@ -403,6 +428,7 @@ def test_logs():
# ---------------------------------------------------------------- do it
# ---------------------------------------------------------------- do it
test_division
()
test_division
()
test_karatsuba
()
test_bitop_identities
()
test_bitop_identities
()
test_format
()
test_format
()
test_misc
()
test_misc
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment