public void BinarySearch_Validations(int count) { PooledList <T> list = GenericListFactory(count); list.Sort(); T element = CreateT(3215); AssertExtensions.Throws <ArgumentException>(null, () => list.BinarySearch(0, count + 1, element, GetIComparer())); //"Finding items longer than array should throw ArgumentException" Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(-1, count, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative index." Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(0, -1, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative count." AssertExtensions.Throws <ArgumentException>(null, () => list.BinarySearch(count + 1, count, element, GetIComparer())); //"ArgumentException should be thrown on index greater than length of array." list.Dispose(); }
public void BinarySearch_ForEveryItemWithDuplicates(int count) { if (count > 0) { PooledList <T> list = GenericListFactory(count); list.Add(list[0]); list.Sort(); PooledList <T> beforeList = list.ToPooledList(); Assert.All(Enumerable.Range(0, list.Count), index => { Assert.True(list.BinarySearch(beforeList[index]) >= 0); Assert.True(list.BinarySearch(beforeList[index], GetIComparer()) >= 0); Assert.Equal(beforeList[index], list[index]); }); list.Dispose(); } }
public void BinarySearch_ForEveryItemWithoutDuplicates(int count) { PooledList <T> list = GenericListFactory(count); foreach (T item in list) { while (list.Count((value) => value.Equals(item)) > 1) { list.Remove(item); } } list.Sort(); PooledList <T> beforeList = list.ToPooledList(); Assert.All(Enumerable.Range(0, list.Count), index => { Assert.Equal(index, list.BinarySearch(beforeList[index])); Assert.Equal(index, list.BinarySearch(beforeList[index], GetIComparer())); Assert.Equal(beforeList[index], list[index]); }); list.Dispose(); }