Added Span.SequenceCompareTo tests for types bool, char, int, long and string#28320
Conversation
| { | ||
| for (int mismatchIndex = 0; mismatchIndex < length; mismatchIndex++) | ||
| { | ||
| string[] first = new string[length]; |
There was a problem hiding this comment.
Nit, it's optional, but we usually use var on the left side when the right side is a constructor.
There was a problem hiding this comment.
Not a problem 😄 My last commit addresses this remark.
| public static partial class SpanTests | ||
| { | ||
| [Fact] | ||
| public static void ZeroLengthSequenceCompareTo_Int() |
There was a problem hiding this comment.
We already have some T = int tests in this file:
https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/Span/SequenceCompareTo.T.cs#L12
Can you please consolidate these (i.e. remove the redundant integer specific tests from SequenceCompare.T.cs)?
| public static partial class SpanTests | ||
| { | ||
| [Fact] | ||
| public static void ZeroLengthSequenceCompareTo_String() |
There was a problem hiding this comment.
Can you move these tests (for T = string) into SequenceCompareTo.T.cs? That is where we tend to have tests for reference types like string, i.e. T != primitive numeric types (such as byte, int, long).
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="AllocationHelper.cs" /> | ||
| <Compile Include="Span\SequenceCompareTo.bool.cs" /> |
There was a problem hiding this comment.
nit: Please sort these alphabetically and move them to the ItemGroup with the rest of the Span tests, here:
|
|
||
| namespace System.SpanTests | ||
| { | ||
| public static partial class SpanTests |
There was a problem hiding this comment.
We also need test coverage for ReadOnlySpan.
The tests should look similar to the ones you just added here, except call SequenceCompareTo on ReadOnlySpan<T> instead of Span<T>.
It also looks like we need to port over the existing byte specific tests from Span to ReadOnlySpan (copy and modify).
See other ReadOnlySpanTests if you have any questions:
If you add the ROS tests, please add the cs files to the appropriate ItemGroup -
Thanks!
There was a problem hiding this comment.
My last commit addresses the ROS tests. Hope everything will be alright !
| var a = new bool[3]; | ||
|
|
||
| var first = new Span<bool>(a, 1, 0); | ||
| var second = new Span<bool>(a, 2, 0); |
There was a problem hiding this comment.
nit: If you will notice, the second Span gets implicitly casted to a ReadOnlySpan when we call SequenceCompareTo. Consider changing the type to ReadOnlySpan explicitly:
var second = new ReadOnlySpan<bool>(a, 2, 0);This way we are consistent with other tests, like SequenceCompareToWithSingleMismatch_Bool https://github.com/dotnet/corefx/pull/28320/files#diff-b162e342a6ea095c71071f76c985a098R91
| [Fact] | ||
| public static void SameSpanSequenceCompareTo_Int() | ||
| { | ||
| int[] a = { 4, 5, 6 }; |
There was a problem hiding this comment.
nit: I realize we have similar code elsewhere, but can we use values that are larger than byte (i.e. larger than 255), and that can only fit into an integer, going forward?
Random values somewhere between Int16.MaxValue (32767) and Int32.MaxValue (2147483647) would be best.
See recently added SequenceEqual.long as an example: https://github.com/dotnet/corefx/blob/master/src/System.Memory/tests/Span/SequenceEqual.long.cs#L34
| [Fact] | ||
| public static void SameSpanSequenceCompareTo_Long() | ||
| { | ||
| long[] a = { 4, 5, 6 }; |
There was a problem hiding this comment.
Same here. Use long[] a = { 488238291, 52498989823, 619890289890 };
ahsonkhan
left a comment
There was a problem hiding this comment.
Looks great. Thanks for taking this on and congrats on your first contribution :)
|
I just pushed the changes you requested regarding the test values. Thanks you for your valuable comments and help 😄 I hope I can contribute even more to this awesome project ! 🎉 |
| [Fact] | ||
| public static void SameSpanSequenceCompareTo_Int() | ||
| { | ||
| int[] a = { 4, 5, 6 }; |
There was a problem hiding this comment.
I just pushed the changes you requested regarding the test values.
We should make the same changes to the Span tests too (for int/long), just like ROSpan.
There was a problem hiding this comment.
Oh ! It seems I commited too quickly. It will be OK in a few minutes !
|
Unrelated test failure: OSX.1012.Amd64.Open-x64-Debug |
|
Filed an issue for this, potentially intermittent, CI failure: https://github.com/dotnet/corefx/issues/28390 I am sure it has nothing to do with this change/PR. |
|
@dotnet-bot test OSX x64 Debug Build |
…nd string (dotnet/corefx#28320) * Added SequenceCompareTo tests for types bool, char, int, long and string * Removed a TraitAttribute * Changed explicit type names to 'var' when on the left side of a constructor * Removed redundants tests in SequenceCompareTo.T * Moved tests from SequenceCompareTo.String.cs to SequenceCompareTo.T.cs * Moved <Compile> items to the correct ItemGroup * Change some Span to ReadOnlySpan * Added ReadOnlySpan.SequenceCompareTo tests * Changed test values to match int & long types. * Changed test values to match int & long types. Commit migrated from dotnet/corefx@84e257e
This PR resolves #28118 by adding more unit tests for the MemoryExtensions.SequenceCompareTo function.
It includes new tests for the following types : bool, char, int, long and string.
Hope this first PR will match your expectations 😄