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
2f6c2e03
Kaydet (Commit)
2f6c2e03
authored
Ock 27, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
More exhaustive combinatoric checks.
üst
ecf252ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
test_itertools.py
Lib/test/test_itertools.py
+28
-16
No files found.
Lib/test/test_itertools.py
Dosyayı görüntüle @
2f6c2e03
...
@@ -274,22 +274,34 @@ class TestBasicOps(unittest.TestCase):
...
@@ -274,22 +274,34 @@ class TestBasicOps(unittest.TestCase):
# Test relationships between product(), permutations(),
# Test relationships between product(), permutations(),
# combinations() and combinations_with_replacement().
# combinations() and combinations_with_replacement().
s
=
'ABCDE'
for
n
in
range
(
6
):
for
r
in
range
(
8
):
s
=
'ABCDEFG'
[:
n
]
prod
=
list
(
product
(
s
,
repeat
=
r
))
for
r
in
range
(
8
):
cwr
=
list
(
combinations_with_replacement
(
s
,
r
))
prod
=
list
(
product
(
s
,
repeat
=
r
))
perm
=
list
(
permutations
(
s
,
r
))
cwr
=
list
(
combinations_with_replacement
(
s
,
r
))
comb
=
list
(
combinations
(
s
,
r
))
perm
=
list
(
permutations
(
s
,
r
))
comb
=
list
(
combinations
(
s
,
r
))
self
.
assertEquals
(
len
(
prod
),
len
(
s
)
**
r
)
self
.
assertEquals
(
prod
,
sorted
(
set
(
prod
)))
# prod in lexicographic order without repeats
# Check size
self
.
assertEquals
(
cwr
,
[
t
for
t
in
prod
if
sorted
(
t
)
==
list
(
t
)])
# cwr: prods which are sorted
self
.
assertEquals
(
len
(
prod
),
n
**
r
)
self
.
assertEquals
(
perm
,
[
t
for
t
in
prod
if
len
(
set
(
t
))
==
r
])
# perm: prods with no dups
self
.
assertEquals
(
len
(
cwr
),
(
fact
(
n
+
r
-
1
)
/
fact
(
r
)
/
fact
(
n
-
1
))
if
n
else
(
not
r
))
self
.
assertEqual
(
comb
,
[
t
for
t
in
perm
if
sorted
(
t
)
==
list
(
t
)])
# comb: perms that are sorted
self
.
assertEquals
(
len
(
perm
),
0
if
r
>
n
else
fact
(
n
)
/
fact
(
n
-
r
))
self
.
assertEqual
(
comb
,
[
t
for
t
in
cwr
if
len
(
set
(
t
))
==
r
])
# comb: cwrs without dups
self
.
assertEquals
(
len
(
comb
),
0
if
r
>
n
else
fact
(
n
)
/
fact
(
r
)
/
fact
(
n
-
r
))
self
.
assertEqual
(
comb
,
filter
(
set
(
cwr
)
.
__contains__
,
perm
))
# comb: perm that is a cwr
self
.
assertEqual
(
comb
,
filter
(
set
(
perm
)
.
__contains__
,
cwr
))
# comb: cwr that is a perm
# Check lexicographic order without repeated tuples
self
.
assertEqual
(
comb
,
sorted
(
set
(
cwr
)
&
set
(
perm
)))
# comb: both a cwr and a perm
self
.
assertEquals
(
prod
,
sorted
(
set
(
prod
)))
self
.
assertEquals
(
cwr
,
sorted
(
set
(
cwr
)))
self
.
assertEquals
(
perm
,
sorted
(
set
(
perm
)))
self
.
assertEquals
(
comb
,
sorted
(
set
(
comb
)))
# Check interrelationships
self
.
assertEquals
(
cwr
,
[
t
for
t
in
prod
if
sorted
(
t
)
==
list
(
t
)])
# cwr: prods which are sorted
self
.
assertEquals
(
perm
,
[
t
for
t
in
prod
if
len
(
set
(
t
))
==
r
])
# perm: prods with no dups
self
.
assertEqual
(
comb
,
[
t
for
t
in
perm
if
sorted
(
t
)
==
list
(
t
)])
# comb: perms that are sorted
self
.
assertEqual
(
comb
,
[
t
for
t
in
cwr
if
len
(
set
(
t
))
==
r
])
# comb: cwrs without dups
self
.
assertEqual
(
comb
,
filter
(
set
(
cwr
)
.
__contains__
,
perm
))
# comb: perm that is a cwr
self
.
assertEqual
(
comb
,
filter
(
set
(
perm
)
.
__contains__
,
cwr
))
# comb: cwr that is a perm
self
.
assertEqual
(
comb
,
sorted
(
set
(
cwr
)
&
set
(
perm
)))
# comb: both a cwr and a perm
def
test_compress
(
self
):
def
test_compress
(
self
):
self
.
assertEqual
(
list
(
compress
(
'ABCDEF'
,
[
1
,
0
,
1
,
0
,
1
,
1
])),
list
(
'ACEF'
))
self
.
assertEqual
(
list
(
compress
(
'ABCDEF'
,
[
1
,
0
,
1
,
0
,
1
,
1
])),
list
(
'ACEF'
))
...
...
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