public void Select_With_NullSelector_Must_Throw() { // Arrange var enumerable = Wrap.AsValueEnumerable(new int[0]); var selector = (NullableSelectorAt <int, string>)null; // Act Action action = () => _ = ValueEnumerableExtensions.Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(enumerable, selector); // Assert _ = action.Must() .Throw <ArgumentNullException>() .EvaluateTrue(exception => exception.ParamName == "selector"); }
public void Select_With_ValidData_Must_Succeed(int[] source, Func <int, int, string> selector) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); var expected = System.Linq.Enumerable.Select(wrapped, selector); // Act var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector); // Assert _ = result.Must() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public void Single_SelectorAt_With_Multiple_Must_Return_None(int[] source, Func <int, int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); // Act var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .Single(); // Assert _ = result.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }
public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func <int, int, string> selector) { // Arrange var pool = MemoryPool <string> .Shared; var wrapped = Wrap .AsValueEnumerable(source); var expected = Enumerable .Select(source, selector) .ToArray(); // Act using var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToArray(pool); // Assert _ = result.Memory .SequenceEqual(expected); }
public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); var expected = Enumerable .Select(source, selector.AsFunc()) .ToArray(); // Act var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToArray(); // Assert _ = result.Must() .BeArrayOf <string>() .BeEqualTo(expected); }
public void Single_SelectorAt_With_Single_Must_Return_Some(int[] source, Func <int, int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); var expected = Enumerable .Select(source, selector) .Single(); // Act var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .Single(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void ElementAt_SelectorAt_With_ValidData_Must_Return_Some(int[] source, Func <int, int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); var expected = Enumerable .Select(source, selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act var result = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(index); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected[index]), () => throw new Exception()); } }
public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func <int, int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); // Act var optionNegative = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(-1); var optionTooLarge = ValueEnumerableExtensions .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(source.Length); // Assert _ = optionNegative.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); _ = optionTooLarge.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }