public static void Main() { int[] arr = new int[] { 3, -1, 15, 4, 17, 2, 33, 0 }; Console.WriteLine("arr = [{0}]", string.Join(", ", arr)); Sorter collectionSorter = new Sorter(); collectionSorter.SelectionSort(arr); Console.WriteLine("sorted = [{0}]", string.Join(", ", arr)); collectionSorter.SelectionSort(new int[0]); // Test sorting empty array collectionSorter.SelectionSort(new int[1]); // Test sorting single element array Searcher collectionSearcher = new Searcher(); Console.WriteLine(collectionSearcher.BinarySearch(arr, -1000)); Console.WriteLine(collectionSearcher.BinarySearch(arr, 0)); Console.WriteLine(collectionSearcher.BinarySearch(arr, 17)); Console.WriteLine(collectionSearcher.BinarySearch(arr, 10)); Console.WriteLine(collectionSearcher.BinarySearch(arr, 1000)); int testEmptArraySearch = collectionSearcher.BinarySearch(new int[0], 5); // Test searching empty array int testSingleElementExistingSearch = collectionSearcher.BinarySearch(new int[1], 0); // Test searching single element array (Existing value) int testSingleelementNoExistingsearch = collectionSearcher.BinarySearch(new int[1], 5); // Test searching single element array (Non existing value) }
public int BinarySearchTest_InputIntArray(int[] array, int element) { return(Searcher.BinarySearch <int>(array, element)); }
public int BinarySearchTest_InputStringArray(string[] array, string element) { return(Searcher.BinarySearch <string>(array, element)); }
public void BinarySearchTest <T>(T[] array, T key, int expected) where T : IComparable { var searcher = new Searcher <T>(); Assert.That(searcher.BinarySearch(array, key), Is.EqualTo(expected)); }