public PartialViewResult BinarySearch(string values, int element) { try { var input = ConvertStringToIntArray(values); var result = _basicAlgorithms.BinarySearch(input, element); return(PartialView( "_Results", new ResultsViewModel { Success = true, Result = result == -1 ? string.Format("elementu {0} nie ma w zbiorze", element) : string.Format("element {0} znajduje się na pozycji {1}", element, result) })); } catch (Exception) { return(PartialView("_Results", new ResultsViewModel { Success = false })); } }
public void BinarySearch_ElementNoInCollection_ReturnsMinus1() { var result = _basicAlgorithms.BinarySearch(new int[] { -19, 1, 3, 7, 10 }, 0); Assert.AreEqual(-1, result); }