public static Find ( Array input, int value ) : int | ||
input | Array | |
value | int | |
return | int |
public void A_value_smaller_than_the_arrays_smallest_value_is_not_included() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var value = 0; Assert.Equal(-1, BinarySearch.Find(array, value)); }
public void A_value_larger_than_the_arrays_largest_value_is_not_found() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var value = 13; Assert.Equal(-1, BinarySearch.Find(array, value)); }
public void Finds_a_value_at_the_end_of_an_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var value = 11; Assert.Equal(6, BinarySearch.Find(array, value)); }
public void A_value_larger_than_the_arrays_largest_value_is_not_included() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var sut = new BinarySearch(array); Assert.Equal(-1, sut.Find(13)); }
public void Identifies_that_a_value_is_not_included_in_the_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var value = 7; Assert.Equal(-1, BinarySearch.Find(array, value)); }
public void TestBinarySearchReturnsCorrectIndex() { var expected = 0; var index = BinarySearch.Find(new int[] { 1, 2, 3, 4, 5, 6 }, 1); Assert.AreEqual(expected, index); }
public void Nothing_is_included_in_an_empty_array() { var array = Array.Empty <int>(); var value = 1; Assert.Equal(-1, BinarySearch.Find(array, value)); }
public void Identifies_that_a_value_is_not_included_in_the_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var sut = new BinarySearch(array); Assert.Equal(-1, sut.Find(7)); }
public void Finds_a_value_in_an_array_with_one_element() { var array = new[] { 6 }; var sut = new BinarySearch(array); Assert.Equal(0, sut.Find(6)); }
public void Finds_a_value_at_the_end_of_an_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var sut = new BinarySearch(array); Assert.Equal(6, sut.Find(11)); }
public void Finds_a_value_in_an_array_of_even_length() { var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 }; var sut = new BinarySearch(array); Assert.Equal(5, sut.Find(21)); }
public void BinarySearchTest() { for (int i = 0; i < 10; i++) { for (int j = 0; j < 100; j++) { int[] data = ArrayUtilities.CreateRandomArray(j, -100, 100); Array.Sort(data); for (int n = -100; n <= 100; n++) { int index = BinarySearch.Find(data, n); if (index < 0) { Assert.IsTrue(Array.BinarySearch(data, n) < 0); } else { Assert.AreEqual(n, data[index]); } } } } }
public void Finds_a_value_in_the_middle_of_an_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var sut = new BinarySearch(array); Assert.Equal(3, sut.Find(6)); }
public void TestBinarySearchRetursnCorrectWhenValueNotFound() { var expected = -1; var index = BinarySearch.Find(new int[] { 1, 2, 3, 4, 5, 6 }, 122); Assert.AreEqual(expected, index); }
public void Finds_a_value_in_the_middle_of_an_array() { var array = new[] { 1, 3, 4, 6, 8, 9, 11 }; var value = 6; Assert.Equal(3, BinarySearch.Find(array, value)); }
public void Nothing_is_included_in_an_empty_array() { var array = new int[0]; var sut = new BinarySearch(array); Assert.Equal(-1, sut.Find(1)); }
public void Finds_a_value_in_an_array_with_one_element() { var array = new[] { 6 }; var value = 6; Assert.Equal(0, BinarySearch.Find(array, value)); }
public void Finds_a_value_in_an_array_of_odd_length() { var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634 }; var value = 144; Assert.Equal(9, BinarySearch.Find(array, value)); }
public void Finds_a_value_in_an_array_of_even_length() { var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 }; var value = 21; Assert.Equal(5, BinarySearch.Find(array, value)); }
public void Nothing_is_found_when_the_left_and_right_bounds_cross() { var array = new[] { 1, 2 }; var value = 0; Assert.Equal(-1, BinarySearch.Find(array, value)); }
public void BinarySearchWorks_Hard() { int[] elements = { 6, 13, 14, 25, 33, 43, 51, 53, 64, 72, 84, 93, 95, 96, 97 }; int result = BinarySearch.Find(elements, 97); Assert.Equal(result, 14); }
public void BinarySearchNoElement() { int[] array = { 1, 3, 7, 11, 14, 15, 18 }; int result = BinarySearch <int> .Find(array, 2); Assert.AreEqual(-1, result); }
public void BinarySearchUsual() { int[] array = { 1, 3, 7, 11, 14, 15, 18 }; int result = BinarySearch <int> .Find(array, 15); Assert.AreEqual(5, result); }
public void Test_Correct_Input() { int[] array = new int[] { 4, 8, 13, 15, 19, 26, 29, 35, 39, 47, 58, 69 }; int actual = BinarySearch.Find(array, 8); int expected = 1; Assert.AreEqual(expected, actual); }
static void Main(string[] args) { int[] storage = { 1, 3, 4, 8, 20, 50, 77, 100 }; int number = -500; BinarySearch searchRoutine = new BinarySearch(); Console.WriteLine($"The index of the search numer {number} is {searchRoutine.Find(number, storage)}"); Console.ReadKey(); }
public void TestFind() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; BinarySearch <int> searcher = new BinarySearch <int>(); int idx = searcher.Find(array, 3); Assert.AreEqual(idx, 2); }
public void BinarySearch_Find_FindMiddle() { var search = new BinarySearch(); var list = new List <int>() { 2, 4, 6 }; var result = search.Find(list, 4); Assert.AreEqual(1, result.PositionFound); list = new List <int>() { 2, 4, 6, 8 }; result = search.Find(list, 6); Assert.AreEqual(2, result.PositionFound); }
private static void BinarySearchFunctionality() { var mass = new int[4] { 1, 2, 3, 4 }; const int num = 2; var index = BinarySearch <int> .Find(mass, num, Comparer <int> .Default); Console.WriteLine($"The element {num} has {index} index"); }
public void TestBinarySearch() { var array = new BinarySearchItem[] { new BinarySearchItem { Id = 1 }, new BinarySearchItem { Id = 3 }, new BinarySearchItem { Id = 5 }, new BinarySearchItem { Id = 7 }, new BinarySearchItem { Id = 9 }, new BinarySearchItem { Id = 11 }, new BinarySearchItem { Id = 15 }, new BinarySearchItem { Id = 21 }, new BinarySearchItem { Id = 29 }, }; var binarySearch = new BinarySearch <BinarySearchItem>(); var result1 = binarySearch.Find(array, new BinarySearchItem { Id = 21 }); var result2 = binarySearch.Find(array, new BinarySearchItem { Id = 6 }); }
public void BinarySearch_Find_NoFind() { var search = new BinarySearch(); var list = new List <int>() { 2, 4, 6 }; var result = search.Find(list, 5); Assert.IsNull(result.PositionFound); }
private int? ExecuteFind( int[] array, int value ) { var searcher = new BinarySearch(); return searcher.Find(array, value); }