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

Commit c68312e

Browse files
committed
add icomparable overload tests.
1 parent 9a19658 commit c68312e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/System.Memory/tests/ReadOnlySpan/BinarySearch.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private static void TestOverloads<T, TComparable>(
6969
{
7070
TestSpan(array, value, expectedIndex);
7171
TestReadOnlySpan(array, value, expectedIndex);
72+
TestIComparableSpan(array, value, expectedIndex);
73+
TestIComparableReadOnlySpan(array, value, expectedIndex);
7274
TestComparerSpan(array, value, expectedIndex);
7375
TestComparerReadOnlySpan(array, value, expectedIndex);
7476
}
@@ -89,6 +91,22 @@ private static void TestReadOnlySpan<T, TComparable>(
8991
var index = span.BinarySearch(value);
9092
Assert.Equal(expectedIndex, index);
9193
}
94+
private static void TestIComparableSpan<T, TComparable>(
95+
T[] array, TComparable value, int expectedIndex)
96+
where TComparable : IComparable<T>, T
97+
{
98+
var span = new Span<T>(array);
99+
var index = span.BinarySearch((IComparable<T>)value);
100+
Assert.Equal(expectedIndex, index);
101+
}
102+
private static void TestIComparableReadOnlySpan<T, TComparable>(
103+
T[] array, TComparable value, int expectedIndex)
104+
where TComparable : IComparable<T>, T
105+
{
106+
var span = new ReadOnlySpan<T>(array);
107+
var index = span.BinarySearch((IComparable<T>)value);
108+
Assert.Equal(expectedIndex, index);
109+
}
92110
private static void TestComparerSpan<T, TComparable>(
93111
T[] array, TComparable value, int expectedIndex)
94112
where TComparable : IComparable<T>, T

0 commit comments

Comments
 (0)