Merge remote-tracking branch 'joncham/sgen-msvc2'
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
index f53eb6dd25d062f8fed18b780db13b1e027bd2dd..a3acee11f30a3de19dc10edc58888573123cdf74 100644 (file)
@@ -225,7 +225,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() {
@@ -657,7 +673,7 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F03a");
                }
-#if NET_1_1
+
                {
                        bool errorThrown = false;
                        try {
@@ -667,7 +683,6 @@ public class ArrayTest
                        }
                        Assert.IsTrue (errorThrown, "#F03b");
                }
-#endif
 #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
                {
                        bool errorThrown = false;
@@ -3392,6 +3407,39 @@ public class ArrayTest
                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);         
+       }
+
 #endif
 
 }