2008-09-08 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index 9fce407fbdbbfa23fe07472240a68a976d2e4fea..a18f160201bb95edc5574edd1cf9b18216c93a61 100644 (file)
@@ -18,8 +18,6 @@ using System.Collections.Generic;
 
 namespace MonoTests.System
 {
-
-
        //Auxiliary Things
        enum enua  {hola,adios,mas,menos};
 
@@ -33,17 +31,26 @@ namespace MonoTests.System
 
        class BClass : AClass
        {
-    }
+       }
 
        class CClass : AClass
-    {
-    }
+       {
+       }
 
        struct AStruct
        {
                public string s;
                public string a;
        }
+       
+       class DataEqual
+       {
+               public override bool Equals (object obj)
+               {
+                       return true;
+               }
+       }
+               
        //End Auxiliary Things
 
 [TestFixture]
@@ -119,20 +126,16 @@ public class ArrayTest : Assertion
 
                {
                        char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
-                       Assert("#B05", 
-                              Array.BinarySearch(arr, 'c') >= 3);
-                       Assert("#B06", 
-                              Array.BinarySearch(arr, 'c') < 6);
+                       Assert("#B05", Array.BinarySearch(arr, 'c') >= 3);
+                       Assert("#B06", Array.BinarySearch(arr, 'c') < 6);
                }
                {
                        char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
-                       AssertEquals("#B07", 
-                                    -4, Array.BinarySearch(arr, 'c'));
+                       AssertEquals("#B07", -4, Array.BinarySearch(arr, 'c'));
                }
                {
                        char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
-                       AssertEquals("#B08", 
-                                    -9, Array.BinarySearch(arr, 'e'));
+                       AssertEquals("#B08", -9, Array.BinarySearch(arr, 'e'));
                }
        }
 
@@ -180,20 +183,16 @@ public class ArrayTest : Assertion
 
                {
                        char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
-                       Assert("#B26", 
-                              Array.BinarySearch(arr, 2, 8, 'c') >= 5);
-                       Assert("#B27", 
-                              Array.BinarySearch(arr, 2, 8, 'c') < 8);
+                       Assert("#B26", Array.BinarySearch(arr, 2, 8, 'c') >= 5);
+                       Assert("#B27", Array.BinarySearch(arr, 2, 8, 'c') < 8);
                }
                {
                        char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
-                       AssertEquals("#B28", 
-                                    -6, Array.BinarySearch(arr, 2, 8, 'c'));
+                       AssertEquals("#B28", -6, Array.BinarySearch(arr, 2, 8, 'c'));
                }
                {
                        char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
-                       AssertEquals("#B29", 
-                                    -11, Array.BinarySearch(arr, 2, 8, 'e'));
+                       AssertEquals("#B29", -11, Array.BinarySearch(arr, 2, 8, 'e'));
                }
        }
 
@@ -393,13 +392,11 @@ public class ArrayTest : Assertion
                char[] copy = new Char[4];
                Array.Copy(orig, copy, 4);
                for (int i = 0; i < orig.Length; i++) {
-                       AssertEquals("#E09(" + i + ")",
-                                    orig[i], copy[i]);
+                       AssertEquals("#E09(" + i + ")", orig[i], copy[i]);
                }
                Array.Clear(copy, 0, copy.Length);
                for (int i = 0; i < orig.Length; i++) {
-                       AssertEquals("#E10(" + i + ")",
-                                    (char)0, copy[i]);
+                       AssertEquals("#E10(" + i + ")", (char)0, copy[i]);
                }
                Array.Copy(orig, copy, 2);
                AssertEquals("#E11", orig[0], copy[0]);
@@ -438,8 +435,7 @@ public class ArrayTest : Assertion
                Array.Copy(orig, 1, copy, 1, 3);
                Assert("#E33", copy[0] != orig[0]);
                for (int i = 1; i < orig.Length; i++) {
-                       AssertEquals("#E34(" + i + ")",
-                                    orig[i], copy[i]);
+                       AssertEquals("#E34(" + i + ")", orig[i], copy[i]);
                }
                Array.Clear(copy, 0, copy.Length);
                Array.Copy(orig, 1, copy, 0, 2);
@@ -449,6 +445,17 @@ public class ArrayTest : Assertion
                Assert("#E38", copy[3] != orig[3]);
        }
 
+       [Test]
+       [ExpectedException (typeof (InvalidCastException))]
+       public void Copy_InvalidCast () {
+               object[] arr1 = new object [10];
+               Type[] arr2 = new Type [10];
+
+               arr1 [0] = new object ();
+
+               Array.Copy (arr1, 0, arr2, 0, 10);
+       }
+
        [Test]
        public void TestCopyTo() {
                {
@@ -470,6 +477,11 @@ public class ArrayTest : Assertion
                        } catch (ArgumentException) {
                                errorThrown = true;
                        }
+#if TARGET_JVM // This is really implementation dependent behaviour.
+                       catch (RankException) {
+                               errorThrown = true;
+                       }
+#endif // TARGET_JVM
                        Assert("#E62", errorThrown);
                }
                {
@@ -630,6 +642,7 @@ public class ArrayTest : Assertion
                        Assert("#F03b", errorThrown);
                }
 #endif
+#if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -639,6 +652,7 @@ public class ArrayTest : Assertion
                        }
                        Assert("#F04", errorThrown);
                }
+#endif // TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -649,6 +663,7 @@ public class ArrayTest : Assertion
                        }
                        Assert("#F05", errorThrown);
                }
+#if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -691,14 +706,15 @@ public class ArrayTest : Assertion
                Type szarrayType = new int [10].GetType ();
                Assert (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
                Assert (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
+#endif // TARGET_JVM
        }
        
        [Test]
-        [ExpectedException (typeof (ArgumentNullException))]
-        public void TestCreateInstance2 ()
-        {
-                Array a = Array.CreateInstance (typeof (Int32), (int[])null);
-        }
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void TestCreateInstance2 ()
+       {
+               Array.CreateInstance (typeof (Int32), (int[])null);
+       }
 
        [Test]
 #if NET_2_0
@@ -706,10 +722,10 @@ public class ArrayTest : Assertion
 #else
        [ExpectedException (typeof (NullReferenceException))]
 #endif
-        public void TestCreateInstance2b ()
-        {
-                Array a = Array.CreateInstance (typeof (Int32), (long[])null);
-        }
+       public void TestCreateInstance2b ()
+       {
+               Array.CreateInstance (typeof (Int32), (long[])null);
+       }
 
        [Test]
        public void TestGetEnumerator() {
@@ -765,6 +781,7 @@ public class ArrayTest : Assertion
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestGetEnumeratorNonZeroLowerBounds() {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -793,6 +810,7 @@ public class ArrayTest : Assertion
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_Add () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -800,19 +818,20 @@ public class ArrayTest : Assertion
                Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
                try {
                        ((IList)myArray).Add ("can not");
-                       Fail ("IList.Add should throw");    
+                       Fail ("IList.Add should throw");
                }
                catch (NotSupportedException) {
                        return;
                }
                catch (Exception) {
-                       Fail ("IList.Add threw wrong exception type");    
+                       Fail ("IList.Add threw wrong exception type");
                }
 
                Fail("IList.Add shouldn't get this far");
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_Insert () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -820,19 +839,20 @@ public class ArrayTest : Assertion
                Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
                try {
                        ((IList)myArray).Insert (0, "can not");
-                       Fail ("IList.Insert should throw");    
+                       Fail ("IList.Insert should throw");
                }
                catch (NotSupportedException) {
                        return;
                }
                catch (Exception) {
-                       Fail ("IList.Insert threw wrong exception type");    
+                       Fail ("IList.Insert threw wrong exception type");
                }
 
                Fail("IList.Insert shouldn't get this far");
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_Remove () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -840,19 +860,20 @@ public class ArrayTest : Assertion
                Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
                try {
                        ((IList)myArray).Remove ("can not");
-                       Fail ("IList.Remove should throw");    
+                       Fail ("IList.Remove should throw");
                }
                catch (NotSupportedException) {
                        return;
                }
                catch (Exception) {
-                       Fail ("IList.Remove threw wrong exception type");    
+                       Fail ("IList.Remove threw wrong exception type");
                }
 
                Fail("IList.Remove shouldn't get this far");
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_RemoveAt () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -860,19 +881,20 @@ public class ArrayTest : Assertion
                Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
                try {
                        ((IList)myArray).RemoveAt (0);
-                       Fail ("IList.RemoveAt should throw");    
+                       Fail ("IList.RemoveAt should throw");
                }
                catch (NotSupportedException) {
                        return;
                }
                catch (Exception) {
-                       Fail ("IList.RemoveAt threw wrong exception type");    
+                       Fail ("IList.RemoveAt threw wrong exception type");
                }
 
                Fail("IList.RemoveAt shouldn't get this far");
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_Contains () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -898,6 +920,7 @@ public class ArrayTest : Assertion
        }
 
        [Test]
+       [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
        public void TestIList_IndexOf () {
                int[] myLengthsArray = new int[2] { 3, 5 };
                int[] myBoundsArray = new int[2] { 2, 3 };
@@ -954,14 +977,11 @@ public class ArrayTest : Assertion
                }
 
                char[] c2 = new Char[5];
-               AssertEquals("#H03", 
-                            5, c2.GetLength(0));
+               AssertEquals("#H03", 5, c2.GetLength(0));
 
                char[,] c3 = new Char[6,7];
-               AssertEquals("#H04", 
-                            6, c3.GetLength(0));
-               AssertEquals("#H05", 
-                            7, c3.GetLength(1));
+               AssertEquals("#H04", 6, c3.GetLength(0));
+               AssertEquals("#H05", 7, c3.GetLength(1));
        }
 
        [Test]
@@ -988,14 +1008,11 @@ public class ArrayTest : Assertion
                }
 
                char[] c1 = new Char[5];
-               AssertEquals("#H33", 
-                            0, c1.GetLowerBound(0));
+               AssertEquals("#H33", 0, c1.GetLowerBound(0));
 
                char[,] c2 = new Char[4,4];
-               AssertEquals("#H34", 
-                            0, c2.GetLowerBound(0));
-               AssertEquals("#H35", 
-                            0, c2.GetLowerBound(1));
+               AssertEquals("#H34", 0, c2.GetLowerBound(0));
+               AssertEquals("#H35", 0, c2.GetLowerBound(1));
        }
 
        [Test]
