diff --git a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.Enumerable.Int64.cs b/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.Enumerable.Int64.cs deleted file mode 100644 index d424d8ef..00000000 --- a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.Enumerable.Int64.cs +++ /dev/null @@ -1,69 +0,0 @@ -using PrimeFuncPack.UnitTest; -using System; -using System.Collections.Generic; -using System.Linq; -using static PrimeFuncPack.UnitTest.TestData; - -namespace PrimeFuncPack.Core.Tests; - -partial class OptionalLinqExtensionsTests -{ - [Test] - public void ElementAtOrAbsentByLong_CollectionSourceIsNull_ExpectArgumentNullException() - { - IEnumerable source = null!; - long index = 1; - - var ex = Assert.Throws(() => _ = source.ElementAtOrAbsent(index)); - Assert.That(ex!.ParamName, Is.EqualTo("source")); - } - - [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] - public void ElementAtOrAbsentByLong_CollectionIndexIsInRange_ExpectPresentItem( - long index) - { - var source = CreateCollection(SomeTextStructType, NullTextStructType, null); - var actual = source.ElementAtOrAbsent(index); - - var expectedValue = source.ElementAt(checked((int)index)); - var expected = Optional.Present(expectedValue); - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(3)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_CollectionIndexIsNotInRange_ExpectAbsent( - long index) - { - var source = CreateCollection(PlusFifteenIdRefType, MinusFifteenIdRefType, ZeroIdRefType); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(0)] - [TestCase(1)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_CollectionIsEmpty_ExpectAbsent( - long index) - { - var source = CreateCollection(); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } -} diff --git a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.List.Int64.cs b/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.List.Int64.cs deleted file mode 100644 index 462ece29..00000000 --- a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.List.Int64.cs +++ /dev/null @@ -1,73 +0,0 @@ -using PrimeFuncPack.UnitTest; -using System; -using System.Collections.Generic; -using System.Linq; -using static PrimeFuncPack.UnitTest.TestData; - -namespace PrimeFuncPack.Core.Tests; - -partial class OptionalLinqExtensionsTests -{ - [Test] - public void ElementAtOrAbsentByLong_ListSourceIsNull_ExpectArgumentNullException() - { - IList source = null!; - long index = 1; - - var ex = Assert.Throws(Test); - Assert.That(ex!.ParamName, Is.EqualTo("source")); - - void Test() - => - _ = source.ElementAtOrAbsent(index); - } - - [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] - public void ElementAtOrAbsentByLong_ListIndexIsInRange_ExpectPresentItem( - long index) - { - var source = CreateList(NullTextStructType, SomeTextStructType, SomeTextStructType); - var actual = source.ElementAtOrAbsent(index); - - var expectedValue = source.ElementAt(checked((int)index)); - var expected = Optional.Present(expectedValue); - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(4)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_ListIndexIsNotInRange_ExpectAbsent( - long index) - { - var source = CreateList(PlusFifteenIdRefType, MinusFifteenIdRefType, ZeroIdRefType, null); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(0)] - [TestCase(1)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_ListIsEmpty_ExpectAbsent( - long index) - { - var source = CreateList(); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } -} diff --git a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.ReadOnlyList.Int64.cs b/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.ReadOnlyList.Int64.cs deleted file mode 100644 index 06302d78..00000000 --- a/src/core-taggeds-optional/Optional.Tests.Old/OptionalLinqExtensions.Tests/ElementAtOrAbsent.ReadOnlyList.Int64.cs +++ /dev/null @@ -1,73 +0,0 @@ -using PrimeFuncPack.UnitTest; -using System; -using System.Collections.Generic; -using System.Linq; -using static PrimeFuncPack.UnitTest.TestData; - -namespace PrimeFuncPack.Core.Tests; - -partial class OptionalLinqExtensionsTests -{ - [Test] - public void ElementAtOrAbsentByLong_ReadOnlyListSourceIsNull_ExpectArgumentNullException() - { - IReadOnlyList source = null!; - long index = 1; - - var ex = Assert.Throws(Test); - Assert.That(ex!.ParamName, Is.EqualTo("source")); - - void Test() - => - _ = source.ElementAtOrAbsent(index); - } - - [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] - public void ElementAtOrAbsentByLong_ReadOnlyListIndexIsInRange_ExpectPresentItem( - long index) - { - var source = CreateReadOnlyList(PlusFifteenIdRefType, null, ZeroIdRefType); - var actual = source.ElementAtOrAbsent(index); - - var expectedValue = source.ElementAt(checked((int)index)); - var expected = Optional.Present(expectedValue); - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(4)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_ReadOnlyListIndexIsNotInRange_ExpectAbsent( - long index) - { - var source = CreateReadOnlyList(PlusFifteenIdRefType, MinusFifteenIdRefType, ZeroIdRefType, null); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } - - [Test] - [TestCase(long.MinValue)] - [TestCase(-1)] - [TestCase(0)] - [TestCase(1)] - [TestCase(long.MaxValue)] - public void ElementAtOrAbsentByLong_ReadOnlyListIsEmpty_ExpectAbsent( - long index) - { - var source = CreateReadOnlyList(); - - var actual = source.ElementAtOrAbsent(index); - var expected = Optional.Absent; - - Assert.That(actual, Is.EqualTo(expected)); - } -} diff --git a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/ElementAtOrAbsent.cs b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/ElementAtOrAbsent.cs index fef00fc0..73566a88 100644 --- a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/ElementAtOrAbsent.cs +++ b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/ElementAtOrAbsent.cs @@ -19,12 +19,4 @@ public static Optional ElementAtOrAbsent( InnerElementAtOrAbsent( source ?? throw new ArgumentNullException(nameof(source)), index); - - public static Optional ElementAtOrAbsent( - this IEnumerable source, - long index) - => - InnerElementAtOrAbsent( - source ?? throw new ArgumentNullException(nameof(source)), - index); } diff --git a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent.cs b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent.cs index dfc3ce16..00388d9a 100644 --- a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent.cs +++ b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent.cs @@ -37,24 +37,6 @@ IList list => list.InnerElementAtOrAbsent_IList(index), - _ => - source.InnerElementAtOrAbsent_IEnumerable(index) - }; - - private static Optional InnerElementAtOrAbsent( - this IEnumerable source, - long index) - => - source switch - { - IReadOnlyList list - => - list.InnerElementAtOrAbsent_IReadOnlyList(index), - - IList list - => - list.InnerElementAtOrAbsent_IList(index), - _ => source.InnerElementAtOrAbsent_IEnumerable(index) }; diff --git a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IEnumerable.cs b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IEnumerable.cs index 6af84211..f400f876 100644 --- a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IEnumerable.cs +++ b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IEnumerable.cs @@ -31,32 +31,4 @@ private static Optional InnerElementAtOrAbsent_IEnumerable( return default; } - - private static Optional InnerElementAtOrAbsent_IEnumerable( - this IEnumerable source, - long index) - { - if (index >= 0) - { - using var enumerator = source.GetEnumerator(); - - if (enumerator.MoveNext()) - { - var countdownIndex = index; - - do - { - if (countdownIndex == 0) - { - return new(enumerator.Current); - } - - countdownIndex--; - } - while (enumerator.MoveNext()); - } - } - - return default; - } } diff --git a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IList.cs b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IList.cs index 2cffea7f..e572dea1 100644 --- a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IList.cs +++ b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IList.cs @@ -9,10 +9,4 @@ private static Optional InnerElementAtOrAbsent_IList( int index) => index >= 0 && index < source.Count ? new(source[index]) : default; - - private static Optional InnerElementAtOrAbsent_IList( - this IList source, - long index) - => - index >= 0 && index < source.Count ? new(source[(int)index]) : default; } diff --git a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IReadOnlyList.cs b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IReadOnlyList.cs index 76c06a74..a1d8e9e4 100644 --- a/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IReadOnlyList.cs +++ b/src/core-taggeds-optional/Optional/OptionalLinqExtensions/Inner/InnerElementAtOrAbsent_IReadOnlyList.cs @@ -9,10 +9,4 @@ private static Optional InnerElementAtOrAbsent_IReadOnlyList( int index) => index >= 0 && index < source.Count ? new(source[index]) : default; - - private static Optional InnerElementAtOrAbsent_IReadOnlyList( - this IReadOnlyList source, - long index) - => - index >= 0 && index < source.Count ? new(source[(int)index]) : default; }