public void FindLastIndexIntInt_VerifyDuplicates(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); 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.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate); Assert.Equal(list.Count - 1, 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.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate); Assert.Equal(list.Count - 1, index); //"Err_29892adewiu Verify second item is duplicated" } }
public void FindLastIndex_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.FindLastIndex(EqualsDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindLastIndex to return the same." } //[] Verify FindLastIndex returns 0 if the match returns true on every item int expected = count == 0 ? -1 : count - 1; index = list.FindLastIndex(_alwaysTrueDelegate); Assert.Equal(expected, index); //"Err_15198ajid Verify FindLastIndex returns 0 if the match returns true on every item" //[] Verify FindLastIndex returns -1 if the match returns false on every item index = list.FindLastIndex(_alwaysFalseDelegate); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindLastIndex returns -1 if the match returns false on every item" }
public void FindLastIndexInt_VerifyExceptions(int count) { SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); Predicate <T> predicate = _alwaysTrueDelegate; //[] Verify Null match Assert.Throws <ArgumentNullException>(() => list.FindLastIndex(0, null !)); //"Err_858ahia Expected null match to throw ArgumentNullException" /****************************************************************************** * index ******************************************************************************/ //[] Verify index=Int32.MinValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(int.MinValue, predicate)); //"Err_948ahid Expected index=Int32.MinValue to throw ArgumentOutOfRangeException" if (0 < list.Count) { //[] Verify index=-1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(-1, predicate)); //"Err_328ahuaw Expected index=-1 to throw ArgumentOutOfRangeException" } //[] Verify index=list.Count + 1 Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(list.Count + 1, predicate)); //"Err_488ajdi Expected index=list.Count + 1 to throw ArgumentOutOfRangeException" //[] Verify index=list.Count Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(list.Count, predicate)); //"Err_9689ajis Expected index=list.Count to throw ArgumentOutOfRangeException" //[] Verify index=Int32.MaxValue Assert.Throws <ArgumentOutOfRangeException>(() => list.FindLastIndex(int.MaxValue, predicate)); //"Err_238ajwisa Expected index=Int32.MaxValue to throw ArgumentOutOfRangeException" }
public void FindLastIndexInt_VerifyVanilla(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = (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.FindLastIndex(count - 1, EqualsDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindLastIndex to return the same." } //[] Verify FindLastIndex returns 0 if the match returns true on every item index = list.FindLastIndex(count - 1, _alwaysTrueDelegate); int expected = count == 0 ? -1 : count - 1; Assert.Equal(expected, index); //"Err_15198ajid Verify FindLastIndex returns 0 if the match returns true on every item" //[] Verify FindLastIndex returns -1 if the match returns false on every item index = list.FindLastIndex(count - 1, _alwaysFalseDelegate); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindLastIndex returns -1 if the match returns false on every item" //[] Verify FindLastIndex returns 0 if the index == 0 expected = 0 < count ? count - 1 : -1; index = list.FindLastIndex(count - 1, _alwaysTrueDelegate); Assert.Equal(expected, index); //"Err_4858ajodoa Verify FindLastIndex returns 0 if the index == 0 " if (1 < count) { //[] Verify NEG FindLastIndex uses the index expectedItem = beforeList[count - 1]; index = list.FindLastIndex(count - 2, EqualsDelegate); Assert.Equal(-1, index); //"Err_548797ahjid Verify NEG FindLastIndex uses the index" //[] Verify POS FindLastIndex uses the index LOWER expectedItem = beforeList[0]; index = list.FindLastIndex(count - 2, EqualsDelegate); Assert.Equal(0, index); //"Err_68797ahid Verify POS FindLastIndex uses the index LOWER" //[] Verify POS FindLastIndex uses the index UPPER expectedItem = beforeList[count - 2]; expected = count - 2; index = list.FindLastIndex(count - 2, EqualsDelegate); Assert.Equal(expected, index); //"Err_51488ajod Verify POS FindLastIndex uses the index UPPER" } }
public void FindLastIndexIntInt_VerifyVanilla(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = (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.FindLastIndex(count - 1, count, EqualsDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindLastIndex to be the same." } //[] Verify FindLastIndex returns 0 if the match returns true on every item int expected = count == 0 ? -1 : count - 1; index = list.FindLastIndex(count - 1, count, _alwaysTrueDelegate); Assert.Equal(expected, index); //"Err_15198ajid Verify FindLastIndex returns 0 if the match returns true on every item" //[] Verify FindLastIndex returns -1 if the match returns false on every item index = list.FindLastIndex(count - 1, count, _alwaysFalseDelegate); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindLastIndex returns -1 if the match returns false on every item" if (0 < count) { //[] Verify FindLastIndex returns -1 if the index == 0 index = list.FindLastIndex(0, 0, _alwaysTrueDelegate); Assert.Equal(-1, index); //"Err_298298ahdi Verify FindLastIndex returns -1 if the index=0" //[] Verify NEG FindLastIndex uses the count expectedItem = beforeList[0]; index = list.FindLastIndex(count - 1, count - 1, EqualsDelegate); Assert.Equal(-1, index); //"Err_7894ahoid Verify NEG FindLastIndex uses the count" } if (1 < count) { //[] Verify NEG FindLastIndex uses the index expectedItem = beforeList[count - 1]; index = list.FindLastIndex(count - 2, count - 1, EqualsDelegate); Assert.Equal(-1, index); //"Err_548797ahjid Verify NEG FindLastIndex uses the index" //[] Verify POS FindLastIndex uses the index expectedItem = beforeList[count - 2]; index = list.FindLastIndex(count - 2, count - 1, EqualsDelegate); Assert.Equal(count - 2, index); //"Err_68797ahid Verify POS FindLastIndex uses the index" //[] Verify POS FindLastIndex uses the count expectedItem = beforeList[count - 2]; index = list.FindLastIndex(count - 1, count - 1, EqualsDelegate); Assert.Equal(count - 2, index); //"Err_28278ahdii Verify POS FindLastIndex uses the count" //[] Verify NEG FindLastIndex uses the index and count LOWER expectedItem = beforeList[0]; index = list.FindLastIndex(count - 2, count - 2, EqualsDelegate); Assert.Equal(-1, index); //"Err_384984ahjiod Verify NEG FindLastIndex uses the index and count LOWER" //[] Verify NEG FindLastIndex uses the index and count UPPER expectedItem = beforeList[count - 1]; index = list.FindLastIndex(count - 2, count - 2, EqualsDelegate); Assert.Equal(-1, index); //"Err_1489haidid Verify NEG FindLastIndex uses the index and count UPPER" //[] Verify POS FindLastIndex uses the index and count LOWER expectedItem = beforeList[1]; index = list.FindLastIndex(count - 2, count - 2, EqualsDelegate); Assert.Equal(1, index); //"Err_604890ahjid Verify POS FindLastIndex uses the index and count LOWER" //[] Verify POS FindLastIndex uses the index and count UPPER expectedItem = beforeList[count - 2]; index = list.FindLastIndex(count - 2, count - 2, EqualsDelegate); Assert.Equal(count - 2, index); //"Err_66844ahidd Verify POS FindLastIndex uses the index and count UPPER" } }