Uh oh!
There was an error while loading. Please reload this page.
Adding more tests for the generic math feature - #55377
Conversation
ghost
commented
Jul 8, 2021
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost
commented
Jul 8, 2021
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
This was a mistake in the interface definition?
There was a problem hiding this comment.
Yesn't.
Ideally both rotate and shift operators would take TSelf on the RHS. However, shift operators require dotnet/csharplang#4666 to go in and so Rotate should match until it does.
There was a problem hiding this comment.
Did you consider using theories to tighten up these tests and avoid the duplication? e.g. I prefer the conciseness and clarity of this:
| [Fact] | |
| publicstaticvoidTryCreateFromCharTest() | |
| { | |
| byteresult; | |
| Assert.True(NumberHelper<byte>.TryCreate<char>((char)0x0000,outresult)); | |
| Assert.Equal((byte)0x00,result); | |
| Assert.True(NumberHelper<byte>.TryCreate<char>((char)0x0001,outresult)); | |
| Assert.Equal((byte)0x01,result); | |
| Assert.False(NumberHelper<byte>.TryCreate<char>((char)0x7FFF,outresult)); | |
| Assert.Equal((byte)0x00,result); | |
| Assert.False(NumberHelper<byte>.TryCreate<char>((char)0x8000,outresult)); | |
| Assert.Equal((byte)0x00,result); | |
| Assert.False(NumberHelper<byte>.TryCreate<char>((char)0xFFFF,outresult)); | |
| Assert.Equal((byte)0x00,result); | |
| } | |
| [Theory] | |
| [InlineData(0x0000,0x00)] | |
| [InlineData(0x0001,0x01)] | |
| [InlineData(0x7FFF,0x00)] | |
| [InlineData(0x8000,0x00)] | |
| [InlineData(0xFFFF,0x00)] | |
| publicstaticvoidTryCreateFromCharTest(intinput,intexpected) | |
| { | |
| Assert.True(NumberHelper<byte>.TryCreate<char>((char)input,outbyteresult)); | |
| Assert.Equal((byte)expected,result); | |
| } |
There was a problem hiding this comment.
I'll log an issue for this as a low hanging fruit to make these easier to manage and add new cases for in the future.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Accident. Must have deleted these by mistake when adding in the other tests.
stephentoub
left a comment
There was a problem hiding this comment.
Spot checked and left a few comments. Thanks.
lambdageek
commented
Jul 9, 2021
mono interp failure looks relevant |
BrzVlad
commented
Jul 9, 2021
mono interp failures should have been fixed in #55418 |
tannergooding
commented
Jul 9, 2021
Rebased to pick up fixes. |
| [Fact] | ||
| public static void MinTest() | ||
| { | ||
| Assert.Equal((byte)0x00, NumberHelper<byte>.Min((byte)0x00, (byte)1)); |
There was a problem hiding this comment.
I feel like Theory would be easier here, but it's a nit, so I'm not too bothered. I also don't know how you generated these. If you used a tt file, I'm sure writing a Fact was easier
pgovind
left a comment
There was a problem hiding this comment.
I checked a few places and everything looked good. (I know it's already merged :))
This adds more tests covering the generic math feature for integer types.
CC. @pgovind, @stephentoub, @jeffhandley