public void Given_two_sorted_array_when_merge_then_should_be_merged_as_one_sorted_array()
        {
            var solution = new MergeSortedArray();

            solution.Merge(_numbersFirst, 5, _numbersSecond, 4);
            Assert.Equal(_numbersFirst, _expected);
        }
示例#2
0
 void InternalTest(int[] n1, int m, int[] n2, int n, int[] expected)
 {
     MergeSortedArray.Merge(n1, m, n2, n);
     Assert.Equal <int>(expected.Length, n1.Length);
     for (int i = 0; i < n1.Length; i++)
     {
         Assert.Equal <int>(expected[i], n1[i]);
     }
 }
示例#3
0
        public void TestMergeSortedArray()
        {
            var a1 = new[] { 1, 2, 3, 0, 0, 0 };
            var a2 = new[] { 2, 5, 6 };

            MergeSortedArray.Merge(a1, 3, a2, 3);
            Assert.AreEqual(a1[4], 5);
            Assert.AreEqual(a1[0], 1);
        }
示例#4
0
        public void MergeSortedArrayTestCase2()
        {
            var nums1 = new[] { 1 };
            var m     = 1;
            var nums2 = new int[] {};
            var n     = 0;

            MergeSortedArray.Merge(nums1, m, nums2, n);
            nums1.Should().ContainInOrder(new [] { 1 });
        }
示例#5
0
        public void MergeSortedArrayTestCase1()
        {
            var nums1 = new[] { 1, 2, 3, 0, 0, 0 };
            var m     = 3;
            var nums2 = new[] { 2, 5, 6 };
            var n     = 3;

            MergeSortedArray.Merge(nums1, m, nums2, n);
            nums1.Should().ContainInOrder(new [] { 1, 2, 2, 3, 5, 6 });
        }
示例#6
0
        public void MergeTests()
        {
            MergeSortedArray obj = new MergeSortedArray();

            var arr  = new int[] { 1, 2, 3, 0, 0, 0 };
            var arr1 = new int[] { 2, 5, 6 };

            obj.Merge(arr, 3, arr1, 3);//[1,2,2,3,5,6]

            arr  = new int[] { 0 };
            arr1 = new int[] { 1 };
            obj.Merge(arr, 0, arr1, 1);//[1,2,2,3,5,6]

            arr  = new int[] { };
            arr1 = new int[] { };
            obj.Merge(arr, 0, arr1, 0);

            arr  = new int[] { 1, 2, 3 };
            arr1 = new int[] { };
            obj.Merge(arr, 0, arr1, 0);
        }
示例#7
0
        public void Example()
        {
            // Given
            var nums1 = new[] { 1, 2, 3, 0, 0, 0 };
            var m     = 3;
            var nums2 = new[] { 2, 5, 6 };
            var n     = 3;

            // When
            _sut.Merge(nums1, m, nums2, n);

            // Then
            var expected = new[] { 1, 2, 2, 3, 5, 6 };

            nums1.Should().BeEquivalentTo(expected);
        }
示例#8
0
 public void Merge(int[] nums1, int m, int[] nums2, int n, int[] expected)
 {
     _sut.Merge(nums1, m, nums2, n);
     Assert.AreEqual(expected, nums1);
 }