nunit / nunit

NUnit Framework
https://nunit.org/
MIT License
2.51k stars 731 forks source link

PropertiesComparer 32 Property Limit Error Message #4862

Open Cincidial opened 3 hours ago

Cincidial commented 3 hours ago

When using .UsingPropertiesComparer() on a class with 32 or more properties the following error message is returned

System.NotSupportedException : No comparer found for instances of type 'x' and 'x'

(x is the same class in this case, just as an example)

This message doesn't actually tell the test writer what's going on as unless you look at the PropertiesComparer.cs in this repo there's no documentation on a max property limit. At least as far as I could find on this page

As can be seen in the file this check could return it's own enum result for a better error message.

Also, I'm wondering why there is a 32 property max (actually only 31 because a >= is used instead of a >)? I see in that code there's an int whose 31 of 32 bits are being used as flags, but would that also work as a long so that a max of 64 properties is available instead? A list could also be used instead of bitwise operations so that there is no property limit

stevenaw commented 3 hours ago

I'm wondering why there is a 32 property max

A simple answer I could suppose here is just that it was a good starting point 🙂 You are right we could double the number of supported properties just by changing the uint to ulong.

@manfred-brands I know this was a major contribution of yours recently so I'm curious your thoughts on a finite limit here rather than suggesting my own outright. My thinking is there is probably a complexity and slight performance impact if we go beyond 64, but otherwise potentially no issues. Still, it's a trade-off we'd need to consider. A BitArray or a Span<int> could perhaps be used if we wanted to support a boundless amount.

@Cincidial would you be interested in contributing a change here if/once we decide what one could look like?

Cincidial commented 2 hours ago

Yup I can do the change if/once y'all decide on the direction you want to take (if that direction is to make a change).