Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cbe16aef
Kaydet (Commit)
cbe16aef
authored
Eyl 25, 2015
tarafından
Martin Panter
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #25211: Eliminate lazy error message class by using subTest
Some of the calls to the Frm class were buggy anyway.
üst
52736ddc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
88 deletions
+72
-88
test_long.py
Lib/test/test_long.py
+72
-88
No files found.
Lib/test/test_long.py
Dosyayı görüntüle @
cbe16aef
...
@@ -7,15 +7,6 @@ import random
...
@@ -7,15 +7,6 @@ import random
import
math
import
math
import
array
import
array
# Used for lazy formatting of failure messages
class
Frm
(
object
):
def
__init__
(
self
,
format
,
*
args
):
self
.
format
=
format
self
.
args
=
args
def
__str__
(
self
):
return
self
.
format
%
self
.
args
# SHIFT should match the value in longintrepr.h for best testing.
# SHIFT should match the value in longintrepr.h for best testing.
SHIFT
=
sys
.
int_info
.
bits_per_digit
SHIFT
=
sys
.
int_info
.
bits_per_digit
BASE
=
2
**
SHIFT
BASE
=
2
**
SHIFT
...
@@ -163,17 +154,18 @@ class LongTest(unittest.TestCase):
...
@@ -163,17 +154,18 @@ class LongTest(unittest.TestCase):
def
check_division
(
self
,
x
,
y
):
def
check_division
(
self
,
x
,
y
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
q
,
r
=
divmod
(
x
,
y
)
with
self
.
subTest
(
x
=
x
,
y
=
y
):
q2
,
r2
=
x
//
y
,
x
%
y
q
,
r
=
divmod
(
x
,
y
)
pab
,
pba
=
x
*
y
,
y
*
x
q2
,
r2
=
x
//
y
,
x
%
y
eq
(
pab
,
pba
,
Frm
(
"multiplication does not commute for
%
r and
%
r"
,
x
,
y
))
pab
,
pba
=
x
*
y
,
y
*
x
eq
(
q
,
q2
,
Frm
(
"divmod returns different quotient than / for
%
r and
%
r"
,
x
,
y
))
eq
(
pab
,
pba
,
"multiplication does not commute"
)
eq
(
r
,
r2
,
Frm
(
"divmod returns different mod than
%%
for
%
r and
%
r"
,
x
,
y
))
eq
(
q
,
q2
,
"divmod returns different quotient than /"
)
eq
(
x
,
q
*
y
+
r
,
Frm
(
"x != q*y + r after divmod on x=
%
r, y=
%
r"
,
x
,
y
))
eq
(
r
,
r2
,
"divmod returns different mod than
%
"
)
if
y
>
0
:
eq
(
x
,
q
*
y
+
r
,
"x != q*y + r after divmod"
)
self
.
assertTrue
(
0
<=
r
<
y
,
Frm
(
"bad mod from divmod on
%
r and
%
r"
,
x
,
y
))
if
y
>
0
:
else
:
self
.
assertTrue
(
0
<=
r
<
y
,
"bad mod from divmod"
)
self
.
assertTrue
(
y
<
r
<=
0
,
Frm
(
"bad mod from divmod on
%
r and
%
r"
,
x
,
y
))
else
:
self
.
assertTrue
(
y
<
r
<=
0
,
"bad mod from divmod"
)
def
test_division
(
self
):
def
test_division
(
self
):
digits
=
list
(
range
(
1
,
MAXDIGITS
+
1
))
+
list
(
range
(
KARATSUBA_CUTOFF
,
digits
=
list
(
range
(
1
,
MAXDIGITS
+
1
))
+
list
(
range
(
KARATSUBA_CUTOFF
,
...
@@ -228,72 +220,63 @@ class LongTest(unittest.TestCase):
...
@@ -228,72 +220,63 @@ class LongTest(unittest.TestCase):
for
bbits
in
bits
:
for
bbits
in
bits
:
if
bbits
<
abits
:
if
bbits
<
abits
:
continue
continue
b
=
(
1
<<
bbits
)
-
1
with
self
.
subTest
(
abits
=
abits
,
bbits
=
bbits
):
x
=
a
*
b
b
=
(
1
<<
bbits
)
-
1
y
=
((
1
<<
(
abits
+
bbits
))
-
x
=
a
*
b
(
1
<<
abits
)
-
y
=
((
1
<<
(
abits
+
bbits
)
)
-
(
1
<<
bbits
)
+
(
1
<<
abits
)
-
1
)
(
1
<<
bbits
)
+
self
.
assertEqual
(
x
,
y
,
1
)
Frm
(
"bad result for a*b: a=
%
r, b=
%
r, x=
%
r, y=
%
r"
,
a
,
b
,
x
,
y
)
)
self
.
assertEqual
(
x
,
y
)
def
check_bitop_identities_1
(
self
,
x
):
def
check_bitop_identities_1
(
self
,
x
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
eq
(
x
&
0
,
0
,
Frm
(
"x & 0 != 0 for x=
%
r"
,
x
))
with
self
.
subTest
(
x
=
x
):
eq
(
x
|
0
,
x
,
Frm
(
"x | 0 != x for x=
%
r"
,
x
))
eq
(
x
&
0
,
0
)
eq
(
x
^
0
,
x
,
Frm
(
"x ^ 0 != x for x=
%
r"
,
x
))
eq
(
x
|
0
,
x
)
eq
(
x
&
-
1
,
x
,
Frm
(
"x & -1 != x for x=
%
r"
,
x
))
eq
(
x
^
0
,
x
)
eq
(
x
|
-
1
,
-
1
,
Frm
(
"x | -1 != -1 for x=
%
r"
,
x
))
eq
(
x
&
-
1
,
x
)
eq
(
x
^
-
1
,
~
x
,
Frm
(
"x ^ -1 != ~x for x=
%
r"
,
x
))
eq
(
x
|
-
1
,
-
1
)
eq
(
x
,
~~
x
,
Frm
(
"x != ~~x for x=
%
r"
,
x
))
eq
(
x
^
-
1
,
~
x
)
eq
(
x
&
x
,
x
,
Frm
(
"x & x != x for x=
%
r"
,
x
))
eq
(
x
,
~~
x
)
eq
(
x
|
x
,
x
,
Frm
(
"x | x != x for x=
%
r"
,
x
))
eq
(
x
&
x
,
x
)
eq
(
x
^
x
,
0
,
Frm
(
"x ^ x != 0 for x=
%
r"
,
x
))
eq
(
x
|
x
,
x
)
eq
(
x
&
~
x
,
0
,
Frm
(
"x & ~x != 0 for x=
%
r"
,
x
))
eq
(
x
^
x
,
0
)
eq
(
x
|
~
x
,
-
1
,
Frm
(
"x | ~x != -1 for x=
%
r"
,
x
))
eq
(
x
&
~
x
,
0
)
eq
(
x
^
~
x
,
-
1
,
Frm
(
"x ^ ~x != -1 for x=
%
r"
,
x
))
eq
(
x
|
~
x
,
-
1
)
eq
(
-
x
,
1
+
~
x
,
Frm
(
"not -x == 1 + ~x for x=
%
r"
,
x
))
eq
(
x
^
~
x
,
-
1
)
eq
(
-
x
,
~
(
x
-
1
),
Frm
(
"not -x == ~(x-1) forx =
%
r"
,
x
))
eq
(
-
x
,
1
+
~
x
)
eq
(
-
x
,
~
(
x
-
1
))
for
n
in
range
(
2
*
SHIFT
):
for
n
in
range
(
2
*
SHIFT
):
p2
=
2
**
n
p2
=
2
**
n
eq
(
x
<<
n
>>
n
,
x
,
with
self
.
subTest
(
x
=
x
,
n
=
n
,
p2
=
p2
):
Frm
(
"x << n >> n != x for x=
%
r, n=
%
r"
,
(
x
,
n
)))
eq
(
x
<<
n
>>
n
,
x
)
eq
(
x
//
p2
,
x
>>
n
,
eq
(
x
//
p2
,
x
>>
n
)
Frm
(
"x // p2 != x >> n for x=
%
r n=
%
r p2=
%
r"
,
(
x
,
n
,
p2
)))
eq
(
x
*
p2
,
x
<<
n
)
eq
(
x
*
p2
,
x
<<
n
,
eq
(
x
&
-
p2
,
x
>>
n
<<
n
)
Frm
(
"x * p2 != x << n for x=
%
r n=
%
r p2=
%
r"
,
(
x
,
n
,
p2
)))
eq
(
x
&
-
p2
,
x
&
~
(
p2
-
1
))
eq
(
x
&
-
p2
,
x
>>
n
<<
n
,
Frm
(
"not x & -p2 == x >> n << n for x=
%
r n=
%
r p2=
%
r"
,
(
x
,
n
,
p2
)))
eq
(
x
&
-
p2
,
x
&
~
(
p2
-
1
),
Frm
(
"not x & -p2 == x & ~(p2 - 1) for x=
%
r n=
%
r p2=
%
r"
,
(
x
,
n
,
p2
)))
def
check_bitop_identities_2
(
self
,
x
,
y
):
def
check_bitop_identities_2
(
self
,
x
,
y
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
eq
(
x
&
y
,
y
&
x
,
Frm
(
"x & y != y & x for x=
%
r, y=
%
r"
,
(
x
,
y
)))
with
self
.
subTest
(
x
=
x
,
y
=
y
):
eq
(
x
|
y
,
y
|
x
,
Frm
(
"x | y != y | x for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
&
y
,
y
&
x
)
eq
(
x
^
y
,
y
^
x
,
Frm
(
"x ^ y != y ^ x for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
|
y
,
y
|
x
)
eq
(
x
^
y
^
x
,
y
,
Frm
(
"x ^ y ^ x != y for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
^
y
,
y
^
x
)
eq
(
x
&
y
,
~
(
~
x
|
~
y
),
Frm
(
"x & y != ~(~x | ~y) for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
^
y
^
x
,
y
)
eq
(
x
|
y
,
~
(
~
x
&
~
y
),
Frm
(
"x | y != ~(~x & ~y) for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
&
y
,
~
(
~
x
|
~
y
))
eq
(
x
^
y
,
(
x
|
y
)
&
~
(
x
&
y
),
eq
(
x
|
y
,
~
(
~
x
&
~
y
))
Frm
(
"x ^ y != (x | y) & ~(x & y) for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
^
y
,
(
x
|
y
)
&
~
(
x
&
y
))
eq
(
x
^
y
,
(
x
&
~
y
)
|
(
~
x
&
y
),
eq
(
x
^
y
,
(
x
&
~
y
)
|
(
~
x
&
y
))
Frm
(
"x ^ y == (x & ~y) | (~x & y) for x=
%
r, y=
%
r"
,
(
x
,
y
)))
eq
(
x
^
y
,
(
x
|
y
)
&
(
~
x
|
~
y
))
eq
(
x
^
y
,
(
x
|
y
)
&
(
~
x
|
~
y
),
Frm
(
"x ^ y == (x | y) & (~x | ~y) for x=
%
r, y=
%
r"
,
(
x
,
y
)))
def
check_bitop_identities_3
(
self
,
x
,
y
,
z
):
def
check_bitop_identities_3
(
self
,
x
,
y
,
z
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
eq
((
x
&
y
)
&
z
,
x
&
(
y
&
z
),
with
self
.
subTest
(
x
=
x
,
y
=
y
,
z
=
z
):
Frm
(
"(x & y) & z != x & (y & z) for x=
%
r, y=
%
r, z=
%
r"
,
(
x
,
y
,
z
)))
eq
((
x
&
y
)
&
z
,
x
&
(
y
&
z
))
eq
((
x
|
y
)
|
z
,
x
|
(
y
|
z
),
eq
((
x
|
y
)
|
z
,
x
|
(
y
|
z
))
Frm
(
"(x | y) | z != x | (y | z) for x=
%
r, y=
%
r, z=
%
r"
,
(
x
,
y
,
z
)))
eq
((
x
^
y
)
^
z
,
x
^
(
y
^
z
))
eq
((
x
^
y
)
^
z
,
x
^
(
y
^
z
),
eq
(
x
&
(
y
|
z
),
(
x
&
y
)
|
(
x
&
z
))
Frm
(
"(x ^ y) ^ z != x ^ (y ^ z) for x=
%
r, y=
%
r, z=
%
r"
,
(
x
,
y
,
z
)))
eq
(
x
|
(
y
&
z
),
(
x
|
y
)
&
(
x
|
z
))
eq
(
x
&
(
y
|
z
),
(
x
&
y
)
|
(
x
&
z
),
Frm
(
"x & (y | z) != (x & y) | (x & z) for x=
%
r, y=
%
r, z=
%
r"
,
(
x
,
y
,
z
)))
eq
(
x
|
(
y
&
z
),
(
x
|
y
)
&
(
x
|
z
),
Frm
(
"x | (y & z) != (x | y) & (x | z) for x=
%
r, y=
%
r, z=
%
r"
,
(
x
,
y
,
z
)))
def
test_bitop_identities
(
self
):
def
test_bitop_identities
(
self
):
for
x
in
special
:
for
x
in
special
:
...
@@ -324,11 +307,11 @@ class LongTest(unittest.TestCase):
...
@@ -324,11 +307,11 @@ class LongTest(unittest.TestCase):
def
check_format_1
(
self
,
x
):
def
check_format_1
(
self
,
x
):
for
base
,
mapper
in
(
2
,
bin
),
(
8
,
oct
),
(
10
,
str
),
(
10
,
repr
),
(
16
,
hex
):
for
base
,
mapper
in
(
2
,
bin
),
(
8
,
oct
),
(
10
,
str
),
(
10
,
repr
),
(
16
,
hex
):
got
=
mapper
(
x
)
got
=
mapper
(
x
)
expected
=
self
.
slow_format
(
x
,
base
)
with
self
.
subTest
(
x
=
x
,
mapper
=
mapper
.
__name__
):
msg
=
Frm
(
"
%
s returned
%
r but expected
%
r for
%
r"
,
expected
=
self
.
slow_format
(
x
,
base
)
mapper
.
__name__
,
got
,
expected
,
x
)
self
.
assertEqual
(
got
,
expected
)
self
.
assertEqual
(
got
,
expected
,
msg
)
with
self
.
subTest
(
got
=
got
):
self
.
assertEqual
(
int
(
got
,
0
),
x
,
Frm
(
'int("
%
s", 0) !=
%
r'
,
got
,
x
)
)
self
.
assertEqual
(
int
(
got
,
0
),
x
)
def
test_format
(
self
):
def
test_format
(
self
):
for
x
in
special
:
for
x
in
special
:
...
@@ -627,14 +610,15 @@ class LongTest(unittest.TestCase):
...
@@ -627,14 +610,15 @@ class LongTest(unittest.TestCase):
for
y
in
cases
:
for
y
in
cases
:
Ry
=
Rat
(
y
)
Ry
=
Rat
(
y
)
Rcmp
=
(
Rx
>
Ry
)
-
(
Rx
<
Ry
)
Rcmp
=
(
Rx
>
Ry
)
-
(
Rx
<
Ry
)
xycmp
=
(
x
>
y
)
-
(
x
<
y
)
with
self
.
subTest
(
x
=
x
,
y
=
y
,
Rcmp
=
Rcmp
):
eq
(
Rcmp
,
xycmp
,
Frm
(
"
%
r
%
r
%
d
%
d"
,
x
,
y
,
Rcmp
,
xycmp
))
xycmp
=
(
x
>
y
)
-
(
x
<
y
)
eq
(
x
==
y
,
Rcmp
==
0
,
Frm
(
"
%
r ==
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
Rcmp
,
xycmp
)
eq
(
x
!=
y
,
Rcmp
!=
0
,
Frm
(
"
%
r !=
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
x
==
y
,
Rcmp
==
0
)
eq
(
x
<
y
,
Rcmp
<
0
,
Frm
(
"
%
r <
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
x
!=
y
,
Rcmp
!=
0
)
eq
(
x
<=
y
,
Rcmp
<=
0
,
Frm
(
"
%
r <=
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
x
<
y
,
Rcmp
<
0
)
eq
(
x
>
y
,
Rcmp
>
0
,
Frm
(
"
%
r >
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
x
<=
y
,
Rcmp
<=
0
)
eq
(
x
>=
y
,
Rcmp
>=
0
,
Frm
(
"
%
r >=
%
r
%
d"
,
x
,
y
,
Rcmp
))
eq
(
x
>
y
,
Rcmp
>
0
)
eq
(
x
>=
y
,
Rcmp
>=
0
)
def
test__format__
(
self
):
def
test__format__
(
self
):
self
.
assertEqual
(
format
(
123456789
,
'd'
),
'123456789'
)
self
.
assertEqual
(
format
(
123456789
,
'd'
),
'123456789'
)
...
...
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