From 8dd5ace94cc0eebdbc585a1233afbaa3998fd306 Mon Sep 17 00:00:00 2001 From: ankit Date: Thu, 16 Mar 2006 17:04:44 +0000 Subject: [PATCH] In class/corlib/System.Collections.Generic: * List.cs (CheckIndex): Check for -ve indices and allow index == size. (Insert): Use CheckIndex. In class/corlib/Test/System.Collections.Generic: * ListTest.cs: Add some tests for InsertRange. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@58069 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- class/corlib/System.Collections.Generic/ChangeLog | 5 +++++ class/corlib/System.Collections.Generic/List.cs | 6 ++---- class/corlib/Test/System.Collections.Generic/ChangeLog | 4 ++++ class/corlib/Test/System.Collections.Generic/ListTest.cs | 13 +++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/class/corlib/System.Collections.Generic/ChangeLog b/class/corlib/System.Collections.Generic/ChangeLog index 20e2bb3753..c61ce070c7 100644 --- a/class/corlib/System.Collections.Generic/ChangeLog +++ b/class/corlib/System.Collections.Generic/ChangeLog @@ -1,3 +1,8 @@ +2006-03-16 Ankit Jain + + * List.cs (CheckIndex): Check for -ve indices and allow index == size. + (Insert): Use CheckIndex. + 2006-03-12 Zoltan Varga * List.cs: Applied patch from . Fixes #77504. diff --git a/class/corlib/System.Collections.Generic/List.cs b/class/corlib/System.Collections.Generic/List.cs index 1b4edb3240..b95278e1e5 100644 --- a/class/corlib/System.Collections.Generic/List.cs +++ b/class/corlib/System.Collections.Generic/List.cs @@ -342,15 +342,13 @@ namespace System.Collections.Generic { void CheckIndex (int index) { - if ((uint) index >= (uint) size) + if (index < 0 || (uint) index > (uint) size) throw new ArgumentOutOfRangeException ("index"); } public void Insert (int index, T item) { - if ((uint) index > (uint) size) - throw new ArgumentOutOfRangeException ("index"); - + CheckIndex (index); GrowIfNeeded (1); Shift (index, 1); this [index] = item; diff --git a/class/corlib/Test/System.Collections.Generic/ChangeLog b/class/corlib/Test/System.Collections.Generic/ChangeLog index 0b05f3c398..1a1cb21857 100644 --- a/class/corlib/Test/System.Collections.Generic/ChangeLog +++ b/class/corlib/Test/System.Collections.Generic/ChangeLog @@ -1,3 +1,7 @@ +2006-03-16 Ankit Jain + + * ListTest.cs: Add some tests for InsertRange. + 2006-01-23 Raja R Harinath * DictionaryTest.cs (IDictionary_*): Add a few tests for the diff --git a/class/corlib/Test/System.Collections.Generic/ListTest.cs b/class/corlib/Test/System.Collections.Generic/ListTest.cs index 8243b25251..50b482ca28 100644 --- a/class/corlib/Test/System.Collections.Generic/ListTest.cs +++ b/class/corlib/Test/System.Collections.Generic/ListTest.cs @@ -109,6 +109,13 @@ namespace MonoTests.System.Collections.Generic { Assert.AreEqual (2, _list1 [2]); Assert.AreEqual (3, _list1 [3]); Assert.AreEqual (50, _list1 [4]); + + newRange = new List (); + List li = new List (); + li.Add (1); + newRange.InsertRange (0, li); + newRange.InsertRange (newRange.Count, li); + Assert.AreEqual (2, newRange.Count); } [Test, ExpectedException (typeof (ArgumentNullException))] @@ -118,6 +125,12 @@ namespace MonoTests.System.Collections.Generic { _list1.InsertRange (0, n); } + [Test, ExpectedException (typeof (ArgumentOutOfRangeException))] + public void InsertRangeNegativeIndexTest () + { + _list1.InsertRange (-1, _list1); + } + [Test] public void IndexOfTest () { -- 2.11.4.GIT