Author: raja
Date: 2006-01-19 08:32:39 -0500 (Thu, 19 Jan 2006)
New Revision: 55781

Modified:
   trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog
   trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
   trunk/mcs/class/corlib/Test/System.Collections.Generic/ChangeLog
   trunk/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs
Log:
In System.Collections.Generic:
        Fix to pass new nunit tests.
        * Dictionary.cs (ShimEnumerator): New class.  Implement the
        requirement that ((IDictionary) foo).GetEnumerator ().Current has
        type DictionaryEntry.
        (IDictionary.GetEnumerator): Use ShimEnumerator.
        (Enumerator.Current): Now has type KeyValuePair<TKey, TValue>.
        (Enumerator.MoveNext): Use VerifyState.
        (Enumerator.VerifyState): Move validation of 'current' field to ...
        (Enumerator.CurrentSlot): ... this.
        (Enumerator.Current, Enumerator.IDictionaryEnumerator.Entry):
        Use CurrentSlot.
        (CopyTo, ICollection.CopyTo): Use subtle reasoning to replace a
        '>=' with a '>'.  Don't throw an ArgumentException when
        index==array.Length && Count==0.
        (KeyCollection.CopyTo, ValueCollection.CopyTo): Likewise, and thus
        obviate the need to check (dictionary.Count == 0).

In Test/System.Collections.Generic:
        * DictionaryTest.cs: Remove NotWorking annotations.
        (Empty_CopyTo, Empty_Values_CopyTo): Fix tests to check that
        CopyTo from an empty dictionary does not throw an exception when
        'index==array.Length'.
        (PlainEnumeratorReturnTest): Check the type of 'Entry' property too.


Modified: trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog 2006-01-19 
13:21:49 UTC (rev 55780)
+++ trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog 2006-01-19 
13:32:39 UTC (rev 55781)
@@ -1,3 +1,22 @@
+2006-01-19  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       Fix to pass new nunit tests.
+       * Dictionary.cs (ShimEnumerator): New class.  Implement the
+       requirement that ((IDictionary) foo).GetEnumerator ().Current has
+       type DictionaryEntry.
+       (IDictionary.GetEnumerator): Use ShimEnumerator.
+       (Enumerator.Current): Now has type KeyValuePair<TKey, TValue>.
+       (Enumerator.MoveNext): Use VerifyState.
+       (Enumerator.VerifyState): Move validation of 'current' field to ...
+       (Enumerator.CurrentSlot): ... this.
+       (Enumerator.Current, Enumerator.IDictionaryEnumerator.Entry):
+       Use CurrentSlot.
+       (CopyTo, ICollection.CopyTo): Use subtle reasoning to replace a
+       '>=' with a '>'.  Don't throw an ArgumentException when
+       index==array.Length && Count==0.
+       (KeyCollection.CopyTo, ValueCollection.CopyTo): Likewise, and thus
+       obviate the need to check (dictionary.Count == 0).
+
 2005-12-20  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * List.cs: Applied Atsushi's patch for Sort (bug 76361) now that the

Modified: trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
===================================================================
--- trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs     
2006-01-19 13:21:49 UTC (rev 55780)
+++ trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs     
2006-01-19 13:32:39 UTC (rev 55781)
@@ -171,7 +171,8 @@
                                throw new ArgumentNullException ("array");
                        if (index < 0)
                                throw new ArgumentOutOfRangeException ("index");
-                       if (index >= array.Length)
+                       // we want no exception for index==array.Length && 
Count == 0
+                       if (index > array.Length)
                                throw new ArgumentException ("index larger than 
largest valid index of array");
                        if (array.Length - index < Count)
                                throw new ArgumentException ("Destination array 
cannot hold the requested elements!");
@@ -446,7 +447,8 @@
                                throw new ArgumentNullException ("array");
                        if (index < 0)
                                throw new ArgumentOutOfRangeException ("index");
-                       if (index >= array.Length)
+                       // we want no exception for index==array.Length && 
Count == 0
+                       if (index > array.Length)
                                throw new ArgumentException ("index larger than 
largest valid index of array");
                        if (array.Length - index < Count)
                                throw new ArgumentException ("Destination array 
cannot hold the requested elements!");
@@ -469,7 +471,7 @@
 
                IDictionaryEnumerator IDictionary.GetEnumerator ()
                {
-                       return new Enumerator (this);
+                       return new ShimEnumerator (this);
                }
 
                public Enumerator GetEnumerator ()
@@ -478,6 +480,49 @@
                }
 
                [Serializable]
+               private struct ShimEnumerator : IDictionaryEnumerator, 
IEnumerator
+               {
+                       Enumerator host_enumerator;
+                       public ShimEnumerator (Dictionary<TKey, TValue> host)
+                       {
+                               host_enumerator = host.GetEnumerator ();
+                       }
+
+                       public void Dispose ()
+                       {
+                               host_enumerator.Dispose ();
+                       }
+
+                       public bool MoveNext ()
+                       {
+                               return host_enumerator.MoveNext ();
+                       }
+
+                       public DictionaryEntry Entry {
+                               get { return ((IDictionaryEnumerator) 
host_enumerator).Entry; }
+                       }
+
+                       public object Key {
+                               get { return host_enumerator.Current.Key; }
+                       }
+
+                       public object Value {
+                               get { return host_enumerator.Current.Value; }
+                       }
+
+                       // This is the raison d' etre of this [EMAIL 
PROTECTED]@^@ class.
+                       // We want: IDictionary.GetEnumerator ().Current is 
DictionaryEntry
+                       public object Current {
+                               get { return Entry; }
+                       }
+
+                       public void Reset ()
+                       {
+                               ((IEnumerator)host_enumerator).Reset ();
+                       }
+               }
+
+               [Serializable]
                public struct Enumerator : 
IEnumerator<KeyValuePair<TKey,TValue>>,
                        IDisposable, IDictionaryEnumerator, IEnumerator
                {
@@ -500,33 +545,25 @@
 
                        public bool MoveNext ()
                        {
-                               if (dictionary == null)
-                                       throw new ObjectDisposedException 
(null);
-                               if (dictionary.generation != stamp)
-                                       throw new InvalidOperationException 
("out of sync");
+                               VerifyState ();
 
-                               // Pre-condition: current == null => this is 
the first call
-                               // to MoveNext ()
+                               // Pre-condition: current == null => this is 
the first call to MoveNext ()
                                if (current != null)
                                        current = current.Next;
 
                                while (current == null && next_index < 
dictionary.table.Length)
                                        current = dictionary.table 
[next_index++];
 
-                               // Post-condition: current == null => this is 
the last call
-                               // to MoveNext()
+                               // Post-condition: current == null => this is 
the last call to MoveNext()
                                return current != null;
                        }
 
                        public KeyValuePair<TKey, TValue> Current {
-                               get {
-                                       VerifyState ();
-                                       return current.Data;
-                               }
+                               get { return CurrentSlot ().Data; }
                        }
 
                        object IEnumerator.Current {
-                               get { return ((IDictionaryEnumerator) 
this).Entry; }
+                               get { return Current; }
                        }
 
                        void IEnumerator.Reset ()
@@ -537,8 +574,8 @@
 
                        DictionaryEntry IDictionaryEnumerator.Entry {
                                get {
-                                       VerifyState ();
-                                       return new DictionaryEntry 
(current.Data.Key, current.Data.Value);
+                                       Slot s = CurrentSlot ();
+                                       return new DictionaryEntry (s.Data.Key, 
s.Data.Value);
                                }
                        }
 
@@ -556,9 +593,16 @@
                                        throw new ObjectDisposedException 
(null);
                                if (dictionary.generation != stamp)
                                        throw new InvalidOperationException 
("out of sync");
+                       }
+
+                       Slot CurrentSlot ()
+                       {
+                               VerifyState ();
                                if (current == null)
-                                       throw new InvalidOperationException ();
+                                       throw new InvalidOperationException 
("Current is not valid");
+                               return current;
                        }
+
                        public void Dispose ()
                        {
                                current = null;
@@ -584,10 +628,8 @@
                                        throw new ArgumentNullException 
("array");
                                if (index < 0)
                                        throw new ArgumentOutOfRangeException 
("index");
-                               // no exception for index==array.Length in this 
case
-                               if (dictionary.Count == 0)
-                                       return;
-                               if (index >= array.Length)
+                               // we want no exception for index==array.Length 
&& dictionary.Count == 0
+                               if (index > array.Length)
                                        throw new ArgumentException ("index 
larger than largest valid index of array");
                                if (array.Length - index < dictionary.Count)
                                        throw new ArgumentException 
("Destination array cannot hold the requested elements!");
@@ -704,10 +746,8 @@
                                        throw new ArgumentNullException 
("array");
                                if (index < 0)
                                        throw new ArgumentOutOfRangeException 
("index");
-                               // no exception for index==array.Length in this 
case
-                               if (dictionary.Count == 0)
-                                       return;
-                               if (index >= array.Length)
+                               // we want no exception for index==array.Length 
&& dictionary.Count == 0
+                               if (index > array.Length)
                                        throw new ArgumentException ("index 
larger than largest valid index of array");
                                if (array.Length - index < dictionary.Count)
                                        throw new ArgumentException 
("Destination array cannot hold the requested elements!");

Modified: trunk/mcs/class/corlib/Test/System.Collections.Generic/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Collections.Generic/ChangeLog    
2006-01-19 13:21:49 UTC (rev 55780)
+++ trunk/mcs/class/corlib/Test/System.Collections.Generic/ChangeLog    
2006-01-19 13:32:39 UTC (rev 55781)
@@ -1,3 +1,11 @@
+2006-01-19  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * DictionaryTest.cs: Remove NotWorking annotations.
+       (Empty_CopyTo, Empty_Values_CopyTo): Fix tests to check that
+       CopyTo from an empty dictionary does not throw an exception when
+       'index==array.Length'.
+       (PlainEnumeratorReturnTest): Check the type of 'Entry' property too.
+
 2006-01-19  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * DictionaryTest.cs : fixed several tests to not fail under .NET 2.0

Modified: 
trunk/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs    
2006-01-19 13:21:49 UTC (rev 55780)
+++ trunk/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs    
2006-01-19 13:32:39 UTC (rev 55781)
@@ -332,7 +332,6 @@
                }
        
                [Test]
-               [Category ("NotWorking")] // our code is based on 2.0 beta.
                public void IEnumeratorTest ()
                {
                        _dictionary.Add ("key1", "value1");
@@ -384,7 +383,6 @@
                }
        
                [Test]
-               [Category ("NotWorking")] // our code is based on 2.0 beta.
                public void ForEachTest ()
                {
                        _dictionary.Add ("key1", "value1");
@@ -394,23 +392,17 @@
        
                        int i = 0;
                        foreach (KeyValuePair <string, object> entry in 
_dictionary)
-                       {
                                i++;
-                       }
                        Assert.AreEqual(4, i, "fail1: foreach entry failed!");
        
                        i = 0;
                        foreach (KeyValuePair <string, object> entry in 
((IEnumerable)_dictionary))
-                       {
                                i++;
-                       }
                        Assert.AreEqual(4, i, "fail2: foreach entry failed!");
        
                        i = 0;
                        foreach (DictionaryEntry entry in 
((IDictionary)_dictionary))
-                       {
                                i++;
-                       }
                        Assert.AreEqual (4, i, "fail3: foreach entry failed!");
                }
        
@@ -496,7 +488,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")] // our code is based on 2.0 beta.
                public void PlainEnumeratorReturnTest ()
                {
                        // Test that we return a KeyValuePair even for 
non-generic dictionary iteration
@@ -504,8 +495,9 @@
                        IEnumerator<KeyValuePair<string, object>> enumerator = 
_dictionary.GetEnumerator();
                        Assert.IsTrue(enumerator.MoveNext(), "#1");
                        Assert.AreEqual (typeof (KeyValuePair<string,object>), 
((IEnumerator)enumerator).Current.GetType (), "#2");
-                       Assert.AreEqual (typeof (KeyValuePair<string,object>), 
((IDictionaryEnumerator)enumerator).Current.GetType (), "#3");
-                       Assert.AreEqual (typeof (KeyValuePair<string,object>), 
((object) enumerator.Current).GetType (), "#4");
+                       Assert.AreEqual (typeof (DictionaryEntry), 
((IDictionaryEnumerator)enumerator).Entry.GetType (), "#3");
+                       Assert.AreEqual (typeof (KeyValuePair<string,object>), 
((IDictionaryEnumerator)enumerator).Current.GetType (), "#4");
+                       Assert.AreEqual (typeof (KeyValuePair<string,object>), 
((object) enumerator.Current).GetType (), "#5");
                }
 
                [Test, ExpectedException (typeof (InvalidOperationException))]
@@ -614,11 +606,12 @@
                }
 
                [Test]
-               public void Empty_Values_CopyTo ()
+               public void Empty_KeysValues_CopyTo ()
                {
                        Dictionary<int, int> d = new Dictionary<int, int> ();
-                       int[] array = new int[10];
-                       d.Values.CopyTo (array, 0);
+                       int[] array = new int[1];
+                       d.Keys.CopyTo (array, array.Length);
+                       d.Values.CopyTo (array, array.Length);
                }
 
                [Test]
@@ -627,7 +620,11 @@
                        Dictionary<int, int> d = new Dictionary<int, int> ();
                        ICollection c = (ICollection) d;
                        DictionaryEntry [] array = new DictionaryEntry [1];
-                       c.CopyTo (array, 0);
+                       c.CopyTo (array, array.Length);
+
+                       ICollection<KeyValuePair<int,int>> c2 = d;
+                       KeyValuePair<int,int> [] array2 = new 
KeyValuePair<int,int> [1];
+                       c2.CopyTo (array2, array2.Length);
                }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to