Skip to content

Commit 835bb2f

Browse files
author
Noel Roemmele
committed
Fixed case where S = [] and k = 0. Also added doctest to make sure behaviour has been corrected.
1 parent 1711cdc commit 835bb2f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/sage/combinat/tuple.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ def unrank(self, i):
194194
...
195195
IndexError: index i (=1) is greater than or equal to the cardinality
196196
197+
Verify that :meth:`unrank` gives the correct answer when `|S| < 1` and
198+
`k = 0`::
199+
200+
sage: T = Tuples(range(0), 0)
201+
sage: T[0]
202+
()
203+
sage: T[-1]
204+
()
205+
sage: T[1]
206+
Traceback (most recent call last):
207+
...
208+
IndexError: index i (=1) is greater than or equal to the cardinality
209+
197210
Verify that :issue:`39534` has been fixed::
198211
199212
sage: T = Tuples(range(3), 30).random_element()
@@ -209,7 +222,7 @@ def unrank(self, i):
209222
raise IndexError("index i (={}) is greater than or equal to the cardinality"
210223
.format(i))
211224
ts = len(self.S)
212-
if ts == 1:
225+
if ts <= 1:
213226
return tuple(self.S[0] for _ in range(self.k))
214227
return tuple(i.digits(ts, self.S, self.k))
215228

0 commit comments

Comments
 (0)