Skip to content

Missing comparison failure details for EqualTo when comparing two collection #4450

Description

@gps7

Based on discussion topic #4448 there is a problem provided constructive information about failure once comparing two collections. For example:

var actual = new[] { "A", "B", "C" };
var expected = new[] { "C", "B", "A" };
Assert.That(actual, Is.EqualTo(expected));

Failure gives fallowing information:
Expected and actual are both <System.String[3]>
Values differ at index [0]
String lengths are both 1. Strings differ at index 0.
Expected: "C"
But was: "A"
-----------^

Unfortunately, this does not show full list of actual and expected values which makes very complex to investigate when order is changed since full list is not provided. As comparison, Comparing of each collection item provides all useful information about both collection:

			var actual = new[] { "A", "B", "C" };
			Assert.That(actual, Has.All.EqualTo("E"));

Which fails with very useful message:
Expected: all items equal to "EX"
But was: < "A", "B", "C" >
First non-matching item at index [0]: "A"

I would expect similar information to be provided by EqualTo once two collections are compared so it lists actual and expected list and would consider truncation for long collection lists. For example in my first case should provide something like this:
Expected and actual are both <System.String[3]>
String lengths are both 1. Strings differ at index 0.
Expected: < "C", "B", "A" >"
But was: < "A", "B", "C" >
First non-matching item at index [0]: "A"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions