Equality structural comparer needs to do recursive comparisons. Fixes #13110
authorMarek Safar <marek.safar@gmail.com>
Tue, 9 Jul 2013 09:12:33 +0000 (11:12 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 9 Jul 2013 09:12:33 +0000 (11:12 +0200)
mcs/class/corlib/System.Collections/StructuralComparisons.cs
mcs/class/corlib/Test/System.Collections/StructuralComparisonsTest.cs [new file with mode: 0644]
mcs/class/corlib/corlib_test.dll.sources

index d738574dc41d1319412ed6f43e725b2d5203b11b..9ce2574ebb18bb71eae8d5c98784f15f7d537702 100644 (file)
@@ -45,7 +45,7 @@ namespace System.Collections
 
                        int IEqualityComparer.GetHashCode (object obj)
                        {
-                               var comparer = obj as IEqualityComparer;
+                               var comparer = obj as IStructuralEquatable;
                                if (comparer != null)
                                        return comparer.GetHashCode (this);
 
@@ -54,7 +54,7 @@ namespace System.Collections
 
                        bool IEqualityComparer.Equals (object x, object y)
                        {
-                               var comparer = x as IEqualityComparer;
+                               var comparer = x as IStructuralEquatable;
                                if (comparer != null)
                                        return comparer.Equals (y, this);
 
diff --git a/mcs/class/corlib/Test/System.Collections/StructuralComparisonsTest.cs b/mcs/class/corlib/Test/System.Collections/StructuralComparisonsTest.cs
new file mode 100644 (file)
index 0000000..38c9ace
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// StructuralComparisonsTest.cs
+//
+// Authors:
+//     Marek Safar  <marek.safar@gmail.com>
+//
+// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_0
+
+using System.Collections;
+using NUnit.Framework;
+
+namespace MonoTests.System.Collections
+{
+       [TestFixture]
+       public class StructuralComparisonsTest
+       {
+               [Test]
+               public void EqualsTest ()
+               {
+                       int[] a1 = new[] { 9, 1, 3, 4 };
+                       int[] a2 = new[] { 9, 1, 3, 4 };
+
+                       Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (a1, a2), "#1");
+                       Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (null, a2), "#2");
+                       Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (a1, null), "#3");
+                       Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (null, null), "#4");
+                       Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (4, 4), "#5");
+                       Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (4, 5), "#6");
+               }
+       }
+}
+
+#endif
\ No newline at end of file
index ed7f3c7bf26c66a5fc594baabb6807a5962b5ab6..0ac74a6812b2a68db0826ae48e9781eb80bb29ac 100644 (file)
@@ -39,6 +39,7 @@ System.Collections/QueueTest.cs
 System.Collections/ReadOnlyCollectionBaseTest.cs
 System.Collections/SortedListTest.cs
 System.Collections/StackTest.cs
+System.Collections/StructuralComparisonsTest.cs
 System.Collections.Generic/ComparerTest.cs
 System.Collections.Generic/DictionaryTest.cs
 System.Collections.Generic/EqualityComparerTest.cs