@@ -1022,14 +1039,11 @@ public class ArrayTest : Assertion
                }
 
                char[] c1 = new Char[5];
-               AssertEquals("#H63", 
-                            4, c1.GetUpperBound(0));
+               AssertEquals("#H63", 4, c1.GetUpperBound(0));
 
                char[,] c2 = new Char[4,6];
-               AssertEquals("#H64", 
-                            3, c2.GetUpperBound(0));
-               AssertEquals("#H65", 
-                            5, c2.GetUpperBound(1));
+               AssertEquals("#H64", 3, c2.GetUpperBound(0));
+               AssertEquals("#H65", 5, c2.GetUpperBound(1));
        }
 
        [Test]
@@ -1113,7 +1127,7 @@ public class ArrayTest : Assertion
                for (int i = 0; i < c1.GetLength(0); i++) {
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                AssertEquals("#I24(" + i + "," + j + ")",
-                                            c1[i,j], c1.GetValue(i, j));
+                                       c1[i,j], c1.GetValue(i, j));
                        }
                }
        }
@@ -1163,7 +1177,7 @@ public class ArrayTest : Assertion
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                for (int k = 0; k < c1.GetLength(2); k++) {
                                        AssertEquals("#I44(" + i + "," + j + ")",
-                                                    c1[i,j,k], c1.GetValue(i,j,k));
+                                               c1[i,j,k], c1.GetValue(i,j,k));
                                }
                        }
                }
@@ -1237,7 +1251,7 @@ public class ArrayTest : Assertion
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                int[] coords = {i, j};
                                AssertEquals("#I65(" + i + "," + j + ")",
-                                            c1[i,j], c1.GetValue(coords));
+                                       c1[i,j], c1.GetValue(coords));
                        }
                }
        }
