|
| 1 | +import * as assert from 'assert'; |
| 2 | +import { describe, it } from 'mocha'; |
| 3 | +import { insertIntoSortedArray } from '../src/sortutils'; |
| 4 | + |
| 5 | +describe('insertIntoSortedArray', () => { |
| 6 | + it('insert 1 into []', testList([], 1, [1])); |
| 7 | + |
| 8 | + it('insert 2 into [1]', testList([1], 2, [1, 2])); |
| 9 | + |
| 10 | + it('insert 1 into [2]', testList([2], 1, [1, 2])); |
| 11 | + |
| 12 | + it('insert 3 into [1, 2]', testList([1, 2], 3, [1, 2, 3])); |
| 13 | + |
| 14 | + it('insert 2 into [1, 3]', testList([1, 3], 2, [1, 2, 3])); |
| 15 | + |
| 16 | + it('insert 1 into [2, 3]', testList([2, 3], 1, [1, 2, 3])); |
| 17 | + |
| 18 | + it('insert 2 into [1, 2, 3]', testList([1, 2, 3], 2, [1, 2, 2, 3])); |
| 19 | +}); |
| 20 | + |
| 21 | +function testList(input: number[], insert: number, expected: number[]) { |
| 22 | + return () => { |
| 23 | + const compare = (a: number, b: number) => a - b; |
| 24 | + insertIntoSortedArray(input, insert, compare); |
| 25 | + assert.deepEqual(input, expected); |
| 26 | + }; |
| 27 | +} |
0 commit comments