Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gps7 opened this issue Aug 7, 2023 · 2 comments
Closed

Comments

@gps7
Copy link

gps7 commented Aug 7, 2023

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"

@gps7 gps7 changed the title EqualTo comparison provides very wage failure results for collection comparison Missing comparison failure details for EqualTo when comparing two collection Aug 31, 2023
@gps7
Copy link
Author

gps7 commented Sep 14, 2023

Please confirm that this is a bug as it was discussed.

@stevenaw
Copy link
Member

Thanks for finding and raising this @gps7 !
I'll add the bug label now. I can see this was already discussed to be a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants