From 896e2d4000003bb5a053b1c2c2d9971808e7afbc Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 22 Oct 2023 14:00:22 +0200 Subject: [PATCH] RecyclableList.BinarySearch tests added. --- .../RecyclableListCompatibilityListTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Recyclable.Collections.Compatibility.List.Tests/RecyclableListCompatibilityListTests.cs b/Recyclable.Collections.Compatibility.List.Tests/RecyclableListCompatibilityListTests.cs index da1d55b..32227f2 100644 --- a/Recyclable.Collections.Compatibility.List.Tests/RecyclableListCompatibilityListTests.cs +++ b/Recyclable.Collections.Compatibility.List.Tests/RecyclableListCompatibilityListTests.cs @@ -11,6 +11,29 @@ namespace Recyclable.CollectionsTests { public class RecyclableListCompatibilityListTests { + [Theory] + [MemberData(nameof(RecyclableLongListTestData.SourceDataWithItemIndexVariants), MemberType = typeof(RecyclableLongListTestData))] + public void BinarySearchShouldFindAllItems(string testCase, IEnumerable testData, int itemsCount, in long[] itemIndexes) + { + _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); + + // Prepare + using var list = new RecyclableList(testData, itemsCount); + var expectedData = testData.ToList(); + + foreach (var itemIndex in itemIndexes) + { + var expectedItem = expectedData[(int)itemIndex]; + var expected = expectedData.BinarySearch(expectedItem); + + // Act + var actual = list.BinarySearch(expectedItem); + + // Validate + _ = actual.Should().Be(expected); + } + } + [Theory] [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConvertAllShouldConvertAllItems(string testCase, IEnumerable testData, int itemsCount)