|
| 1 | +import test from 'ava'; |
| 2 | +import {sorted, range, list, map} from '@aureooms/js-itertools'; |
| 3 | +import {shuffle, randrange} from '@aureooms/js-random'; |
| 4 | +import {increasing} from '@aureooms/js-compare'; |
| 5 | + |
| 6 | +import sortInt32 from '../../../src/array/api/sortInt32'; |
| 7 | + |
| 8 | +const macro = (t, data) => { |
| 9 | + const result = sortInt32(data.slice()); |
| 10 | + const expected = sorted(increasing, data); |
| 11 | + t.deepEqual(expected, result); |
| 12 | +}; |
| 13 | + |
| 14 | +const repr = (data) => |
| 15 | + data.length >= 20 |
| 16 | + ? `[${data.slice(0, 9)},..,${data.slice(-9)}]` |
| 17 | + : JSON.stringify(data); |
| 18 | + |
| 19 | +macro.title = (title, data) => title || `sortInt32(${repr(data)})`; |
| 20 | + |
| 21 | +test(macro, []); |
| 22 | +test(macro, [1, -2, -3, 4]); |
| 23 | + |
| 24 | +const N = 1 << 17; |
| 25 | +const longShuffledInput = list(range((-N / 2) | 0, (N / 2) | 0)); |
| 26 | +shuffle(longShuffledInput, 0, N); |
| 27 | +test(macro, longShuffledInput); |
| 28 | + |
| 29 | +const longRandomInput = list( |
| 30 | + map(() => randrange(-(2 ** 31), 2 ** 31), range(N)) |
| 31 | +); |
| 32 | +test(macro, longRandomInput); |
0 commit comments