public void FindIndex_VerifyDuplicates(int count) { SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); T? expectedItem = default(T); int index; Predicate <T> EqualsDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < count) { list.Add(beforeList[0]); //[] Verify first item is duplicated expectedItem = beforeList[0]; index = list.FindIndex(EqualsDelegate); Assert.Equal(0, index); //"Err_3282iahid Verify first item is duplicated" } if (1 < count) { list.Add(beforeList[1]); //[] Verify second item is duplicated expectedItem = beforeList[1]; index = list.FindIndex(EqualsDelegate); Assert.Equal(1, index); //"Err_29892adewiu Verify second item is duplicated" } }
public void FindIndex_VerifyVanilla(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDefaultDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; for (int i = 0; i < count; ++i) { list.Add(beforeList[i]); } //[] Verify FinIndex returns the correct index for (int i = 0; i < count; ++i) { expectedItem = beforeList[i]; index = list.FindIndex(EqualsDefaultDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindIndex to return the same." } //[] Verify FindIndex returns 0 if the match returns true on every item int expected = count == 0 ? -1 : 0; index = list.FindIndex(_alwaysTrueDelegate); Assert.Equal(expected, index); //"Err_15198ajid Verify FindIndex returns 0 if the match returns true on every item expected" //[] Verify FindIndex returns -1 if the match returns false on every item index = list.FindIndex(_alwaysFalseDelegate); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindIndex returns -1 if the match returns false on every item" }
public void FindIndexIntInt_VerifyDuplicates(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = delegate(T item) { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < count) { list.Add(beforeList[0]); //[] Verify first item is duplicated expectedItem = beforeList[0]; index = list.FindIndex(0, list.Count, EqualsDelegate); Assert.Equal(0, index); //"Err_3282iahid Verify first item is duplicated" //[] Verify first item is duplicated and index=1 expectedItem = beforeList[0]; index = list.FindIndex(1, list.Count - 1, EqualsDelegate); Assert.Equal(count, index); //"Err_8588ahidi Verify first item is duplicated and index=1" } if (1 < count) { list.Add(beforeList[1]); //[] Verify second item is duplicated expectedItem = beforeList[1]; index = list.FindIndex(0, list.Count, EqualsDelegate); Assert.Equal(1, index); //"Err_29892adewiu Verify second item is duplicated" //[] Verify second item is duplicated and index=2 expectedItem = beforeList[1]; index = list.FindIndex(2, list.Count - 2, EqualsDelegate); Assert.Equal(count + 1, index); //"Err_1580ahisdf Verify second item is duplicated and index=2" } }
public void FindIndexInt_VerifyVanilla(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = delegate(T item) { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; //[] Verify FinIndex returns the correct index for (int i = 0; i < count; ++i) { expectedItem = beforeList[i]; index = list.FindIndex(0, EqualsDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindIndex to return the same" } //[] Verify FindIndex returns 0 if the match returns true on every item int expected = count == 0 ? -1 : 0; index = list.FindIndex(0, delegate(T item) { return(true); }); Assert.Equal(expected, index); //"Err_15198ajid Verify FindIndex returns 0 if the match returns true on every item " //[] Verify FindIndex returns -1 if the match returns false on every item index = list.FindIndex(0, delegate(T item) { return(false); }); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindIndex returns -1 if the match returns false on every item" //[] Verify FindIndex returns -1 if the index == count index = list.FindIndex(count, delegate(T item) { return(true); }); Assert.Equal(-1, index); //"Err_4858ajodoa Verify FindIndex returns -1 if the index == count" if (0 < count) { //[] Verify NEG FindIndex uses the index expectedItem = beforeList[0]; index = list.FindIndex(1, EqualsDelegate); Assert.Equal(-1, index); //"Err_548797ahjid Verify NEG FindIndex uses the index" } if (1 < count) { //[] Verify POS FindIndex uses the index LOWER expectedItem = beforeList[1]; index = list.FindIndex(1, EqualsDelegate); Assert.Equal(1, index); //"Err_68797ahid Verify POS FindIndex uses the index LOWER" //[] Verify POS FindIndex uses the index UPPER expectedItem = beforeList[count - 1]; index = list.FindIndex(1, EqualsDelegate); Assert.Equal(count - 1, index); //"Err_51488ajod Verify POS FindIndex uses the index UPPER" } }
public void FindIndexInt_VerifyExceptions(int count) { SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); Predicate <T> predicate = delegate(T item) { return(true); }; //[] Verify Null match Assert.Throws <ArgumentNullException>(() => list.FindIndex(0, null !)); //"Err_858ahia Expected null match to throw ArgumentNullException" /****************************************************************************** * index ******************************************************************************/ //[] Verify index=Int32.MinValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(int.MinValue, predicate)); //"Err_948ahid Expected index=Int32.MinValue to throw ArgumentOutOfRangeException" //[] Verify index=-1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(-1, predicate)); //"Err_328ahuaw Expected index=-1 to throw ArgumentOutOfRangeException" //[] Verify index=list.Count + 1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(list.Count + 1, predicate)); //"Err_488ajdi Expected index=list.Count + 1 to throw ArgumentOutOfRangeException" //[] Verify index=Int32.MaxValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(int.MaxValue, predicate)); //"Err_238ajwisa Expected index=Int32.MaxValue to throw ArgumentOutOfRangeException" }
public void FindIndexIntInt_VerifyExceptions(int count) { SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); Predicate <T> predicate = delegate(T item) { return(true); }; //[] Verify Null match Assert.Throws <ArgumentNullException>(() => list.FindIndex(0, 0, null !)); //"Err_858ahia Expected null match to throw ArgumentNullException" /****************************************************************************** * index ******************************************************************************/ //[] Verify index=Int32.MinValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(int.MinValue, 0, predicate)); //"Err_948ahid Expected index=Int32.MinValue to throw ArgumentOutOfRangeException" //[] Verify index=-1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(-1, 0, predicate)); //"Err_328ahuaw Expected index=-1 to throw ArgumentOutOfRangeException" //[] Verify index=list.Count + 1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(list.Count + 1, 0, predicate)); //"Err_488ajdi Expected index=list.Count + 1 to throw ArgumentOutOfRangeException" //[] Verify index=list.Count Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(list.Count, 1, predicate)); //"Err_9689ajis Expected index=list.Count to throw ArgumentOutOfRangeException" //[] Verify index=Int32.MaxValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(int.MaxValue, 0, predicate)); //"Err_238ajwisa Expected index=Int32.MaxValue to throw ArgumentOutOfRangeException" /****************************************************************************** * count ******************************************************************************/ //[] Verify count=Int32.MinValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, int.MinValue, predicate)); //Err_948ahid Expected count=Int32.MinValue to throw ArgumentOutOfRangeException" //[] Verify count=-1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, -1, predicate)); //"Err_328ahuaw Expected count=-1 to throw ArgumentOutOfRangeException" //[] Verify count=list.Count + 1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, list.Count + 1, predicate)); //"Err_488ajdi Expected count=list.Count + 1 to throw ArgumentOutOfRangeException" //[] Verify count=Int32.MaxValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, int.MaxValue, predicate)); //"Err_238ajwisa Expected count=Int32.MaxValue to throw ArgumentOutOfRangeException" /****************************************************************************** * index and count ******************************************************************************/ if (0 < count) { //[] Verify index=1 count=list.Length Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(1, count, predicate)); //"Err_018188avbiw Expected index=1 count=list.Length to throw ArgumentOutOfRangeException" //[] Verify index=0 count=list.Length + 1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, count + 1, predicate)); //"Err_6848ajiodxbz Expected index=0 count=list.Length + 1 to throw ArgumentOutOfRangeException" } }