public void MergeTwoLists_BothEmpty_ShouldMerge()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>(),
                new List <int>());

            result.Should().NotBeNull();
        }
        public void MergeTwoLists_Nulls_ShouldThrow()
        {
            Action action = () =>
            {
                MergeTwoSortedLists.Merge(null, null);
            };

            action.Should().Throw <ArgumentNullException>();
        }
        public void MergeTwoLists_SecondNull_ShouldThrow()
        {
            Action action = () =>
            {
                MergeTwoSortedLists.Merge(
                    null,
                    new List <int>());
            };

            action.Should().Throw <ArgumentNullException>();
        }
        public void MergeTwoLists_SecondEmpty_ShouldMerge()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                1
            },
                new List <int>());

            result.Should().HaveCount(1);
            result[0].Should().Be(1);
        }
Example #5
0
        public void MergeTwoSortedArraysTest()
        {
            int[] arr1 =
            {
                -2120996231,
                -1712935037, -1703673711, -1646095928, -1626097495, -1615680386, -1597131699, -1570326789, -1523090300,
                -1505782987, -1475588920, -1413239376, -1406129179, -1400568380, -1268858441, -1249391611, -1246083490,
                -1146477631, -1083291644, -1073939103, -1043077206, -1041739357, -1036731760, -1033272347,  -970190212,
                -937576457,   -865905850,  -813031026,  -771745552,  -765507965,  -733255990,  -706572903,  -667937720,
                -628689890,   -597415519,  -582800000,  -571329269,  -535481901,  -435616485,  -411950692,  -325996333,
                -303740798,   -193260330,  -191136906,  -172604141,  -145592722,   -51880142,   -25937243,   -18881257,
                -9780,             -9540,       -9490,       -8980,       -8856,       -8753,       -8455,       -8390,-8328, -7929, -7772, -7423, -7412, -7224, -7208,
                46412230, 46920758
            };

            int[] arr2 =
            {
                -2120996231, -2039897248, -2004579200, -1976555129, -1974066388, -1881537032, -1807815184, -1730567509,
                -6992,             -6827,       -6731,       -6138,       -5751,       -5676,       -5483,       -5354, -5217, -5177, -5036, -4710, -4697, -4694, -4641,
                -4483,             -4101,       -3969,       -3733,       -3690,       -3565,       -3399,       -3243, -3041, -3015, -2866, -2776, -2706, -2602, -2569,
                -2400,             -1519,        -533,        -422,        -420,        -347,        -205,         430,   540,  1273,  1349,  1730,  1812,  1908,  2103, 2135, 2181,
                2729,               3165,        3394,        3704,        3868,        3924,        4112,        4147,  4331,  4409,  4589,  4916,  5136,  5385,  5735, 5843, 6050,
                6245,               6304,        6695,        7088,        7442,        7510,        7631,        7880,  7970,  8118,  8361,  8488,  8586,  8780,  8900, 8948, 9177,
                9215,               9449,        9700, 9734
            };

            var merge = new MergeTwoSortedLists();

            int[] result = merge.Merge(arr1, arr2);

            int[] expected =
            {
                -2120996231, -2120996231, -2039897248, -2004579200, -1976555129, -1974066388, -1881537032, -1807815184,
                -1730567509, -1712935037, -1703673711, -1646095928, -1626097495, -1615680386, -1597131699, -1570326789,
                -1523090300, -1505782987, -1475588920, -1413239376, -1406129179, -1400568380, -1268858441, -1249391611,
                -1246083490, -1146477631, -1083291644, -1073939103, -1043077206, -1041739357, -1036731760, -1033272347,
                -970190212,   -937576457,  -865905850,  -813031026,  -771745552,  -765507965,  -733255990,  -706572903,
                -667937720,   -628689890,  -597415519,  -582800000,  -571329269,  -535481901,  -435616485,  -411950692,
                -325996333,   -303740798,  -193260330,  -191136906,  -172604141,  -145592722,   -51880142,   -25937243,-18881257,
                -9780,             -9540,       -9490,       -8980,       -8856,       -8753,       -8455,       -8390, -8328, -7929, -7772, -7423, -7412, -7224, -7208,
                -6992,             -6827,       -6731,       -6138,       -5751,       -5676,       -5483,       -5354, -5217, -5177, -5036, -4710, -4697, -4694, -4641,
                -4483,             -4101,       -3969,       -3733,       -3690,       -3565,       -3399,       -3243, -3041, -3015, -2866, -2776, -2706, -2602, -2569,
                -2400,             -1519,        -533,        -422,        -420,        -347,        -205,         430,   540,  1273,  1349,  1730,  1812,  1908,  2103, 2135, 2181,
                2729,               3165,        3394,        3704,        3868,        3924,        4112,        4147,  4331,  4409,  4589,  4916,  5136,  5385,  5735, 5843, 6050,
                6245,               6304,        6695,        7088,        7442,        7510,        7631,        7880,  7970,  8118,  8361,  8488,  8586,  8780,  8900, 8948, 9177,
                9215,               9449,        9700,        9734,    46412230, 46920758
            };

            Assert.That(result, Is.EqualTo(expected));
        }
        public void MergeTwoLists_BothWithSameElement_ShouldMerge()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                1
            },
                new List <int>()
            {
                1
            });

            result.Should().HaveCount(2);
            result[0].Should().Be(1);
            result[1].Should().Be(1);
        }
        public void MergeTwoLists_BothWithOneDistinctUnsortedElement_ShouldMergeSorted()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                2
            },
                new List <int>()
            {
                1
            });

            result.Should().HaveCount(2);
            result[0].Should().Be(1);
            result[1].Should().Be(2);
        }
        public void MergeTwoLists_SecondAreLast_ShouldMergeSorted()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                1, 2
            },
                new List <int>()
            {
                10
            });

            result.Should().HaveCount(3);
            result[0].Should().Be(1);
            result[1].Should().Be(2);
            result[2].Should().Be(10);
        }
        public void MergeTwoLists_DisctinctSizesSecondBigger_ShouldMergeSorted()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                1
            },
                new List <int>()
            {
                1, 2
            });

            result.Should().HaveCount(3);
            result[0].Should().Be(1);
            result[1].Should().Be(1);
            result[2].Should().Be(2);
        }
        public void MergeTwoLists_RandomCase_ShouldMergeSorted()
        {
            var result = MergeTwoSortedLists.Merge(
                new List <int>()
            {
                -71, 2, 12345
            },
                new List <int>()
            {
                -100, 1, 2, 12344
            });

            result.Should().HaveCount(7);
            result[0].Should().Be(-100);
            result[1].Should().Be(-71);
            result[2].Should().Be(1);
            result[3].Should().Be(2);
            result[4].Should().Be(2);
            result[5].Should().Be(12344);
            result[6].Should().Be(12345);
        }