Skip to content

Commit b87d9bc

Browse files
committed
Add tests for insertIntoSortedArray
1 parent 10deec3 commit b87d9bc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/sortutils.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

Comments
 (0)