Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Added Span.SequenceCompareTo tests for types bool, char, int, long and string#28320

Merged
stephentoub merged 10 commits intodotnet:masterfrom
sputier:#28118_Tests_SequenceCompareTo
Mar 23, 2018
Merged

Added Span.SequenceCompareTo tests for types bool, char, int, long and string#28320
stephentoub merged 10 commits intodotnet:masterfrom
sputier:#28118_Tests_SequenceCompareTo

Conversation

@sputier
Copy link
Contributor

@sputier sputier commented Mar 21, 2018

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 😄

{
for (int mismatchIndex = 0; mismatchIndex < length; mismatchIndex++)
{
string[] first = new string[length];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, it's optional, but we usually use var on the left side when the right side is a constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem 😄 My last commit addresses this remark.

public static partial class SpanTests
{
[Fact]
public static void ZeroLengthSequenceCompareTo_Int()
Copy link

@ahsonkhan ahsonkhan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link

@ahsonkhan ahsonkhan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" />
Copy link

@ahsonkhan ahsonkhan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please sort these alphabetically and move them to the ItemGroup with the rest of the Span tests, here:

<Compile Include="Span\SequenceCompareTo.byte.cs" />


namespace System.SpanTests
{
public static partial class SpanTests
Copy link

@ahsonkhan ahsonkhan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

public static void ZeroLengthSequenceCompareTo_Byte()

public static void ZeroLengthSequenceCompareTo()

See other ReadOnlySpanTests if you have any questions:

public static partial class ReadOnlySpanTests

If you add the ROS tests, please add the cs files to the appropriate ItemGroup -

<Compile Include="ReadOnlySpan\SequenceEqual.byte.cs" />

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Use long[] a = { 488238291, 52498989823, 619890289890 };

Copy link

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for taking this on and congrats on your first contribution :)

@sputier
Copy link
Contributor Author

sputier commented Mar 22, 2018

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 };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ! It seems I commited too quickly. It will be OK in a few minutes !

@ahsonkhan
Copy link

Unrelated test failure:

OSX.1012.Amd64.Open-x64-Debug
System.Net.NetworkInformation.Tests.PingTest/SendPingAsyncWithHostAndTimeoutAndBuffer_Unix
https://mc.dot.net/#/user/sputier/pr~2Fjenkins~2Fdotnet~2Fcorefx~2Fmaster~2F/test~2Ffunctional~2Fcli~2F/aed8e7936300a0290bb29844f967876525ca9ffb/workItem/System.Net.Ping.Functional.Tests/analysis/xunit/System.Net.NetworkInformation.Tests.PingTest~2FSendPingAsyncWithHostAndTimeoutAndBuffer_Unix

Unhandled Exception of Type System.Net.NetworkInformation.PingException
Message :
System.Net.NetworkInformation.PingException : An exception occurred during a Ping request.
---- System.Net.NetworkInformation.PingException : An exception occurred during a Ping request.
Stack Trace :
   at System.Net.NetworkInformation.Ping.GetAddressAndSendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options) in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/src/System/Net/NetworkInformation/Ping.cs:line 364
   at System.Net.NetworkInformation.Tests.PingTest.SendPingAsync(Func`2 sendPing, Action`1 pingResultValidator) in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/tests/FunctionalTests/PingTest.cs:line 464
   at System.Net.NetworkInformation.Tests.PingTest.SendPingAsyncWithHostAndTimeoutAndBuffer_Unix() in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/tests/FunctionalTests/PingTest.cs:line 278
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----
   at System.Net.NetworkInformation.Ping.SendWithPingUtility(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options) in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs:line 210
   at System.Net.NetworkInformation.Ping.SendPingAsyncCore(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options) in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs:line 31
   at System.Net.NetworkInformation.Ping.GetAddressAndSendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options) in /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Net.Ping/src/System/Net/NetworkInformation/Ping.cs:line 353

@ahsonkhan
Copy link

ahsonkhan commented Mar 22, 2018

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.

@ahsonkhan
Copy link

@dotnet-bot test OSX x64 Debug Build
@dotnet-bot test Windows x64 Debug Build

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve test coverage of Span.SequenceCompareTo for T != byte

5 participants