fixed error message in debase
This commit is contained in:
@@ -268,12 +268,13 @@ def debase(num: int, base: tuple[int, ...], strict: bool = True) -> tuple[int, .
|
|||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
indices = []
|
indices = []
|
||||||
|
orig_num = num
|
||||||
for i in range(len(base) - 1):
|
for i in range(len(base) - 1):
|
||||||
ind, num = divmod(num, np.prod(base[i + 1 :]))
|
ind, num = divmod(num, np.prod(base[i + 1 :]))
|
||||||
indices.append(ind)
|
indices.append(ind)
|
||||||
indices.append(num)
|
indices.append(num)
|
||||||
if strict and indices[0] >= base[0]:
|
if strict and indices[0] >= base[0]:
|
||||||
raise ValueError(f"{num} too big for base {base!r} in strict mode")
|
raise ValueError(f"{orig_num} too big for base {base!r} in strict mode")
|
||||||
return tuple(indices)
|
return tuple(indices)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ def test_debase():
|
|||||||
debase(785, (5, 1, 6))
|
debase(785, (5, 1, 6))
|
||||||
assert debase(785, (5, 1, 6), strict=False) == (130, 0, 5)
|
assert debase(785, (5, 1, 6), strict=False) == (130, 0, 5)
|
||||||
|
|
||||||
|
assert debase(0, (1, 1, 1), strict=True) == (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_get_sequence():
|
def test_get_sequence():
|
||||||
s = get_sequence([[0, 0, 20]])
|
s = get_sequence([[0, 0, 20]])
|
||||||
|
|||||||
Reference in New Issue
Block a user