Author: benm
Date: 2005-05-07 12:15:33 -0400 (Sat, 07 May 2005)
New Revision: 44201
Modified:
trunk/mcs/class/corlib/System/Array.cs
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/Test/System/ArrayTest.cs
trunk/mcs/class/corlib/Test/System/ChangeLog
Log:
In System:
2005-05-07 Ben Maurer <[EMAIL PROTECTED]>
* Array.cs (BinarySearch): Patch from kazuki to pass arguments to
the comparer in the same order as msft. Fixes #70725
In Test/System:
2005-05-07 Ben Maurer <[EMAIL PROTECTED]>
* ArrayTest.cs: Test for #70725.
Modified: trunk/mcs/class/corlib/System/Array.cs
===================================================================
--- trunk/mcs/class/corlib/System/Array.cs 2005-05-07 16:11:07 UTC (rev
44200)
+++ trunk/mcs/class/corlib/System/Array.cs 2005-05-07 16:15:33 UTC (rev
44201)
@@ -636,11 +636,11 @@
int iMid = (iMin + iMax) / 2;
object elt = array.GetValueImpl (iMid);
- iCmp = comparer.Compare (value, elt);
+ iCmp = comparer.Compare (elt, value);
if (iCmp == 0)
return iMid;
- else if (iCmp < 0)
+ else if (iCmp > 0)
iMax = iMid - 1;
else
iMin = iMid + 1; // compensate
for the rounding down
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2005-05-07 16:11:07 UTC (rev
44200)
+++ trunk/mcs/class/corlib/System/ChangeLog 2005-05-07 16:15:33 UTC (rev
44201)
@@ -1,3 +1,8 @@
+2005-05-07 Ben Maurer <[EMAIL PROTECTED]>
+
+ * Array.cs (BinarySearch): Patch from kazuki to pass arguments to
+ the comparer in the same order as msft. Fixes #70725
+
2005-05-06 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Enum.cs: the hashtable don't need to be synchronized any more, since
Modified: trunk/mcs/class/corlib/Test/System/ArrayTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ArrayTest.cs 2005-05-07 16:11:07 UTC
(rev 44200)
+++ trunk/mcs/class/corlib/Test/System/ArrayTest.cs 2005-05-07 16:15:33 UTC
(rev 44201)
@@ -2585,7 +2585,36 @@
byte[] array = new byte [16];
Array.Reverse (array, 8, Int32.MaxValue);
}
+
+ public struct CharX : IComparable {
+ public char c;
+
+ public CharX (char c)
+ {
+ this.c = c;
+ }
+
+ public int CompareTo (object obj)
+ {
+ if (obj is CharX)
+ return c.CompareTo (((CharX) obj).c);
+ else
+ return c.CompareTo (obj);
+ }
+ }
+ [Test]
+ public void BinarySearch_ArgPassingOrder ()
+ {
+ //
+ // This tests that arguments are passed to the comprer in the
correct
+ // order. The IComparable of the *array* elements must get
called, not
+ // that of the search object.
+ //
+ CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX
('c') };
+ AssertEquals (1, Array.BinarySearch (x, 'b'));
+ }
+
#if NET_2_0
[Test]
[ExpectedException (typeof (ArgumentNullException))]
Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog 2005-05-07 16:11:07 UTC
(rev 44200)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog 2005-05-07 16:15:33 UTC
(rev 44201)
@@ -1,3 +1,7 @@
+2005-05-07 Ben Maurer <[EMAIL PROTECTED]>
+
+ * ArrayTest.cs: Test for #70725.
+
2005-04-23 Zoltan Varga <[EMAIL PROTECTED]>
* MathTest.cs: Add new rounding test.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches