Fixes the enumerator for SortedList.
authorDuncan Mak <duncan@mono-cvs.ximian.com>
Sat, 14 Jun 2003 04:37:26 +0000 (04:37 -0000)
committerDuncan Mak <duncan@mono-cvs.ximian.com>
Sat, 14 Jun 2003 04:37:26 +0000 (04:37 -0000)
2003-06-13  Herve Poussineau  <hpoussineau@fr.st>

* SortedList.cs: Can enumerate on DictionaryEntries, not only on
keys on values. Enumerate by default on DictionaryEntries.

2003-06-14  Duncan Mak  <duncan@ximian.com>

* SortedListTest.cs
(TestIndexer):
(TestEnumerator): Incorporated these two tests from Philippe
Lavoie <philippe.lavoie@cactus.ca>.

svn path=/trunk/mcs/; revision=15376

mcs/class/corlib/System.Collections/ChangeLog
mcs/class/corlib/System.Collections/SortedList.cs
mcs/class/corlib/Test/System.Collections/ChangeLog
mcs/class/corlib/Test/System.Collections/SortedListTest.cs

index 75fd53a40cd8e2feb345c1c7a63bb742051ec2c4..de43f6ebc8134081d254aa22e5fc5e7bd1c07800 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-13  Herve Poussineau  <hpoussineau@fr.st>
+
+       * SortedList.cs: Can enumerate on DictionaryEntries, not only on
+       keys on values. Enumerate by default on DictionaryEntries.
+
 2003-06-12  Duncan Mak  <duncan@ximian.com>
 
        * Hashtable.cs (constructor):
index 345767273c28985a5f539c41a58ab3d98521a64d..da88fc5a7e4f40cf9d200c423169d25c0ff5d2a9 100644 (file)
@@ -3,6 +3,8 @@
 // \r
 // Author:\r
 //   Sergey Chaban (serge@wildwestsoftware.com)\r
+//   Duncan Mak (duncan@ximian.com)\r
+//   Herve Poussineau (hpoussineau@fr.st\r
 // \r
 \r
 \r
@@ -29,7 +31,7 @@ namespace System.Collections {
 \r
                private readonly static int INITIAL_SIZE = 16;\r
 \r
-               public enum EnumeratorMode : int {KEY_MODE = 0, VALUE_MODE}\r
+               public enum EnumeratorMode : int { KEY_MODE = 0, VALUE_MODE, ENTRY_MODE }\r
 \r
                private int inUse;\r
                private int modificationCount;\r
@@ -196,7 +198,7 @@ namespace System.Collections {
 \r
                IEnumerator IEnumerable.GetEnumerator ()\r
                {\r
-                       return new Enumerator (this, EnumeratorMode.KEY_MODE);\r
+                       return new Enumerator (this, EnumeratorMode.ENTRY_MODE);\r
                }\r
 \r
 \r
@@ -230,7 +232,7 @@ namespace System.Collections {
 \r
                public virtual IDictionaryEnumerator GetEnumerator ()\r
                {\r
-                       return new Enumerator (this, EnumeratorMode.KEY_MODE);\r
+                       return new Enumerator (this, EnumeratorMode.ENTRY_MODE);\r
                }\r
 \r
                public virtual void Remove (object key)\r
@@ -585,7 +587,7 @@ namespace System.Collections {
 \r
                        private object currentKey;\r
                        private object currentValue;\r
-                               \r
+\r
                        bool invalid = false;\r
 \r
                        private readonly static string xstr = "SortedList.Enumerator: snapshot out of sync.";\r
@@ -600,7 +602,7 @@ namespace System.Collections {
                        }\r
 \r
                        public Enumerator (SortedList host)\r
-                       : this (host, EnumeratorMode.KEY_MODE)\r
+                       : this (host, EnumeratorMode.ENTRY_MODE)\r
                        {\r
                        }\r
 \r
@@ -665,10 +667,18 @@ namespace System.Collections {
                                get {\r
                                        if (invalid || pos >= size || pos == -1)\r
                                                throw new InvalidOperationException (xstr);\r
-                                       \r
-                                       return (mode == EnumeratorMode.KEY_MODE)\r
-                                               ? currentKey\r
-                                               : currentValue;\r
+\r
+                                       switch (mode) {\r
+                                        case EnumeratorMode.KEY_MODE:\r
+                                                return currentKey;\r
+                                        case EnumeratorMode.VALUE_MODE:\r
+                                                return currentValue;\r
+                                        case EnumeratorMode.ENTRY_MODE:\r
+                                                return this.Entry;\r
+\r
+                                        default:\r
+                                                throw new NotSupportedException (mode + " is not a supported mode.");\r
+                                        }\r
                                }\r
                        }\r
                }\r
index 008ac60485ff33e422b6132613e634b1b22953b3..937d1033e8f7cba5ca834ce660df2d8645534aa9 100644 (file)
@@ -1,3 +1,10 @@
+2003-06-14  Duncan Mak  <duncan@ximian.com>
+
+       * SortedListTest.cs
+       (TestIndexer):
+       (TestEnumerator): Incorporated these two tests from Philippe
+       Lavoie <philippe.lavoie@cactus.ca>.
+
 2003-06-12  Duncan Mak  <duncan@ximian.com>
 
        * HashtableTest.cs: Converted it to the new style of NUnit tests.
index 780597470f22fbbd045e248a7d8f4f7297096d0d..6176a79fb4b46d90cf9b89de9b7d110e772ec927 100755 (executable)
@@ -599,6 +599,54 @@ public class SortedListTest : Assertion {
                 AssertEquals (1, -i);\r
         }\r
 \r
+        [Test]\r
+        public void TestIndexer ()\r
+        {\r
+                SortedList list = new SortedList ();\r
+\r
+                list.Add (1, new Queue ());\r
+                list.Add (2, new Hashtable ());\r
+                list.Add (3, new Stack ());\r
+\r
+                AssertEquals (typeof (Queue), list [1].GetType ());\r
+                AssertEquals (typeof (Hashtable), list [2].GetType ());\r
+                AssertEquals (typeof (Stack), list [3].GetType ());                \r
+        }\r
+\r
+        [Test]\r
+        public void TestEnumerator ()\r
+        {\r
+                SortedList list = new SortedList ();\r
+\r
+                list.Add (1, new Queue ());\r
+                list.Add (2, new Hashtable ());\r
+                list.Add (3, new Stack ());\r
+\r
+                foreach (DictionaryEntry d in list) {\r
+\r
+                        int key = (int) d.Key;\r
+                        Type value = d.Value.GetType ();\r
+\r
+                        switch (key) {\r
+                        case 1:\r
+                                AssertEquals (typeof (Queue), value);\r
+                                break;\r
+\r
+                        case 2:\r
+                                AssertEquals (typeof (Hashtable), value);\r
+                                break;\r
+\r
+                        case 3:\r
+                                AssertEquals (typeof (Stack), value);\r
+                                break;\r
+\r
+                        default:\r
+                                Fail ("This is incorrect: " + value.FullName);\r
+                                break;\r
+                        }\r
+                }\r
+        }\r
+\r
         [Test]\r
        public void TestRemove() {\r
                SortedList sl1 = new SortedList(24);\r