BAEL-3399: How to merge two sorted arrays into a sorted array
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.algorithms.sortedarrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SortedArraysUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTwoSortedArraysWhenMergeThenReturnMergedSortedArray() {
|
||||
|
||||
int[] first = { 3, 7 };
|
||||
int[] second = { 4, 8, 11 };
|
||||
int[] result = { 3, 4, 7, 8, 11 };
|
||||
|
||||
assertArrayEquals(result, SortedArrays.merge(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSortedArraysWithDuplicatesWhenMergeThenReturnMergedSortedArray() {
|
||||
|
||||
int[] first = { 3, 3, 7 };
|
||||
int[] second = { 4, 8, 8, 11 };
|
||||
int[] result = { 3, 3, 4, 7, 8, 8, 11 };
|
||||
|
||||
assertArrayEquals(result, SortedArrays.merge(first, second));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user