NUnit's logic for comparing arrays - use Comparer<T[]> if it is provided.

Bug #708173 reported by Andrew Skalkin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Fix Released
High
Charlie Poole
NUnit V2
Fix Released
High
Charlie Poole

Bug Description

In the following code snippet, NUnit uses passed comparer as elements' comparer, which prevents us from treating array types just like any other data types in unit tests. The workaround is to check for equality in the following way - Assert.AreEqual(0, comparer.Compare(expected, actual))).

[TestFixture]
public class NUnitFeatures
{
   [Test]
   public void CustomArrayComparison()
   {
      Assert.That(new[] { 1 }, Is.EqualTo(new[] { 1 }).Using(new IntArrayComparer()));
   }

   class IntArrayComparer : IComparer<int[]>
   {
      public int Compare(int[] x, int[] y) { return 0; } // just a stub
   }
}

Google groups discussion:
http://groups.google.com/group/nunit-discuss/browse_thread/thread/792d9afbe01f7892

Changed in nunit-3.0:
status: New → Triaged
tags: added: feature framework
Changed in nunit-3.0:
importance: Undecided → High
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.9.6
Changed in nunit-3.0:
status: Triaged → Fix Committed
Changed in nunitv2:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.6.0
Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Fix Committed → Fix Released
Changed in nunit-3.0:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.