public void RemovedValues(T[] items) { SegmentedList <T> list = new SegmentedList <T>(items); for (int i = 0; i < items.Length; i++) { list.Remove(items[i]); Assert.False(list.Contains(items[i])); //"Should not contain item" } }
public void AddRemoveValues(T[] items) { SegmentedList <T> list = new SegmentedList <T>(items); for (int i = 0; i < items.Length; i++) { list.Add(items[i]); list.Remove(items[i]); list.Add(items[i]); Assert.True(list.Contains(items[i])); //"Should contain item." } }
public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder) { _ = frontToBackOrder; T?defaultValue = default; SegmentedList <T?> list = GenericListFactory(count) !; IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod); while (list.Remove(defaultValue)) { count--; } list.Add(defaultValue); Assert.Equal(count, IndexOf(list !, defaultValue !)); }
public void MultipleValues(T[] items, int times) { SegmentedList <T> list = new SegmentedList <T>(items); for (int i = 0; i < times; i++) { list.Add(items[items.Length / 2]); } for (int i = 0; i < times + 1; i++) { Assert.True(list.Contains(items[items.Length / 2])); //"Should contain item." list.Remove(items[items.Length / 2]); } Assert.False(list.Contains(items[items.Length / 2])); //"Should not contain item" }
public void BinarySearch_ForEveryItemWithoutDuplicates(int count) { SegmentedList <T> list = GenericListFactory(count); foreach (T item in list) { while (list.Count((value) => value.Equals(item)) > 1) { list.Remove(item); } } list.Sort(); SegmentedList <T> beforeList = list.ToSegmentedList(); 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]); }); }