public void TestInsert() { var intervals = new int[2][] { new int[2] { 1, 3 }, new int[2] { 6, 9 } }; var newInterval = new int[] { 2, 5 }; var expectedOutput = new int[2][] { new int[2] { 1, 5 }, new int[2] { 6, 9 } }; var searchProblem = new SearchProblems(); var actualOutput = searchProblem.Insert(intervals, newInterval); Assert.Equal <int>(expectedOutput.Length, actualOutput.Length); for (var i = 0; i < expectedOutput.Length; i++) { Assert.Equal <int>(expectedOutput[i].Length, actualOutput[i].Length); for (var j = 0; j < expectedOutput[i].Length; j++) { Assert.Equal <int>(expectedOutput[i][j], actualOutput[i][j]); } } }
public void TestMergeOutOfOrder() { var input = new int[3][] { new int[2] { 1, 4 }, new int[2] { 0, 2 }, new int[2] { 3, 5 } }; var expectedOutput = new int[1][] { new int[2] { 0, 5 } }; var searchProblem = new SearchProblems(); var actualOutput = searchProblem.Merge(input); Assert.Equal <int>(expectedOutput.Length, actualOutput.Length); for (var i = 0; i < expectedOutput.Length; i++) { Assert.Equal <int>(expectedOutput[i].Length, actualOutput[i].Length); for (var j = 0; j < expectedOutput[i].Length; j++) { Assert.Equal <int>(expectedOutput[i][j], actualOutput[i][j]); } } }
public void TestMerge() { var input = new int[4][] { new int[2] { 1, 3 }, new int[2] { 2, 6 }, new int[2] { 8, 10 }, new int[2] { 15, 18 } }; var expectedOutput = new int[3][] { new int[2] { 1, 6 }, new int[2] { 8, 10 }, new int[2] { 15, 18 } }; var searchProblem = new SearchProblems(); var actualOutput = searchProblem.Merge(input); Assert.Equal <int>(expectedOutput.Length, actualOutput.Length); for (var i = 0; i < expectedOutput.Length; i++) { Assert.Equal <int>(expectedOutput[i].Length, actualOutput[i].Length); for (var j = 0; j < expectedOutput[i].Length; j++) { Assert.Equal <int>(expectedOutput[i][j], actualOutput[i][j]); } } }
public void TestIsAnagram(string s, string t, bool expectedOutput) { var searchProblems = new SearchProblems(); var actualOutput = searchProblems.IsAnagram(s, t); Assert.Equal <bool>(expectedOutput, actualOutput); }
public void TestSearchRange(int[] nums, int target, int[] expectedResult) { var searchProblems = new SearchProblems(); var actualResult = searchProblems.SearchRange(nums, target); Assert.True(actualResult[0] == expectedResult[0] && actualResult[1] == expectedResult[1]); }
public void TestSearch(int[] nums, int target, int expectedIndex) { var searchProblems = new SearchProblems(); var actualIndex = searchProblems.Search(nums, target); Assert.Equal <int>(expectedIndex, actualIndex); }
public void TestDivide(int num1, int num2, int expectedValue) { var searchProblems = new SearchProblems(); var actualResult = searchProblems.Divide(num1, num2); Assert.Equal <int>(expectedValue, actualResult); }
public void TestIntersection2(int[] num1, int[] num2, int[] expectedResult) { var searchProblems = new SearchProblems(); var actualResult = searchProblems.Intersection2(num1, num2); Assert.Equal <int>(expectedResult.Length, actualResult.Length); for (var i = 0; i < expectedResult.Length; i++) { Assert.Equal <int>(expectedResult[i], actualResult[i]); } }
public void TestCountSmallerBruteForce(int[] input, int[] expected) { var searchProblems = new SearchProblems(); var actual = searchProblems.CountSmallerBruteForce(input); Assert.Equal <int>(expected.Length, actual.Count); for (var i = 0; i < actual.Count; i++) { Assert.Equal <int>(expected[i], actual[i]); } }
public void testGetMilestoneDays() { var result = SearchProblems.getMilestoneDays(new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, new int[] { 100, 200, 500 }); Assert.AreEqual(result.Length, 3); Assert.AreEqual(result[0], 4); Assert.AreEqual(result[1], 6); Assert.AreEqual(result[2], 10); result = SearchProblems.getMilestoneDays(new int[] { 700, 800, 600, 400, 600, 700 }, new int[] { 3100, 2200, 800, 2100, 1000 }); Assert.AreEqual(result.Length, 5); Assert.AreEqual(result[0], 5); Assert.AreEqual(result[1], 4); Assert.AreEqual(result[2], 2); Assert.AreEqual(result[3], 3); Assert.AreEqual(result[4], 2); }
public void TestInsertJoinedIntervals() { var intervals = new int[5][] { new int[2] { 1, 2 }, new int[2] { 3, 5 }, new int[2] { 6, 7 }, new int[2] { 8, 10 }, new int[2] { 12, 16 } }; var newInterval = new int[] { 4, 8 }; var expectedOutput = new int[3][] { new int[2] { 1, 2 }, new int[2] { 3, 10 }, new int[2] { 12, 16 } }; var searchProblem = new SearchProblems(); var actualOutput = searchProblem.Insert(intervals, newInterval); Assert.Equal <int>(expectedOutput.Length, actualOutput.Length); for (var i = 0; i < expectedOutput.Length; i++) { Assert.Equal <int>(expectedOutput[i].Length, actualOutput[i].Length); for (var j = 0; j < expectedOutput[i].Length; j++) { Assert.Equal <int>(expectedOutput[i][j], actualOutput[i][j]); } } }
public static void testgetBillionUsersDay() { var result = SearchProblems.getBillionUsersDay(new double[] { 1.1, 1.2, 1.3 }); Assert.AreEqual(79, result); }