Skip to content

Commit cd16663

Browse files
committed
add tests for subscripting a memoized generator
1 parent 2f11241 commit cd16663

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

unpythonic/tests/test_gmemo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ def gen():
9292
fail["Should have raised at the second next() call."] # pragma: no cover
9393
test[total_evaluations == 2]
9494

95+
with testset("subscripting to get already computed items"):
96+
@gmemoize
97+
def gen():
98+
yield from range(5)
99+
g3 = gen()
100+
test[len(g3) == 0]
101+
next(g3)
102+
test[len(g3) == 1]
103+
next(g3)
104+
test[len(g3) == 2]
105+
next(g3)
106+
test[len(g3) == 3]
107+
test[g3[0] == 0]
108+
test[g3[1] == 1]
109+
test[g3[2] == 2]
110+
test_raises[IndexError, g3[3]]
111+
95112
with testset("memoizing a sequence partially"):
96113
# To do this, build a chain of generators, then memoize only the last one:
97114
evaluations = Counter()

0 commit comments

Comments
 (0)