|
4 | 4 | from functools import partial |
5 | 5 | from random import Random |
6 | 6 | from pickle import dumps, loads |
7 | | -from toolz.itertoolz import (remove, groupby, merge_sorted, |
| 7 | +from toolz.itertoolz import (remove, groupby, indices, merge_sorted, |
8 | 8 | concat, concatv, interleave, unique, |
9 | 9 | isiterable, getter, |
10 | 10 | mapcat, isdistinct, first, second, |
@@ -52,6 +52,31 @@ def test_groupby(): |
52 | 52 | assert groupby(iseven, [1, 2, 3, 4]) == {True: [2, 4], False: [1, 3]} |
53 | 53 |
|
54 | 54 |
|
| 55 | +def test_indices(): |
| 56 | + assert list(indices(0)) == [] |
| 57 | + assert list(indices(0, 5)) == [] |
| 58 | + assert list(indices(5, 0)) == [] |
| 59 | + |
| 60 | + assert list(indices(5)) == [(0,), |
| 61 | + (1,), |
| 62 | + (2,), |
| 63 | + (3,), |
| 64 | + (4,)] |
| 65 | + |
| 66 | + assert list(indices(1, 5)) == [(0, 0,), |
| 67 | + (0, 1,), |
| 68 | + (0, 2,), |
| 69 | + (0, 3,), |
| 70 | + (0, 4,)] |
| 71 | + |
| 72 | + assert list(indices(3, 2)) == [(0, 0), |
| 73 | + (0, 1), |
| 74 | + (1, 0), |
| 75 | + (1, 1), |
| 76 | + (2, 0), |
| 77 | + (2, 1)] |
| 78 | + |
| 79 | + |
55 | 80 | def test_groupby_non_callable(): |
56 | 81 | assert groupby(0, [(1, 2), (1, 3), (2, 2), (2, 4)]) == \ |
57 | 82 | {1: [(1, 2), (1, 3)], |
|
0 commit comments