package test.leecode.linkedlist; import org.junit.Assert; import org.junit.Test; import cn.fansunion.leecode.linkedlist.MergeSortedArray; /** * @author wen.lei@brgroup.com * * 2022-2-23 */ public class MergeSortedArrayTest @Test public void test() MergeSortedArray test = new MergeSortedArray(); // test2 int [] nums3 = new int [] 2 , 3 , 5 , 0 , 0 , 0 , 0 , 0 ; int [] nums4 = new int [] 1 , 4 , 5 , 6 , 9 ; test.merge(nums3, 3 , nums4, 5 ); Assert.assertArrayEquals( new int [] 1 , 2 , 3 , 4 , 5 , 5 , 6 , 9 , nums3); // test1 int [] nums1 = new int [] 1 , 2 , 3 , 0 , 0 , 0 ; int [] nums2 = new int [] 2 , 5 , 6 ; test.merge(nums1, 3 , nums2, 3 ); Assert.assertArrayEquals( new int [] 1 , 2 , 2 , 3 , 5 , 6 , nums1); // test3 int [] nums5 = new int [] 3 , 3 , 3 , 3 , 0 , 0 , 0 , 0 ; int [] nums6 = new int [] 1 , 1 , 2 , 2 ; test.merge(nums5, 4 , nums6, 4 ); Assert.assertArrayEquals( new int [] 1 , 1 , 2 , 2 , 3 , 3 , 3 , 3 , nums5); // test4 int [] nums7 = new int [] 1 , 1 , 2 , 3 , 0 , 0 , 0 , 0 ; int [] nums8 = new int [] 4 , 5 , 6 , 7 ; test.merge(nums7, 4 , nums8, 4 ); Assert.assertArrayEquals( new int [] 1 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , nums7);
@Test public void testMergeWithReturn() MergeSortedArray test = new MergeSortedArray(); // test2 int [] nums3 = new int [] 2 , 3 , 5 ; int [] nums4 = new int [] 1 , 4 , 5 , 6 , 9 ; int [] test2 = test.mergeWithReturn(nums3, nums4); Assert.assertArrayEquals( new int [] 1 , 2 , 3 , 4 , 5 , 5 , 6 , 9 , test2); // test1 int [] nums1 = new int [] 1 , 2 , 3 ; int [] nums2 = new int [] 2 , 5 , 6 ; int [] test1 = test.mergeWithReturn(nums1, nums2); Assert.assertArrayEquals( new int [] 1 , 2 , 2 , 3 , 5 , 6 , test1); // test3 int [] nums5 = new int [] 3 , 3 , 3 , 3 ; int [] nums6 = new int [] 1 , 1 , 2 , 2 ; int [] test3 = test.mergeWithReturn(nums5, nums6); Assert.assertArrayEquals( new int [] 1 , 1 , 2 , 2 , 3 , 3 , 3 , 3 , test3); // test4 int [] nums7 = new int [] 1 , 1 , 2 , 3 ; int [] nums8 = new int [] 4 , 5 , 6 , 7 ; int [] test4 = test.mergeWithReturn(nums7, nums8); Assert.assertArrayEquals( new int [] 1 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , test4);
// mergeStupid public static void main(String[] args) // test1 int [] nums1 = new int [] 1 , 2 , 3 , 0 , 0 , 0 ; int [] nums2 = new int [] 2 , 5 , 6 ; MergeSortedArray msa = new MergeSortedArray(); msa.mergeStupidAndError(nums1, 3 , nums2, 3 ); for ( int num : nums1) System.out.print(num);
System.out.println(); // test2 int [] nums3 = new int [] 2 , 3 , 5 , 0 , 0 , 0 , 0 , 0 ; int [] nums4 = new int [] 1 , 4 , 5 , 6 , 9 ; MergeSortedArray msa2 = new MergeSortedArray(); msa2.mergeStupidAndError(nums3, 3 , nums4, 5 ); for ( int num : nums3) System.out.print(num);
|