@@ -1362,6 +1376,16 @@ public class ArrayTest : Assertion
                AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
        }
        
+       [Test]
+       public void TestIndexOf_CustomEqual ()
+       {
+               DataEqual[] test = new DataEqual [] { new DataEqual () };
+               AssertEquals (0, Array.IndexOf (test, "asdfas", 0));
+               
+               IList array = (IList)test;
+               AssertEquals (0, array.IndexOf ("asdfas"));
+       }
+       
        [Test]
        public void TestLastIndexOf1() {
                {
@@ -1390,6 +1414,8 @@ public class ArrayTest : Assertion
                AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
                AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
                AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
+
+               AssertEquals (-1, Array.LastIndexOf (new String [0], "foo"));
        }
 
        [Test]
@@ -1475,44 +1501,47 @@ public class ArrayTest : Assertion
                }
 
                String[] s1 = {"this", "is", "really", "a", "test"};
-               AssertEquals("#K45", 
-                            -1, Array.LastIndexOf(s1, null, 3, 3));
-               AssertEquals("#K46", 
-                            -1, Array.LastIndexOf(s1, "nothing", 3, 3));
-               AssertEquals("#K47", 
-                            -1, Array.LastIndexOf(s1, "this", 3, 3));
-               AssertEquals("#K48",
-                            1, Array.LastIndexOf(s1, "is", 3, 3));
-               AssertEquals("#K49", 
-                            -1, Array.LastIndexOf(s1, "test", 3, 3));
-               AssertEquals("#K50", 
-                            3, Array.LastIndexOf(s1, "a", 3, 3));
-       }
-
-       [Test]
-        [ExpectedException (typeof (ArgumentOutOfRangeException))]
-        public void TestLastIndexOf4 ()
-        {
-                short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
-                Array.LastIndexOf (a, 16, -1);
-        }
-
-        [Test]
-        public void TestLastIndexOf5 ()
-        {
-                char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
-                string s;
-                int retval;
-                bool error = false;
-
-                for (int i = a.Length - 1; i >= 0 ; i--) {
-                        s = i.ToString ();
-                        retval = Array.LastIndexOf(a, a [i], i, i + 1);
-                        if (retval != i)
-                                error = true;
-                }
-                Assert (!error);
-        }
+               AssertEquals("#K45", -1, Array.LastIndexOf(s1, null, 3, 3));
+               AssertEquals("#K46", -1, Array.LastIndexOf(s1, "nothing", 3, 3));
+               AssertEquals("#K47", -1, Array.LastIndexOf(s1, "this", 3, 3));
+               AssertEquals("#K48", 1, Array.LastIndexOf(s1, "is", 3, 3));
+               AssertEquals("#K49", -1, Array.LastIndexOf(s1, "test", 3, 3));
+               AssertEquals("#K50", 3, Array.LastIndexOf(s1, "a", 3, 3));
+       }
+
+       [Test]
+       public void TestLastIndexOf4 ()
+       {
+               short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
+               try {
+                       Array.LastIndexOf (a, (object)16, -1);
+                       NUnit.Framework.Assert.Fail ("#1");
+               } catch (ArgumentOutOfRangeException) { }
+               
+#if NET_2_0            
+               try {
+                       Array.LastIndexOf<short> (a, 16, -1);
+                       NUnit.Framework.Assert.Fail ("#2");
+               } catch (ArgumentOutOfRangeException) { }
+#endif         
+       }
+
+       [Test]
+       public void TestLastIndexOf5 ()
+       {
+               char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
+               string s;
+               int retval;
+               bool error = false;
+
+               for (int i = a.Length - 1; i >= 0 ; i--) {
+                       s = i.ToString ();
+                       retval = Array.LastIndexOf(a, a [i], i, i + 1);
+                       if (retval != i)
+                               error = true;
+               }
+               Assert (!error);
+       }
 
        [Test]
        [ExpectedException (typeof (ArgumentOutOfRangeException))]
@@ -1727,7 +1756,7 @@ public class ArrayTest : Assertion
                for (int i = 0; i < c1.GetLength(0); i++) {
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                AssertEquals("#M24(" + i + "," + j + ")",
-                                            c1[i,j], c2[i, j]);
+                                       c1[i,j], c2[i, j]);
                        }
                }
        }
