-
Notifications
You must be signed in to change notification settings - Fork 269
/
Copy pathmerge-two-sorted-arrays.test.js
45 lines (41 loc) · 1.63 KB
/
merge-two-sorted-arrays.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { mergeTwoSortedArrays, mergeTwoSortedArrays2 } = require('.');
describe('Merge Two Sorted Array which are already in ascending order ', () => {
let array1 = [];
let array2 = [];
describe('When array[i]-array[j] = 1 where i>j & j>=0', () => {
beforeEach(() => {
array1 = [1, 2, 3, 4, 5];
array2 = [6, 7, 8];
});
it('Merge two sort array with complexity O(n+m)', () => {
expect(mergeTwoSortedArrays(array1, array2)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('Merge two sort array with complexity O(nlogn)', () => {
expect(mergeTwoSortedArrays2(array1, array2)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
});
});
describe('When array[i]-array[j] => 1 where i>j & j>=0', () => {
beforeEach(() => {
array1 = [1, 3, 5, 6, 98, 100];
array2 = [2, 4, 99];
});
it('Merge two sort array with complexity O(n+m)', () => {
expect(mergeTwoSortedArrays(array1, array2)).toEqual([1, 2, 3, 4, 5, 6, 98, 99, 100]);
});
it('Merge two sort array with complexity O(nlogn)', () => {
expect(mergeTwoSortedArrays2(array1, array2)).toEqual([1, 2, 3, 4, 5, 6, 98, 99, 100]);
});
});
describe('When array[i]-array[j] <= 1 where i>j & j>=0', () => {
beforeEach(() => {
array1 = [1, 1, 5, 6, 98, 100];
array2 = [4, 4, 99];
});
it('Merge two sort array with complexity O(n+m)', () => {
expect(mergeTwoSortedArrays(array1, array2)).toEqual([1, 1, 4, 4, 5, 6, 98, 99, 100]);
});
it('Merge two sort array with complexity O(nlogn)', () => {
expect(mergeTwoSortedArrays2(array1, array2)).toEqual([1, 1, 4, 4, 5, 6, 98, 99, 100]);
});
});
});