mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
85 lines
1.4 KiB
Python
85 lines
1.4 KiB
Python
import itertools
|
|
|
|
from testutils import assertRaises
|
|
|
|
|
|
# itertools.count tests
|
|
|
|
# default arguments
|
|
c = itertools.count()
|
|
assert next(c) == 0
|
|
assert next(c) == 1
|
|
assert next(c) == 2
|
|
|
|
# positional
|
|
c = itertools.count(2, 3)
|
|
assert next(c) == 2
|
|
assert next(c) == 5
|
|
assert next(c) == 8
|
|
|
|
# backwards
|
|
c = itertools.count(1, -10)
|
|
assert next(c) == 1
|
|
assert next(c) == -9
|
|
assert next(c) == -19
|
|
|
|
# step = 0
|
|
c = itertools.count(5, 0)
|
|
assert next(c) == 5
|
|
assert next(c) == 5
|
|
|
|
# itertools.count TODOs: kwargs and floats
|
|
|
|
# step kwarg
|
|
# c = itertools.count(step=5)
|
|
# assert next(c) == 0
|
|
# assert next(c) == 5
|
|
|
|
# start kwarg
|
|
# c = itertools.count(start=10)
|
|
# assert next(c) == 10
|
|
|
|
# float start
|
|
# c = itertools.count(0.5)
|
|
# assert next(c) == 0.5
|
|
# assert next(c) == 1.5
|
|
# assert next(c) == 2.5
|
|
|
|
# float step
|
|
# c = itertools.count(1, 0.5)
|
|
# assert next(c) == 1
|
|
# assert next(c) == 1.5
|
|
# assert next(c) == 2
|
|
|
|
# float start + step
|
|
# c = itertools.count(0.5, 0.5)
|
|
# assert next(c) == 0.5
|
|
# assert next(c) == 1
|
|
# assert next(c) == 1.5
|
|
|
|
|
|
# itertools.repeat tests
|
|
|
|
# no times
|
|
r = itertools.repeat(5)
|
|
assert next(r) == 5
|
|
assert next(r) == 5
|
|
assert next(r) == 5
|
|
|
|
# times
|
|
r = itertools.repeat(1, 2)
|
|
assert next(r) == 1
|
|
assert next(r) == 1
|
|
with assertRaises(StopIteration):
|
|
next(r)
|
|
|
|
# timees = 0
|
|
r = itertools.repeat(1, 0)
|
|
with assertRaises(StopIteration):
|
|
next(r)
|
|
|
|
# negative times
|
|
r = itertools.repeat(1, -1)
|
|
with assertRaises(StopIteration):
|
|
next(r)
|