-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMergeSortedArrayTest.java
More file actions
41 lines (30 loc) · 1.42 KB
/
MergeSortedArrayTest.java
File metadata and controls
41 lines (30 loc) · 1.42 KB
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
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
public class MergeSortedArrayTest {
@Test
public void testMerge() {
MergeSortedArray msa = new MergeSortedArray();
int[] array0 = new int[]{1};
msa.merge(array0, 1, new int[]{}, 0);
Assert.assertTrue(Arrays.equals(array0, new int[]{1}));
int[] array1 = new int[]{0};
msa.merge(array1, 0, new int[]{1}, 1);
Assert.assertTrue(Arrays.equals(array1, new int[]{1}));
int[] array2 = new int[]{4, 5, 6, 0, 0, 0};
msa.merge(array2, 3, new int[]{1, 2, 3}, 3);
Assert.assertTrue(Arrays.equals(array2, new int[]{1, 2, 3, 4, 5, 6}));
int[] array3 = new int[]{0, 0, 0, 1, 2, 3, -1, -1, -1};
msa.merge(array3, 6, new int[]{0, 4}, 2);
Assert.assertTrue(Arrays.equals(array3, new int[]{0, 0, 0, 0, 1, 2, 3, 4, -1}));
int[] array4 = new int[]{0, 1, 2, 3, 0, 0, 0, 0, 0};
msa.merge(array4, 4, new int[]{3, 4, 0}, 2);
Assert.assertTrue(Arrays.equals(array4, new int[]{0, 1, 2, 3, 3, 4, 0, 0, 0}));
int[] array5 = new int[]{1, 2, 0, 0};
msa.merge(array5, 2, new int[]{1}, 1);
Assert.assertTrue(Arrays.equals(array5, new int[]{1, 1, 2, 0}));
int[] array6 = new int[]{1, 2, 3, 0, 0, 0};
msa.merge(array6, 3, new int[]{2, 5, 6}, 3);
Assert.assertTrue(Arrays.equals(array6, new int[]{1, 2, 2, 3, 5, 6}));
}
}