Skip to content
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

IsEquivalent with default CollectionOrdering does not print expected sequence #2117

Closed
quellatalo opened this issue Mar 19, 2025 · 2 comments · Fixed by #2120
Closed

IsEquivalent with default CollectionOrdering does not print expected sequence #2117

quellatalo opened this issue Mar 19, 2025 · 2 comments · Fixed by #2120

Comments

@quellatalo
Copy link

It seems that without specifying CollectionOrdering, IsEquivalent would use the Matching option.
However, it does not print the expected sequence when it fails.

For example:

    [Test]
    [Arguments(new[] { 1, 2, 3 }, new[] { 3, 2, 1 }, CollectionOrdering.Matching)] // case 0
    [Arguments(new[] { 1, 2, 3 }, new[] { 1, 2, 3, 4 }, CollectionOrdering.Any)] // case 1
    [Arguments(new[] { 1, 2, 3 }, new[] { 3, 2, 1 })] // case 2
    [Arguments(new[] { 1, 2, 3 }, new[] { 1, 2, 3, 4 })] // case 3
    public async Task IsEquivalent_Fail(int[] a, int[] b, CollectionOrdering? collectionOrdering = null)
        => await (collectionOrdering is null
            ? Assert.That(a).IsEquivalentTo(b)
            : Assert.That(a).IsEquivalentTo(b, collectionOrdering.Value));

case 0 starts with: AssertionException: Expected a to be equivalent to [3, 2, 1]
case 1 starts with: AssertionException: Expected a to be equivalent to [1, 2, 3, 4]
However, case 2 and 3 start with: AssertionException: Expected a to be equivalent to b

@quellatalo
Copy link
Author

Also, IsNotEquivalentTo doesn't accept CollectionOrdering, and it always use SequenceEqual to check. (same as CollectionOrdering.Matching)

I see in TUnit you have the same condition split into 2: positive & negative and are maintaining both (Is__ and IsNot__).
I think it's quite hard to maintain.
Is it not possible to separate the Not? For example, something like this would be nice:

await Assert.That(actualCollection).Is.EquivalentTo(expectedCollection, CollectionOrdering.Any);
await Assert.That(actualCollection).Is.Not.EquivalentTo(expectedCollection, CollectionOrdering.Matching);

It would be quite a big change though.

@thomhurst
Copy link
Owner

Assertions were originally like that but the community did not like it

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