Extend SequenceCompareTo_byte for longer vector lengths (dotnet/corefx#34742)
authorBen Adams <thundercat@illyriad.co.uk>
Fri, 25 Jan 2019 20:11:21 +0000 (21:11 +0100)
committerStephen Toub <stoub@microsoft.com>
Fri, 25 Jan 2019 20:11:21 +0000 (15:11 -0500)
* Extend SequenceCompareTo_byte for longer vector lengths

* Feedback

Commit migrated from https://github.com/dotnet/corefx/commit/585e3297d8b861ecaf5100da941a7a922a08a6fd

src/libraries/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs
src/libraries/System.Memory/tests/Span/SequenceCompareTo.byte.cs

index 9accd08..7f079f7 100644 (file)
@@ -72,9 +72,29 @@ namespace System.SpanTests
         }
 
         [Fact]
+        public static void SequenceCompareToEqual_Byte()
+        {
+            for (int length = 1; length < 128; length++)
+            {
+                var first = new byte[length];
+                var second = new byte[length];
+                for (int i = 0; i < length; i++)
+                {
+                    first[i] = second[i] = (byte)(i + 1);
+                }
+
+                var firstSpan = new ReadOnlySpan<byte>(first);
+                var secondSpan = new ReadOnlySpan<byte>(second);
+
+                Assert.Equal(0, firstSpan.SequenceCompareTo<byte>(secondSpan));
+                Assert.Equal(0, secondSpan.SequenceCompareTo<byte>(firstSpan));
+            }
+        }
+
+        [Fact]
         public static void SequenceCompareToWithSingleMismatch_Byte()
         {
-            for (int length = 1; length < 32; length++)
+            for (int length = 1; length < 128; length++)
             {
                 for (int mismatchIndex = 0; mismatchIndex < length; mismatchIndex++)
                 {
@@ -101,7 +121,7 @@ namespace System.SpanTests
         [Fact]
         public static void SequenceCompareToNoMatch_Byte()
         {
-            for (int length = 1; length < 32; length++)
+            for (int length = 1; length < 128; length++)
             {
                 var first = new byte[length];
                 var second = new byte[length];
index 73f3728..bc6c640 100644 (file)
@@ -72,9 +72,29 @@ namespace System.SpanTests
         }
 
         [Fact]
+        public static void SequenceCompareToEqual_Byte()
+        {
+            for (int length = 1; length < 128; length++)
+            {
+                var first = new byte[length];
+                var second = new byte[length];
+                for (int i = 0; i < length; i++)
+                {
+                    first[i] = second[i] = (byte)(i + 1);
+                }
+
+                var firstSpan = new Span<byte>(first);
+                var secondSpan = new Span<byte>(second);
+                
+                Assert.Equal(0, firstSpan.SequenceCompareTo<byte>(secondSpan));
+                Assert.Equal(0, secondSpan.SequenceCompareTo<byte>(firstSpan));
+            }
+        }
+        
+        [Fact]
         public static void SequenceCompareToWithSingleMismatch_Byte()
         {
-            for (int length = 1; length < 32; length++)
+            for (int length = 1; length < 128; length++)
             {
                 for (int mismatchIndex = 0; mismatchIndex < length; mismatchIndex++)
                 {
@@ -101,7 +121,7 @@ namespace System.SpanTests
         [Fact]
         public static void SequenceCompareToNoMatch_Byte()
         {
-            for (int length = 1; length < 32; length++)
+            for (int length = 1; length < 128; length++)
             {
                 byte[] first = new byte[length];
                 byte[] second = new byte[length];