From f9294e43806970da29cc0298c1bddaf20ee35ab8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 22 Jan 2019 14:15:08 +0000 Subject: [PATCH 1/2] Extend SequenceCompareTo_byte for longer vector lengths --- .../ReadOnlySpan/SequenceCompareTo.byte.cs | 26 +++++++++++++++++-- .../tests/Span/SequenceCompareTo.byte.cs | 26 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs b/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs index 9accd0826edf..5c2f7888e113 100644 --- a/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs @@ -71,10 +71,32 @@ public static void LengthMismatchSequenceCompareTo_Byte() Assert.True(result > 0); } + [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(first); + var secondSpan = new ReadOnlySpan(second); + int result = firstSpan.SequenceCompareTo(secondSpan); + Assert.True(result == 0); + + result = secondSpan.SequenceCompareTo(firstSpan); + Assert.True(result == 0); + } + } + [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 +123,7 @@ public static void SequenceCompareToWithSingleMismatch_Byte() [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]; diff --git a/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs b/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs index 73f3728fa1aa..afceae216da8 100644 --- a/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs +++ b/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs @@ -71,10 +71,32 @@ public static void LengthMismatchSequenceCompareTo_Byte() Assert.True(result > 0); } + [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(first); + var secondSpan = new Span(second); + int result = firstSpan.SequenceCompareTo(secondSpan); + Assert.True(result == 0); + + result = secondSpan.SequenceCompareTo(firstSpan); + Assert.True(result == 0); + } + } + [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 +123,7 @@ public static void SequenceCompareToWithSingleMismatch_Byte() [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]; From 307140fcd9b62653300afd75bd3a49efa1bda149 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 22 Jan 2019 19:43:19 +0000 Subject: [PATCH 2/2] Feedback --- .../tests/ReadOnlySpan/SequenceCompareTo.byte.cs | 6 ++---- src/System.Memory/tests/Span/SequenceCompareTo.byte.cs | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs b/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs index 5c2f7888e113..7f079f740f7a 100644 --- a/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs +++ b/src/System.Memory/tests/ReadOnlySpan/SequenceCompareTo.byte.cs @@ -85,11 +85,9 @@ public static void SequenceCompareToEqual_Byte() var firstSpan = new ReadOnlySpan(first); var secondSpan = new ReadOnlySpan(second); - int result = firstSpan.SequenceCompareTo(secondSpan); - Assert.True(result == 0); - result = secondSpan.SequenceCompareTo(firstSpan); - Assert.True(result == 0); + Assert.Equal(0, firstSpan.SequenceCompareTo(secondSpan)); + Assert.Equal(0, secondSpan.SequenceCompareTo(firstSpan)); } } diff --git a/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs b/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs index afceae216da8..bc6c64005af3 100644 --- a/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs +++ b/src/System.Memory/tests/Span/SequenceCompareTo.byte.cs @@ -85,11 +85,9 @@ public static void SequenceCompareToEqual_Byte() var firstSpan = new Span(first); var secondSpan = new Span(second); - int result = firstSpan.SequenceCompareTo(secondSpan); - Assert.True(result == 0); - - result = secondSpan.SequenceCompareTo(firstSpan); - Assert.True(result == 0); + + Assert.Equal(0, firstSpan.SequenceCompareTo(secondSpan)); + Assert.Equal(0, secondSpan.SequenceCompareTo(firstSpan)); } }