[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index b17968aad8487aa155d4d640719d3185ea6f4ce9..36db33d6352b9ac3efc47122a7897ed4289ea21d 100644 (file)
@@ -11,10 +11,8 @@ using NUnit.Framework;
 using System;
 using System.Collections;
 using System.Globalization;
-
-#if NET_2_0
+using System.Reflection;
 using System.Collections.Generic;
-#endif
 
 namespace MonoTests.System
 {
@@ -49,6 +47,11 @@ namespace MonoTests.System
                {
                        return true;
                }
+
+               public override int GetHashCode ()
+               {
+                       return 0;
+               }
        }
                
        //End Auxiliary Things
@@ -58,7 +61,21 @@ public class ArrayTest
 {
        char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
 
-       public ArrayTest() {}
+       interface I
+       {
+       }
+
+       class C
+       {
+       }
+
+       class DC : C
+       {
+       }
+
+       class DI : I
+       {
+       }
 
        [Test]
        public void TestIsFixedSize() {
@@ -222,7 +239,23 @@ public class ArrayTest
                Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null, null), "O=a,i,i,o,c");
        }
 
-       // TODO - testBinarySearch with explicit IComparer args
+       class TestComparer7 : IComparer<int>
+       {
+               public int Compare (int x, int y)
+               {
+                       if (y != 7)
+                               throw new ApplicationException ();
+
+                       return x.CompareTo (y);
+               }
+       }
+
+       [Test]
+       public void BinarySearch_WithComparer ()
+       {
+               var a = new int[] { 2, 6, 9 };
+               Assert.AreEqual (-3, Array.BinarySearch (a, 7, new TestComparer7 ()));
+       }
 
        [Test]
        public void TestClear() {
@@ -298,6 +331,15 @@ public class ArrayTest
                Assert.AreEqual (d1[0], d2[0], "#D07");
        }
 
+       [Test]
+       public void TestMemberwiseClone () {
+               int[] array = new int[] { 1, 2, 3 };
+               MethodBase mi = array.GetType ().GetMethod("MemberwiseClone",
+                                                                                                  BindingFlags.Instance | BindingFlags.NonPublic);
+               int[] res = (int[])mi.Invoke (array, null);
+               Assert.AreEqual (3, res.Length);
+       }
+
        [Test] public void TestIndexer ()
        {
                int [] a = new int [10];
@@ -460,14 +502,24 @@ public class ArrayTest
        }
 
        [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);
+               try {
+                       Array.Copy (arr1, 0, arr2, 0, 10);
+                       Assert.Fail ("#1");
+               } catch (InvalidCastException) {
+               }
+
+               var arr1_2 = new I [1] { new DI () };
+               var arr2_2 = new C [1] { new DC () };
+               try {
+                       Array.Copy (arr2_2, arr1_2, 1);
+                       Assert.Fail ("#1");
+               } catch (InvalidCastException) {
+               }
        }
 
        [Test]
@@ -491,11 +543,6 @@ public class ArrayTest
                        } catch (ArgumentException) {
                                errorThrown = true;
                        }
-#if TARGET_JVM // This is really implementation dependent behaviour.
-                       catch (RankException) {
-                               errorThrown = true;
-                       }
-#endif // TARGET_JVM
                        Assert.IsTrue (errorThrown, "#E62");
                }
                {
@@ -645,7 +692,7 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F03a");
                }
-#if NET_1_1
+
                {
                        bool errorThrown = false;
                        try {
@@ -655,8 +702,6 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F03b");
                }
-#endif
-#if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -666,7 +711,6 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F04");
                }
-#endif // TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -677,7 +721,6 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F05");
                }
-#if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
                {
                        bool errorThrown = false;
                        try {
@@ -720,7 +763,6 @@ public class ArrayTest
                Type szarrayType = new int [10].GetType ();
                Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
                Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
-#endif // TARGET_JVM
        }
        
        [Test]
@@ -731,16 +773,20 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestCreateInstance2b ()
        {
                Array.CreateInstance (typeof (Int32), (long[])null);
        }
 
+       [Test]
+       public void CreateInstanceVoid ()
+       {
+               Assert.Throws<NotSupportedException> (delegate () {
+                               Array.CreateInstance (typeof (void), 1);
+                       });
+       }
+
        [Test]
        public void TestGetEnumerator() {
                String[] s1 = {"this", "is", "a", "test"};
@@ -795,7 +841,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -824,7 +869,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -845,7 +889,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -866,7 +909,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -887,7 +929,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -908,7 +949,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -934,7 +974,6 @@ public class ArrayTest
        }
 
        [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 };
@@ -964,7 +1003,6 @@ public class ArrayTest
                int[] myBoundArray = new int[1] { Int32.MinValue };
                Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
                Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
-
        }
 
        [Test]
@@ -1196,11 +1234,7 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestGetValueLongArray ()
        {
                char[] c = new Char[2];
@@ -1529,12 +1563,10 @@ public class ArrayTest
                        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]
@@ -1601,6 +1633,126 @@ public class ArrayTest
                }
        }
 
+
+       [Test]
+       public void FindIndexTest ()
+       {
+               var a = new int[] { 2, 2, 2, 3, 2 };
+               Assert.AreEqual (2, Array.FindIndex (a, 2, 2, l => true));
+       }
+
+       [Test]
+       public void FindIndex_Invalid ()
+       {
+               var array = new int [] { 1, 2, 3, 4, 5 };
+
+               try {
+                       Array.FindIndex (array, null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException) {
+               }
+
+               try {
+                       Array.FindIndex (array, -1, l => true);
+                       Assert.Fail ("#2");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindIndex (array, -1, 0, l => true);
+                       Assert.Fail ("#2b");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindIndex (array, 0, -1, l => true);
+                       Assert.Fail ("#3");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindIndex (array, 100, l => true);
+                       Assert.Fail ("#4");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindIndex (array, 100, 0, l => true);
+                       Assert.Fail ("#4b");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindIndex (array, 7, 2, l => true);
+                       Assert.Fail ("#5");
+               } catch (ArgumentOutOfRangeException) {
+               }
+       }
+
+       [Test, ExpectedException (typeof (ArgumentNullException))]
+       public void FindLastNullTest ()
+       {
+               var array = new int [] { 1, 2, 3, 4, 5 };               
+               Array.FindLast (array, null);
+       }
+
+       [Test]
+       public void FindLastIndexTest ()
+       {
+               var array = new int [] { 1, 2, 3, 4, 5 };
+
+               Assert.AreEqual (2, Array.FindLastIndex (array, 2, 3, l => true));
+               Assert.AreEqual (2, Array.FindLastIndex (array, 2, 2, l => true));
+               Assert.AreEqual (1, Array.FindLastIndex (array, 1, 2, l => true));
+       }
+
+       [Test]
+       public void FindLastIndex_Invalid ()
+       {
+               var array = new int [] { 1, 2, 3, 4, 5 };
+               try {
+                       Array.FindLastIndex (array, null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, -1, l => true);
+                       Assert.Fail ("#2");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, -1, 0, l => true);
+                       Assert.Fail ("#2b");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, 0, -1, l => true);
+                       Assert.Fail ("#3");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, 100, l => true);
+                       Assert.Fail ("#4");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, 100, 0, l => true);
+                       Assert.Fail ("#4b");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       Array.FindLastIndex (array, 2, 4, l => true);
+                       Assert.Fail ("#5");
+               } catch (ArgumentOutOfRangeException) {
+               }
+       }
+
        [Test]
        public void TestReverse() {
                {
@@ -1678,6 +1830,25 @@ public class ArrayTest
                Assert.AreEqual ('d', c2[3], "#L14");
        }
 
+       [Test]
+       // #8904
+       public void ReverseStruct () {
+               BStruct[] c3 = new BStruct[2];
+               c3 [0] = new BStruct () { i1 = 1, i2 = 2, i3 = 3 };
+               c3 [1] = new BStruct () { i1 = 4, i2 = 5, i3 = 6 };
+               Array.Reverse (c3);
+               Assert.AreEqual (4, c3 [0].i1);
+               Assert.AreEqual (5, c3 [0].i2);
+               Assert.AreEqual (6, c3 [0].i3);
+               Assert.AreEqual (1, c3 [1].i1);
+               Assert.AreEqual (2, c3 [1].i2);
+               Assert.AreEqual (3, c3 [1].i3);
+       }
+
+       struct BStruct {
+               public int i1, i2, i3;
+       }
+
        [Test]
        public void TestSetValue1() {
                {
@@ -1853,11 +2024,7 @@ public class ArrayTest
        }
 
        [Test]
-#if NET_2_0
        [ExpectedException (typeof (ArgumentNullException))]
-#else
-       [ExpectedException (typeof (NullReferenceException))]
-#endif
        public void TestSetValueLongArray ()
        {
                char[] c = new Char[2];
@@ -2306,6 +2473,133 @@ public class ArrayTest
                        Assert.AreEqual (3, i1[4], "#N91");
                        Assert.AreEqual (6, i1[5], "#N92");
                }
+
+               {
+                       // #648828
+                       double[] a = new double[115];
+                       int[] b = new int[256];
+                       Array.Sort<double, int> (a, b, 0, 115);
+               }
+
+               /* Check that ulong[] is not sorted as long[] */
+               {
+                       string[] names = new string[] {
+                               "A", "B", "C", "D", "E"
+                       };
+
+                       ulong[] arr = new ulong [] {
+                               5,
+                               unchecked((ulong)0xffffFFFF00000000),
+                                       0,
+                                               0x7FFFFFFFffffffff,
+                                               100
+                                               };
+
+                       Array a = arr;
+                       Array.Sort (a, names, null);
+                       Assert.AreEqual (0, a.GetValue (0));
+               }
+       }
+
+       [Test]
+       public void Sort_NullValues ()
+       {
+               var s = new [] { "a", null, "b", null };
+               Array.Sort (s, (a, b) => {
+                       if (a == null) {
+                               return b == null ? 0 : 1;
+                       }
+
+                       if (b == null)
+                               return -1;
+
+                       return a.CompareTo (b);
+               });
+
+               Assert.AreEqual ("a", s [0], "#1");
+               Assert.AreEqual ("b", s [1], "#2");
+               Assert.IsNull (s [2], "#3");
+               Assert.IsNull (s [3], "#4");
+       }
+
+       [Test] // #616416
+       public void SortNonGenericDoubleItems () {
+            double[] doubleValues = new double[11];
+
+                       doubleValues[0] = 0.221788066253601;
+                       doubleValues[1] = 0.497278285809481;
+                       doubleValues[2] = 0.100565033883643;
+                       doubleValues[3] = 0.0433309347749905;
+                       doubleValues[4] = 0.00476726438463812;
+                       doubleValues[5] = 0.1354609735456;
+                       doubleValues[6] = 0.57690356588135;
+                       doubleValues[7] = 0.466239434334826;
+                       doubleValues[8] = 0.409741461978934;
+                       doubleValues[9] = 0.0112412763949565;
+                       doubleValues[10] = 0.668704347674307;
+
+            int[] indices = new int[11];
+            indices[0] = 0;
+            indices[1] = 1;
+            indices[2] = 2;
+            indices[3] = 3;
+            indices[4] = 4;
+            indices[5] = 5;
+            indices[6] = 6;
+            indices[7] = 7;
+            indices[8] = 8;
+            indices[9] = 9;
+            indices[10] = 10;
+
+                       Array.Sort ((Array)doubleValues, (Array)indices);
+                       Assert.AreEqual (4, indices [0]);
+       }
+
+       [Test]
+       public void TestSortComparable()
+       {
+               int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+               int[] expected = { 6, 5, 4, 3, 2, 1, 7, 8, 9 };
+               Comp[] c = { new Comp (100), new Comp (16), new Comp (11), new Comp (9), new Comp (0), new Comp (-100) };
+               IComparer<Comp> comp = null;
+               Array.Sort<Comp, int> (c, source, comp);
+
+               Assert.AreEqual (expected, source);
+       }
+
+       class Comp : IComparable
+       {
+               readonly int val;
+
+               public Comp (int a)
+               {
+                       val = a;
+               }
+
+               int IComparable.CompareTo (object obj)
+               {
+                       return val.CompareTo ((obj as Comp).val);
+               }
+       }
+
+       [Test]
+       public void TestSortComparableMixed()
+       {
+               var m = new TestSortComparableMixed_Comparer ();
+               var arr = new object [] { 1, 2, m, 4, 5, 6, 7, 8, 9, 10 };
+
+               Array.Sort (arr);
+
+               var expected = new object [] { m, 1, 2, 4, 5, 6, 7, 8, 9, 10 };
+               Assert.AreEqual (expected, arr);
+       }
+
+       class TestSortComparableMixed_Comparer : IComparable
+       {
+               public int CompareTo (object other)
+               {
+                       return -1;
+               }
        }
 
        [Test]
@@ -2756,7 +3050,6 @@ public class ArrayTest
                Assert.IsTrue (!comparer.Called, "Called");
        }
 
-#if NET_2_0
        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void AsReadOnly_NullArray ()
@@ -2826,6 +3119,22 @@ public class ArrayTest
                Assert.AreEqual (45, sum);
        }
 
+       [Test]
+       public void ReadOnly_CopyTo ()
+       {
+               int[] arr = new int [2];
+               arr [0] = 3;
+               arr [1] = 5;
+               IList<int> a = Array.AsReadOnly (arr);
+
+               int[] arr2 = new int [3];
+               a.CopyTo (arr2, 1);
+
+               Assert.AreEqual (0, arr2 [0]);
+               Assert.AreEqual (3, arr2 [1]);
+               Assert.AreEqual (5, arr2 [2]);
+       }
+
        [Test]
        public void Resize ()
        {
@@ -2907,7 +3216,6 @@ public class ArrayTest
                public int i, j;
        }
 
-#if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
        [Test]
        // From bug #80563
        public void ICollectionNull ()
@@ -2923,6 +3231,9 @@ public class ArrayTest
                test = new object[] {null};
                Assert.AreEqual (test.Contains (null), true, "array with null");
 
+               test = new object[] { 1, null};
+               Assert.IsTrue (test.Contains (null), "array with last null");
+               
                test = new List<object>(test);
                Assert.AreEqual (test.Contains (null), true, "List<object> with test");
                
