Пример #1
0
        public void Test1()
        {
            var arr            = new int[][] { new int[] { 1, 3 }, new int[] { 2, 6 }, new int[] { 8, 10 }, new int[] { 15, 18 } };
            var result         = solution.Merge(arr);
            var expectedResult = new int[][] { new int[] { 1, 6 }, new int[] { 8, 10 }, new int[] { 15, 18 } };

            Assert.AreEqual(result.Length, expectedResult.Length);
            for (var ind = 0; ind > expectedResult.Length; ++ind)
            {
                Assert.AreEqual(expectedResult[ind][0] == result[ind][0] && expectedResult[ind][1] == result[ind][1], true);
            }
        }
        public void Merge_WhenGivenTwoOverlappingIntervalsLCTestCase2_ReturnsCorrectResult()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[10][];
            testArray[0] = new int[] { 5, 5 };
            testArray[1] = new int[] { 1, 3 };
            testArray[2] = new int[] { 3, 5 };
            testArray[3] = new int[] { 4, 6 };
            testArray[4] = new int[] { 1, 1 };
            testArray[5] = new int[] { 3, 3 };
            testArray[6] = new int[] { 5, 6 };
            testArray[7] = new int[] { 3, 3 };
            testArray[8] = new int[] { 2, 4 };
            testArray[9] = new int[] { 0, 0 };

            int[][] expected = new int[2][];
            expected[0] = new int[] { 0, 0 };
            expected[1] = new int[] { 1, 6 };

            // Act
            int[][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
Пример #3
0
        public void MergeTests()
        {
            MergeIntervals obj = new MergeIntervals();

            int[][] arr = new int[][]
            {
                new[] { 1, 3 },
                new[] { 2, 6 },
                new[] { 8, 10 },
                new[] { 15, 18 },
            };

            var x = obj.Merge(arr);

            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 4, 5 }
            };

            x = obj.Merge(arr);

            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 0, 4 }
            };

            x = obj.Merge(arr);


            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 2, 3 }
            };

            x = obj.Merge(arr);
        }
        public void mergeIntervalsTest()
        {
            IList <Interval> result = MergeIntervals.Merge(inputIntervals);

            Console.WriteLine("Actual result: ");
            foreach (Interval interval in result)
            {
                Console.WriteLine("Start: " + interval.start + ", " + "End: " + interval.end);
            }
            Console.WriteLine("Expected result: ");
            foreach (Interval interval in outputIntervals)
            {
                Console.WriteLine("Start: " + interval.start + ", " + "End: " + interval.end);
            }
        }
        public void Merge_WhenGivenTwoOverlappingIntervalsLCTestCase_ReturnsCorrectResult()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[2][];
            testArray[0] = new int[] { 1, 4 };
            testArray[1] = new int[] { 0, 4 };

            int[][] expected = new int[1][];
            expected[0] = new int[] { 0, 4 };

            // Act
            int[][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
        public void Merge_WhenGivenTwoOverlappingIntervals_ReturnsOne()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[4][];
            testArray[0] = new int[] { 1, 3 };
            testArray[1] = new int[] { 2, 6 };
            testArray[2] = new int[] { 8, 10 };
            testArray[3] = new int[] { 15, 18 };

            int[][] expected = new int[3][];
            expected[0] = new int[] { 1, 6 };
            expected[1] = new int[] { 8, 10 };
            expected[2] = new int[] { 15, 18 };

            // Act
            int [][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
Пример #7
0
        public void Given_intervals_When_merge_Then_return()
        {
            List <Interval> intervals = new List <Interval>
            {
                new Interval(1, 3),
                new Interval(2, 6),
                new Interval(8, 10),
                new Interval(15, 18),
            };

            var result = MergeIntervals.Merge(intervals);

            Assert.AreEqual(3, result.Count);

            Assert.AreEqual(1, result[0].start);
            Assert.AreEqual(6, result[0].end);

            Assert.AreEqual(8, result[1].start);
            Assert.AreEqual(10, result[1].end);

            Assert.AreEqual(15, result[2].start);
            Assert.AreEqual(18, result[2].end);
        }