From 02138dfac664814408a7dfe4c82cfb3899d143f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Sun, 5 Mar 2023 19:19:54 +0100 Subject: [PATCH] New tests added for IndexOf & LongIndexOf --- .../RecyclableListTests.cs | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/Recyclable.CollectionsTests/RecyclableListTests.cs b/Recyclable.CollectionsTests/RecyclableListTests.cs index 3089573..a407527 100644 --- a/Recyclable.CollectionsTests/RecyclableListTests.cs +++ b/Recyclable.CollectionsTests/RecyclableListTests.cs @@ -163,7 +163,7 @@ namespace Recyclable.CollectionsTests } [Fact] - public void IndexOfShouldFindTheIndexes() + public void IndexOfShouldReturnCorrectIndexes() { // Prepare using var list = NewRecyclableList; @@ -176,6 +176,36 @@ namespace Recyclable.CollectionsTests } } + [Fact] + public void IndexOfShouldNotFindNonExistingItems() + { + // Prepare + var testData = _testData; + using var list = NewRecyclableList; + _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); + + // Act + foreach (var item in testData) + { + // Validate + _ = list.IndexOf(-item).Should().Be(-1); + } + + // Validate + _ = list.IndexOf(0).Should().Be(-1); + } + + [Fact] + public void IndexOfShouldNotFindAnythingWhenListEmpty() + { + // Prepare + using var list = new RecyclableList(); + + // Validate + _ = list.IndexOf(0).Should().Be(-1); + _ = list.IndexOf(1).Should().Be(-1); + } + [Fact] public void InsertShouldRaiseNotSupportedException() { @@ -329,6 +359,37 @@ namespace Recyclable.CollectionsTests } } + [Fact] + public void LongIndexOfShouldNotFindNonExistingItems() + { + // Prepare + var testData = _testData; + using var list = NewRecyclableList; + _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); + + // Act + foreach (var item in testData) + { + // Validate + _ = list.LongIndexOf(-item).Should().Be(-1); + } + + // Validate + _ = list.LongIndexOf(0).Should().Be(-1); + } + + [Fact] + public void LongIndexOfShouldNotFindAnythingWhenListEmpty() + { + // Prepare + using var list = new RecyclableList(); + + // Validate + _ = list.LongIndexOf(0).Should().Be(-1); + _ = list.LongIndexOf(1).Should().Be(-1); + } + + [Fact] public void ConstructorSourceShouldInitializeList() {