@@ -1779,7 +1808,7 @@ public class ArrayTest : Assertion
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                for (int k = 0; k < c1.GetLength(2); k++) {
                                        AssertEquals("#M44(" + i + "," + j + " )",
-                                                    c1[i,j,k], c2[i,j,k]);
+                                               c1[i,j,k], c2[i,j,k]);
                                }
                        }
                }
@@ -1855,7 +1884,7 @@ public class ArrayTest : Assertion
                for (int i = 0; i < c1.GetLength(0); i++) {
                        for (int j = 0; j < c1.GetLength(1); j++) {
                                AssertEquals("#M65(" + i + "," + j + ")",
-                                            c1[i,j], c2[i,j]);
+                                       c1[i,j], c2[i,j]);
                        }
                }
        }
@@ -2000,7 +2029,7 @@ public class ArrayTest : Assertion
                                        int ex_index = (i * types.Length) + j;
 
                                        AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
-                                                     errorThrown, arg_ex [ex_index] == 1);
+                                               errorThrown, arg_ex [ex_index] == 1);
                                }
                        }
 
@@ -2069,7 +2098,7 @@ public class ArrayTest : Assertion
                                        int ex_index = (i * types.Length) + j;
 
                                        AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
-                                                     errorThrown, arg_ex [ex_index] == 1);
+                                               errorThrown, arg_ex [ex_index] == 1);
                                }
                        }
 
@@ -2499,13 +2528,25 @@ public class ArrayTest : Assertion
                Array.Sort (arrsort, null, 0, arrsort.Length, null);
        }
 
-        [Test]
-        [ExpectedException (typeof (InvalidOperationException))]
-        public void MoreSort10 ()
-        {
-                object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
-                Array.Sort (array, (IComparer) null);
-        }
+       [Test]
+       [ExpectedException (typeof (InvalidOperationException))]
+       public void MoreSort10 ()
+       {
+               object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
+               Array.Sort (array, (IComparer) null);
+       }
+
+       [Test] // bug #81941
+       public void Sort ()
+       {
+               double [] a = new double [2] { 0.9, 0.3 };
+               uint [] b = new uint [2] { 4, 7 };
+               Array.Sort (a, b);
+               AssertEquals ("#1", 0.3, a [0]);
+               AssertEquals ("#2", 0.9, a [1]);
+               AssertEquals ("#3", 7, b [0]);
+               AssertEquals ("#4", 4, b [1]);
+       }
 
        [Test]
        public void ClearJaggedArray () 
@@ -2750,6 +2791,29 @@ public class ArrayTest : Assertion
                AssertEquals (45, sum);
        }
 
+       [Test]
+       public void Resize ()
+       {
+               int [] arr = new int [] { 1, 3, 5 };
+               Array.Resize <int> (ref arr, 3);
+               AssertEquals ("#A1", 3, arr.Length);
+               AssertEquals ("#A2", 1, arr [0]);
+               AssertEquals ("#A3", 3, arr [1]);
+               AssertEquals ("#A4", 5, arr [2]);
+
+               Array.Resize <int> (ref arr, 2);
+               AssertEquals ("#B1", 2, arr.Length);
+               AssertEquals ("#B2", 1, arr [0]);
+               AssertEquals ("#B3", 3, arr [1]);
+
+               Array.Resize <int> (ref arr, 4);
+               AssertEquals ("#C1", 4, arr.Length);
+               AssertEquals ("#C2", 1, arr [0]);
+               AssertEquals ("#C3", 3, arr [1]);
+               AssertEquals ("#C4", 0, arr [2]);
+               AssertEquals ("#C5", 0, arr [3]);
+       }
+
        [Test]
        public void Resize_null ()
        {
@@ -2771,19 +2835,44 @@ public class ArrayTest : Assertion
 
        public class EquatableClass : IEquatable<EquatableClass>
        {
-       int _x;
-       public EquatableClass (int x)
-       {
-               _x = x;
-       }
+               int _x;
+               public EquatableClass (int x)
+               {
+                       _x = x;
+               }
+
+               public bool Equals (EquatableClass other)
+               {
+                       return this._x == other._x;
+               }
+       }
+
+       [Test]
+       public void AsIList ()
+       {
+               IList<int> arr = new int [10];
+               arr [0] = 5;
+               AssertEquals (5, arr [0]);
+
+               IList<FooStruct> arr2 = new FooStruct [10];
+               FooStruct s = new FooStruct ();
+               s.i = 11;
+               s.j = 22;
+               arr2 [5] = s;
+               s = arr2 [5];
+               AssertEquals (11, s.i);
+               AssertEquals (22, s.j);
 
-       public bool Equals (EquatableClass other)
-       {
-               return this._x == other._x;
-       }
+               IList<string> arr3 = new string [10];
+               arr3 [5] = "ABC";
+               AssertEquals ("ABC", arr3 [5]);
+       }
 
+       struct FooStruct {
+               public int i, j;
        }
 
+#if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
        [Test]
        // From bug #80563
        public void ICollectionNull ()
@@ -2808,6 +2897,7 @@ public class ArrayTest : Assertion
                test = new List<object>(test);
                AssertEquals ("array with test", test.Contains (null), false);
        }
+#endif // TARGET_JVM
 #endif
 
        #region Bug 80299
@@ -2849,6 +2939,80 @@ public class ArrayTest : Assertion
        }
 
        #endregion
-}
 
+#if NET_2_0
+       [Test] // bug #322248
+       public void IEnumerator_Reset ()
+       {
+               int[] array = new int[] { 1, 2, 3};
+               IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+               Assert ("#A1", e.MoveNext ());
+               AssertEquals ("#A2", 1, e.Current);
+               Assert ("#A3", e.MoveNext ());
+               AssertEquals ("#A4", 2, e.Current);
+
+               e.Reset ();
+
+               Assert ("#C1", e.MoveNext ());
+               AssertEquals ("#C2", 1, e.Current);
+       }
+
+       [Test]
+       public void IEnumerator_Current_Finished ()
+       {
+               int[] array = new int[] { 1, 2, 3 };
+               IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+               Assert ("#A1", e.MoveNext ());
+               AssertEquals ("#A2", 1, e.Current);
+               Assert ("#A3", e.MoveNext ());
+               AssertEquals ("#A4", 2, e.Current);
+               Assert ("#A5", e.MoveNext ());
+               AssertEquals ("#A6", 3, e.Current);
+               Assert ("#A6", !e.MoveNext ());
+
+               try {
+                       Fail ("#B1:" + e.Current);
+               } catch (InvalidOperationException ex) {
+                       // Enumeration already finished
+                       AssertEquals ("#B2", typeof (InvalidOperationException), ex.GetType ());
+                       AssertNull ("#B3", ex.InnerException);
+                       AssertNotNull ("#B4", ex.Message);
+               }
+       }
+
+       [Test]
+       public void IEnumerator_Current_NotStarted ()
+       {
+               int[] array = new int[] { 1, 2, 3 };
+               IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+
+               try {
+                       Fail ("#A1:" + e.Current);
+               } catch (InvalidOperationException ex) {
+                       // Enumeration has not started. Call MoveNext
+                       AssertEquals ("#A2", typeof (InvalidOperationException), ex.GetType ());
+                       AssertNull ("#A3", ex.InnerException);
+                       AssertNotNull ("#A4", ex.Message);
+               }
+       }
+
+       [Test]
+       public void IEnumerator_Current_Reset ()
+       {
+               int[] array = new int[] { 1, 2, 3 };
+               IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+               e.MoveNext ();
+               e.Reset ();
+
+               try {
+                       Fail ("#B1:" + e.Current);
+               } catch (InvalidOperationException ex) {
+                       // Enumeration has not started. Call MoveNext
+                       AssertEquals ("#B2", typeof (InvalidOperationException), ex.GetType ());
+                       AssertNull ("#B3", ex.InnerException);
+                       AssertNotNull ("#B4", ex.Message);
+               }
+       }
+#endif
+}
 }