@@ -2932,8 +3243,34 @@ public class ArrayTest
                test = new List<object>(test);
                Assert.AreEqual (test.Contains (null), false, "array with test");
        }
-#endif // TARGET_JVM
-#endif
+       
+       [Test]
+       public void IListNull ()
+       {
+               IList<object> test;
+               
+               test = new List<object>();
+               Assert.AreEqual (-1, test.IndexOf (null), "list<o>");
+
+               test = new object[] {};
+               Assert.AreEqual (-1, test.IndexOf (null), "empty array");
+
+               test = new object[] {null};
+               Assert.AreEqual (0, test.IndexOf (null), "array with null");
+
+               test = new object[] { 1, null};
+               Assert.AreEqual (1, test.IndexOf (null), "array with last null");
+               
+               test = new List<object>(test);
+               Assert.AreEqual (1, test.IndexOf (null), "List<object> with test");
+               
+               test = new object[] {new object()};
+               Assert.AreEqual (-1, test.IndexOf (null), "array with object");
+
+               test = new List<object>(test);
+               Assert.AreEqual (-1, test.IndexOf (null), "array with test");
+       }
+       
 
        #region Bug 80299
 
@@ -2975,7 +3312,6 @@ public class ArrayTest
 
        #endregion
 
-#if NET_2_0
        [Test] // bug #322248
        public void IEnumerator_Reset ()
        {
@@ -3049,12 +3385,35 @@ public class ArrayTest
                }
        }
 
+       [Test]
+       public void IEnumerator_Dispose ()
+       {
+               IEnumerable<int> e = new int[] { 1 };
+               var en = e.GetEnumerator ();
+               Assert.IsTrue (en.MoveNext (), "#1");
+               Assert.IsFalse (en.MoveNext (), "#2");
+               en.Dispose ();
+               Assert.IsFalse (en.MoveNext (), "#3");
+       }
+
+       [Test]
+       public void IEnumerator_ZeroSize ()
+       {
+               IEnumerable<int> e = Array.Empty<int> ();
+               var en = e.GetEnumerator ();
+               Assert.IsFalse (en.MoveNext (), "#1");
+
+               e = Array.Empty<int> ();
+               en = e.GetEnumerator ();
+               Assert.IsFalse (en.MoveNext (), "#2");
+       }
+
+       [Test]
        public void ICollection_IsReadOnly() {
                ICollection<string> arr = new string [10];
 
                Assert.IsTrue (arr.IsReadOnly);
        }
-#endif
 
        [Test]
        [ExpectedException (typeof (NotSupportedException))]
@@ -3071,5 +3430,312 @@ public class ArrayTest
        {
                Array.CreateInstance (typeof (Foo<>), 42);
        }
+
+       [Test]
+       [ExpectedException (typeof (IndexOutOfRangeException))]
+       public void ClearNegativeLength ()
+       {
+               Array.Clear (new int [] { 1, 2 }, 0, -1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void MultiDimension_IList_setItem ()
+       {
+               IList array = new int [1, 1];
+               array [0] = 2;
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void MultiDimension_IList_getItem ()
+       {
+               IList array = new int [1, 1];
+               int a = (int) array [0];
+       }
+
+       [Test]
+       public void SetValue_Nullable () {
+               Array array = Array.CreateInstance (typeof (int?), 7);
+
+               object o = 42;
+
+               array.SetValue (o, 0);
+               Assert.AreEqual (42, array.GetValue (0));
+
+               array.SetValue (null, 0);
+               Assert.AreEqual (null, array.GetValue (0));
+       }
+
+       [Test]
+       public void SortNullsWithGenericVersion ()
+       {
+            string[] s1 = new string[6]{
+               "J",
+                "M",
+                 null,
+                "P",
+                "T",
+                "A"};
+
+            string[] s2 = new string[]{null,
+                "A",
+                "J",
+                "M",
+                "P",
+                "T"};
+
+           Array.Sort<string> (s1);
+            for (int i = 0; i < 6; i++) {
+                   Assert.AreEqual (s1[i], s2[i], "At:" + i);
+            }
+       }
+       
+       //
+       // This is a test case for the case that was broken by the code contributed
+       // for bug  #351638.
+       //
+       // This tests the fix for: #622101
+       //
+       [Test]
+       public void SortActuallyWorks ()
+       {
+               string[] data = new string[9]{"Foo", "Bar", "Dingus", null, "Dingu4", "123", "Iam", null, "NotNull"};
+               IComparer comparer = new NullAtEndComparer ();
+               Array.Sort (data, comparer);
+
+               Assert.AreEqual (data [7], null);
+               Assert.AreNotEqual (data [0], null);
+       }
+
+       class NullAtEndComparer : IComparer {
+               public int Compare(object x, object y)
+               {
+                       if (x == null) return 1;
+                       if (y == null) return -1;
+                       return ((string)x).CompareTo((string)y);
+               }
+       }
+
+       [Test] //bxc #11184
+       public void UnalignedArrayClear ()
+       {
+               byte[] input = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+               byte[] expected = new byte[] { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+               Array.Clear (input, 5, 11);
+               
+               Assert.AreEqual (input, expected);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithJaggedArray () {
+               IStructuralComparable a = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
+               IStructuralComparable b = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithArrayOfTheWrongKind () {
+               IStructuralComparable a = new int[] { 1, 2 };
+               IStructuralComparable b = new double[] { 1, 2 };
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithNonArrayType () {
+               IStructuralComparable a = new int[] { 1, 2 };
+               a.CompareTo (99, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithNonArrayOfDifferentSize () {
+               IStructuralComparable a = new int[] { 1, 2 };
+               IStructuralComparable b = new int[] { 1, 2, 3 };
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithMultiDimArray1 () {
+               IStructuralComparable a = new int [2,2] { {10, 10 }, { 10, 10 } };
+               IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithMultiDimArray2 () {
+               IStructuralComparable a = new int [2] { 10, 10 };
+               IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void CompareToWithMultiDimArray3 () {
+               IStructuralComparable a = new int [4] { 10, 10, 10, 10 };
+               IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (IndexOutOfRangeException))]
+       public void CompareToWithBoundedArray1 () {
+               IStructuralComparable a = new int [2] { 10, 10 };
+               Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
+               IStructuralComparable b = ab;
+               ab.SetValue (10, 5);
+               ab.SetValue (10, 6);
+
+               a.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (IndexOutOfRangeException))]
+       public void CompareToWithBoundedArray2 () {
+               IStructuralComparable a = new int [2] { 10, 10 };
+               Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
+               IStructuralComparable b = ab;
+               ab.SetValue (10, 5);
+               ab.SetValue (10, 6);
+
+               //Yes, CompareTo simply doesn't work with bounded arrays!
+               b.CompareTo (b, Comparer<object>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (NullReferenceException))]
+       public void CompareToWithNullComparer () {
+               IStructuralComparable a = new int[] { 1, 2 };
+               IStructuralComparable b = new int[] { 1, 2 };
+               a.CompareTo (b, null);
+       }
+
+       [Test]
+       public void CompareToWithNullArray () {
+               IStructuralComparable a = new int[] { 1, 2 };
+               Assert.AreEqual (1, a.CompareTo (null, Comparer<object>.Default));
+       }
+
+       [Test]
+       public void CompareToWithGoodArrays () {
+               IStructuralComparable a = new int[] { 10, 20 };
+               Assert.AreEqual (0, a.CompareTo (a, Comparer<object>.Default));
+               Assert.AreEqual (0, a.CompareTo (new int [] { 10, 20 }, Comparer<object>.Default));
+               Assert.AreEqual (-1, a.CompareTo (new int [] { 11, 20 }, Comparer<object>.Default));
+               Assert.AreEqual (-1, a.CompareTo (new int [] { 10, 21 }, Comparer<object>.Default));
+               Assert.AreEqual (1, a.CompareTo (new int [] { 9, 20 }, Comparer<object>.Default));
+               Assert.AreEqual (1, a.CompareTo (new int [] { 10, 19 }, Comparer<object>.Default));
+       }
+
+       [Test]
+       public void IStructuralEquatable_Equals ()
+       {
+               IStructuralEquatable array = new int[] {1, 2, 3};
+               IStructuralEquatable array2 = new int[] {1, 2, 3};
+               Assert.AreEqual (false, array.Equals (null, null));
+               Assert.AreEqual (true, array.Equals (array, null));
+               Assert.AreEqual (true, array.Equals (array2, EqualityComparer<int>.Default));
+       }
+
+       [Test]
+       [ExpectedException (typeof (NullReferenceException))]
+       public void IStructuralEquatable_Equals_NoComparer ()
+       {
+               IStructuralEquatable array = new int[] {1, 2, 3};
+               IStructuralComparable array2 = new int[] {1, 2, 3};
+               array.Equals (array2, null);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void IStructuralEquatable_Equals_ComparerThrows ()
+       {
+               IStructuralEquatable array = new int[] {1, 2, 3};
+               IStructuralComparable array2 = new int[] {1, 2, 3};
+               array.Equals (array2, EqualityComparer<long>.Default);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]    
+       public void IStructuralEquatable_GetHashCode_NullComparer ()
+       {
+               IStructuralEquatable a = new int[] { 1, 2 };
+               a.GetHashCode (null);
+       }
+
+       class TestComparer_GetHashCode : IEqualityComparer
+       {
+               public int Counter;
+
+               bool IEqualityComparer.Equals (object x, object y)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public int GetHashCode (object obj)
+               {
+                       return Counter++;
+               }
+       }
+
+       [Test]
+       public void IStructuralEquatable_GetHashCode ()
+       {
+               IStructuralEquatable a = new int[] { 1, 2, 9 };
+
+               var c = new TestComparer_GetHashCode ();
+               a.GetHashCode (c);
+               Assert.AreEqual (3, c.Counter);         
+       }
+
+       [Test]
+       public void EnumeratorsEquality ()
+       {
+               int [] normalBase = new int [0];
+               IEnumerable<int> specialBase = new int [0];
+
+               var firstSpecial = specialBase.GetEnumerator ();
+               var secondSpecial = specialBase.GetEnumerator ();
+               var firstNormal = normalBase.GetEnumerator ();
+               var secondNormal = normalBase.GetEnumerator ();
+
+               Assert.IsFalse (object.ReferenceEquals (firstNormal, secondNormal));
+               Assert.IsTrue (object.ReferenceEquals (firstSpecial, secondSpecial));
+       }
+
+       [Test]
+       public void JaggedArrayCtor ()
+       {
+        var type = Type.GetType ("System.Object[][]");
+
+               ConstructorInfo ctor = null;
+        foreach (var c in type.GetConstructors ()) {
+                       if (c.GetParameters ().Length == 2)
+                               ctor = c;
+               }
+               Assert.IsNotNull (ctor);
+               var arr = (object[])ctor.Invoke (new object [] { 4, 10 });
+               for (int i = 0; i < 4; ++i) {
+                       Assert.IsNotNull (arr [i]);
+                       Assert.AreEqual (10, ((object[])arr [i]).Length);
+               }
+       }
+
+       [Test]
+       public unsafe void PointerArraysBoxing ()
+       {
+               var x = new int*[10];
+               var e = x.GetEnumerator ();
+               e.MoveNext ();
+
+               Assert.Throws<NotSupportedException> (() => { var _ = e.Current; }, "#1");
+               Assert.Throws<NotSupportedException> (() => { var _ = x.GetValue (0); }, "#2");
+               Assert.Throws<NotSupportedException> (() => { x.SetValue (0, 0); }, "#3");
+       }
 }
 }