|
| 1 | +import test from 'ava'; |
| 2 | + |
| 3 | +import {list} from '@iterable-iterator/list'; |
| 4 | +import {range} from '@iterable-iterator/range'; |
| 5 | +import {combinations} from '../../src/index.js'; |
| 6 | + |
| 7 | +const repr = (x) => (Array.isArray(x) ? JSON.stringify(x) : x); |
| 8 | + |
| 9 | +const macro = (t, iterable, r, expected) => { |
| 10 | + t.deepEqual(list(combinations(iterable, r)), expected); |
| 11 | +}; |
| 12 | + |
| 13 | +macro.title = (title, iterable, r, expected) => |
| 14 | + title ?? `combinations(${repr(iterable)}, ${r}) is ${repr(expected)}`; |
| 15 | + |
| 16 | +test(macro, 'ABCD', 2, [ |
| 17 | + ['A', 'B'], |
| 18 | + ['A', 'C'], |
| 19 | + ['A', 'D'], |
| 20 | + ['B', 'C'], |
| 21 | + ['B', 'D'], |
| 22 | + ['C', 'D'], |
| 23 | +]); |
| 24 | + |
| 25 | +test(macro, range(0, 4, 1), 3, [ |
| 26 | + [0, 1, 2], |
| 27 | + [0, 1, 3], |
| 28 | + [0, 2, 3], |
| 29 | + [1, 2, 3], |
| 30 | +]); |
| 31 | + |
| 32 | +test(macro, range(0, 4, 1), 4, [[0, 1, 2, 3]]); |
| 33 | +test(macro, range(0, 4, 1), 5, []); |
| 34 | +test(macro, range(0, 4, 1), 0, [[]]); |
| 35 | +test(macro, range(0, 0, 1), 0, [[]]); |
| 36 | +test(macro, range(0, 0, 1), 1, []); |
0 commit comments