← Back to team overview

nunit-core team mailing list archive

[Bug 709062] Re: "System.ArgumentException : Cannot compare" when the element is a list

 

** Also affects: nunit-3.0
   Importance: Undecided
       Status: New

-- 
You received this bug notification because you are a member of NUnit
Core Developers, which is the registrant for NUnit Framework.
https://bugs.launchpad.net/bugs/709062

Title:
  "System.ArgumentException : Cannot compare" when the element is a list

Status in NUnit Test Framework:
  New
Status in NUnit V2 Test Framework:
  Fix Committed

Bug description:
  Relevant discussion can be found here.
  https://groups.google.com/forum/?pli=1#!topic/nunit-
  discuss/IgGiVyo3fKw

  
  This code throws me a System.ArgumentException : Cannot compare 2 exception. 

  
          public class IntListEqualComparer: IEqualityComparer<List<int>>
          {
              public bool Equals(List<int> x, List<int> y)
              {
                  return x.Count == y.Count;
              }

              public int GetHashCode(List<int> obj)
              {
                  return obj.Count.GetHashCode();
              }
          }

          [Test]
          public void IntListListTest()
          {
              var list1 = new List<int>() {2, 3};
              var list2 = new List<int>() {2, 3};

              var list11 = new List<List<int>>() {list1};
              var list22 = new List<List<int>>() { list2 };
              var comparer = new IntListEqualComparer();
              Assert.That(list11, new CollectionEquivalentConstraint(list22).Using(comparer));
          }

  It seems that Nunit can't compare if the elements are of the type
  List?

  Here's the complete stack trace:

  failed: System.ArgumentException : Cannot compare 2
  	at NUnit.Framework.Constraints.EqualityAdapter.EqualityComparerAdapter`1.ObjectsEqual(Object x, Object y)
  	at NUnit.Framework.Constraints.NUnitEqualityComparer.ObjectsEqual(Object x, Object y)
  	at NUnit.Framework.Constraints.NUnitEqualityComparer.CollectionsEqual(ICollection x, ICollection y)
  	at NUnit.Framework.Constraints.NUnitEqualityComparer.ObjectsEqual(Object x, Object y)
  	at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.ItemsEqual(Object expected, Object actual)
  	at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.TryRemove(Object o)
  	at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.TryRemove(IEnumerable c)
  	at NUnit.Framework.Constraints.CollectionEquivalentConstraint.doMatch(IEnumerable actual)
  	at NUnit.Framework.Constraints.CollectionConstraint.Matches(Object actual)

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunit-3.0/+bug/709062/+subscriptions


References