-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from pfpack/feature/functional-methods
Feature/functional methods
- Loading branch information
Showing
17 changed files
with
901 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Functional/Concat.Array.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using PrimeFuncPack.UnitTest; | ||
using Xunit; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FlatArrayTest | ||
{ | ||
[Fact] | ||
public static void ConcatWithArray_SourceIsEmptyAndOtherIsNull_ExpectEmpty() | ||
{ | ||
var source = default(FlatArray<decimal?>); | ||
var other = (decimal?[]?)null; | ||
|
||
var actual = source.Concat(other); | ||
|
||
actual.VerifyInnerState(default, default); | ||
} | ||
|
||
[Fact] | ||
public static void ConcatWithArray_SourceAndOtherAreEmpty_ExpectEmpty() | ||
{ | ||
var source = default(FlatArray<RefType>); | ||
var other = Array.Empty<RefType>(); | ||
|
||
var actual = source.Concat(other); | ||
|
||
actual.VerifyInnerState(default, default); | ||
} | ||
|
||
[Fact] | ||
public static void ConcatWithArray_SourceIsEmptyAndOtherIsNotEmpty_ExpectOther() | ||
{ | ||
var source = default(FlatArray<RecordType>); | ||
var other = new[] { MinusFifteenIdNullNameRecord, PlusFifteenIdLowerSomeStringNameRecord }; | ||
|
||
var actual = source.Concat(other); | ||
var expectedItems = new[] { MinusFifteenIdNullNameRecord, PlusFifteenIdLowerSomeStringNameRecord }; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Fact] | ||
public static void ConcatWithArray_OtherIsNullAndSourceIsNotEmpty_ExpectSource() | ||
{ | ||
var source = new[] { AnotherString, UpperSomeString, WhiteSpaceString, null }.InitializeFlatArray(2); | ||
var other = (string?[]?)null; | ||
|
||
var actual = source.Concat(other); | ||
var expectedItems = new[] { AnotherString, UpperSomeString }; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Fact] | ||
public static void ConcatWithArray_OtherIsEmptyAndSourceIsNotEmpty_ExpectSource() | ||
{ | ||
var source = new RecordStruct?[] | ||
{ | ||
SomeTextRecordStruct, | ||
AnotherTextRecordStruct, | ||
null, | ||
UpperAnotherTextRecordStruct | ||
} | ||
.InitializeFlatArray(3); | ||
|
||
var other = Array.Empty<RecordStruct?>(); | ||
|
||
var actual = source.Concat(other); | ||
|
||
var expectedItems = new RecordStruct?[] | ||
{ | ||
SomeTextRecordStruct, | ||
AnotherTextRecordStruct, | ||
null | ||
}; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Fact] | ||
public static void ConcatWithArray_SourceAndOtherAreNotEmpty_ExpectMergedArray() | ||
{ | ||
var source = new int?[] | ||
{ | ||
MinusFifteen, | ||
Zero, | ||
null, | ||
int.MaxValue | ||
} | ||
.InitializeFlatArray(3); | ||
|
||
var actual = source.Concat(PlusFifteen, null, One, int.MinValue); | ||
|
||
var expectedItems = new int?[] | ||
{ | ||
MinusFifteen, | ||
Zero, | ||
null, | ||
PlusFifteen, | ||
null, | ||
One, | ||
int.MinValue | ||
}; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Functional/Concat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using PrimeFuncPack.UnitTest; | ||
using Xunit; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FlatArrayTest | ||
{ | ||
[Fact] | ||
public static void Concat_SourceAndOtherAreEmpty_ExpectEmpty() | ||
{ | ||
var source = default(FlatArray<StructType>); | ||
var other = default(FlatArray<StructType>); | ||
|
||
var actual = source.Concat(other); | ||
|
||
actual.VerifyInnerState(default, default); | ||
} | ||
|
||
[Fact] | ||
public static void Concat_SourceIsEmptyAndOtherIsNotEmpty_ExpectOther() | ||
{ | ||
var source = default(FlatArray<int?>); | ||
var other = new int?[] { null, PlusFifteen, Zero, One }.InitializeFlatArray(3); | ||
|
||
var actual = source.Concat(other); | ||
var expectedItems = new int?[] { null, PlusFifteen, Zero }; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Fact] | ||
public static void Concat_OtherIsEmptyAndSourceIsNotEmpty_ExpectSource() | ||
{ | ||
var source = new[] { SomeString, null, AnotherString }.InitializeFlatArray(2); | ||
var other = default(FlatArray<string?>); | ||
|
||
var actual = source.Concat(other); | ||
var expectedItems = new[] { SomeString, null }; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Fact] | ||
public static void Concat_SourceAndOtherAreNotEmpty_ExpectMergedArray() | ||
{ | ||
var source = new[] | ||
{ | ||
null, | ||
MinusFifteenIdNullNameRecord, | ||
ZeroIdNullNameRecord | ||
} | ||
.InitializeFlatArray(2); | ||
|
||
var other = new[] | ||
{ | ||
PlusFifteenIdLowerSomeStringNameRecord, | ||
MinusFifteenIdSomeStringNameRecord, | ||
PlusFifteenIdSomeStringNameRecord, | ||
MinusFifteenIdNullNameRecord, | ||
null | ||
} | ||
.InitializeFlatArray(3); | ||
|
||
var actual = source.Concat(other); | ||
|
||
var expectedItems = new[] | ||
{ | ||
null, | ||
MinusFifteenIdNullNameRecord, | ||
PlusFifteenIdLowerSomeStringNameRecord, | ||
MinusFifteenIdSomeStringNameRecord, | ||
PlusFifteenIdSomeStringNameRecord | ||
}; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Functional/Filter.Index.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using PrimeFuncPack.UnitTest; | ||
using Xunit; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FlatArrayTest | ||
{ | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public static void FilterWithIndex_PredicateIsNull_ExpectArgumentNullException( | ||
bool isSourceDefault) | ||
{ | ||
var source = isSourceDefault ? default : new[] { MinusFifteenIdRefType }.InitializeFlatArray(); | ||
Func<RefType, int, bool> predicate = null!; | ||
|
||
var ex = Assert.Throws<ArgumentNullException>(Test); | ||
Assert.Equal("predicate", ex.ParamName); | ||
|
||
void Test() | ||
=> | ||
_ = source.Filter(predicate); | ||
} | ||
|
||
[Fact] | ||
public static void FilterWithIndex_SourceIsEmpty_ExpectDefault() | ||
{ | ||
var source = default(FlatArray<StructType?>); | ||
|
||
var actual = source.Filter(Predicate); | ||
|
||
actual.VerifyInnerState(default, default); | ||
|
||
static bool Predicate(StructType? item, int _) | ||
=> | ||
true; | ||
} | ||
|
||
[Fact] | ||
public static void FilterWithIndex_SourceIsNotEmptyAndAllPredicatesReturnFalse_ExpectDefault() | ||
{ | ||
var source = new decimal?[] { decimal.One, null, decimal.MaxValue }.InitializeFlatArray(); | ||
|
||
var actual = source.Filter(Predicate); | ||
|
||
actual.VerifyInnerState(default, default); | ||
|
||
static bool Predicate(decimal? item, int _) | ||
=> | ||
false; | ||
} | ||
|
||
[Fact] | ||
public static void FilterWithIndex_SourceIsNotEmptyAndNotAllPredicatesReturnFalse_ExpectFilteredValues() | ||
{ | ||
var mapper = new Dictionary<string, bool> | ||
{ | ||
{ EmptyString, true }, | ||
{ SomeString, false }, | ||
{ UpperAnotherString, true }, | ||
{ WhiteSpaceString, true }, | ||
{ AnotherString, false }, | ||
{ TabString, true } | ||
}; | ||
|
||
var sourceItems = new[] { EmptyString, SomeString, UpperAnotherString, WhiteSpaceString, AnotherString }; | ||
var source = mapper.Keys.ToArray().InitializeFlatArray(sourceItems.Length); | ||
|
||
var actual = source.Filter(Predicate); | ||
var expectedItems = new[] { EmptyString, UpperAnotherString, WhiteSpaceString }; | ||
|
||
actual.VerifyTruncatedState(expectedItems); | ||
|
||
bool Predicate(string item, int index) | ||
{ | ||
Assert.Equal(sourceItems[index], item); | ||
return mapper[item]; | ||
} | ||
} | ||
} |
Oops, something went wrong.