Skip to content

Commit

Permalink
Improve FlatMap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Aug 21, 2023
1 parent 66d5fa0 commit b78d48d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,58 @@ static FlatArray<long> Map(int sourceValue, int index)
[Fact]
public static void FlatMapWithIndex_SourceIsNotDefault_ExpectMappedValues()
{
var mapper = new Dictionary<string, FlatArray<decimal?>>
{
[SomeString] = default,
[AnotherString] = new decimal?[] { decimal.MinusOne, null, decimal.MaxValue }.InitializeFlatArray(2),
[WhiteSpaceString] = new decimal?[] { null }.InitializeFlatArray(),
[UpperSomeString] = new decimal?[] { decimal.One }.InitializeFlatArray(),
[LowerSomeString] = new decimal?[] { decimal.MinusOne }.InitializeFlatArray()
};

var sourceItems = new[] { SomeString, AnotherString, WhiteSpaceString, UpperSomeString };
var source = mapper.Keys.ToArray().InitializeFlatArray(sourceItems.Length);
var mapper = new Dictionary<int, FlatArray<decimal?>>
{
[-1] = new decimal?[] { 8, 4, 2, 1 }.InitializeFlatArray(),
[0] = default,
[1] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }.InitializeFlatArray(),
[2] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }.InitializeFlatArray(),
[3] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }.InitializeFlatArray(),
[4] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }.InitializeFlatArray(),
[5] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }.InitializeFlatArray(),
[6] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }.InitializeFlatArray(),
[7] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.InitializeFlatArray(),
[8] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.InitializeFlatArray(),
[9] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7, 8 }.InitializeFlatArray(),
[10] = new decimal?[] { null, 1, 2, 3, 4, 5, 6, 7 }.InitializeFlatArray(),
[11] = new decimal?[] { null, 1, 2, 3, 4, 5, 6 }.InitializeFlatArray(),
[12] = new decimal?[] { null, 1, 2, 3, 4, 5 }.InitializeFlatArray(),
[13] = new decimal?[] { null, 1, 2, 3, 4 }.InitializeFlatArray(),
[14] = new decimal?[] { null, 1, 2, 3 }.InitializeFlatArray(),
[15] = new decimal?[] { null, 1, 2 }.InitializeFlatArray(),
[16] = new decimal?[] { null, 1 }.InitializeFlatArray(),
[17] = default,
};

var source = mapper.Keys.ToArray().InitializeFlatArray();

var actual = source.FlatMap(Map);
var expectedItems = new decimal?[] { decimal.MinusOne, null, null, decimal.One };
var expectedItems = new decimal?[]
{
8, 4, 2, 1,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
null, 1, 2, 3, 4, 5, 6, 7, 8, 9,
null, 1, 2, 3, 4, 5, 6, 7, 8,
null, 1, 2, 3, 4, 5, 6, 7,
null, 1, 2, 3, 4, 5, 6,
null, 1, 2, 3, 4, 5,
null, 1, 2, 3, 4,
null, 1, 2, 3,
null, 1, 2,
null, 1
};

actual.VerifyTruncatedState(expectedItems);

FlatArray<decimal?> Map(string sourceValue, int index)
{
Assert.Equal(sourceItems[index], sourceValue);
return mapper[sourceValue];
}
FlatArray<decimal?> Map(int sourceValue)
=>
mapper[sourceValue];
}

public static IEnumerable<object[]> FlatMapWithIndex_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault_CaseSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,56 @@ static FlatArray<long> Map(int sourceValue)
[Fact]
public static void FlatMap_SourceIsNotDefault_ExpectMappedValues()
{
var mapper = new Dictionary<int, FlatArray<RecordType?>>
{
[MinusFifteen] = new RecordType?[] { MinusFifteenIdSomeStringNameRecord }.InitializeFlatArray(),
[One] = default,
[int.MaxValue] = new RecordType?[] { PlusFifteenIdSomeStringNameRecord, null, ZeroIdNullNameRecord }.InitializeFlatArray(2),
[PlusFifteen] = new RecordType?[] { MinusFifteenIdNullNameRecord }.InitializeFlatArray()
};

var source = mapper.Keys.ToArray().InitializeFlatArray(3);
var mapper = new Dictionary<int, FlatArray<long>>
{
[-1] = default,
[0] = new long[] { 0 }.InitializeFlatArray(),
[1] = default,
[2] = new long[] { 0, 1 }.InitializeFlatArray(),
[3] = new long[] { 0, 1, 2 }.InitializeFlatArray(),
[4] = new long[] { 0, 1, 2, 3 }.InitializeFlatArray(),
[5] = new long[] { 0, 1, 2, 3, 4 }.InitializeFlatArray(),
[6] = new long[] { 0, 1, 2, 3, 4, 5 }.InitializeFlatArray(),
[7] = new long[] { 0, 1, 2, 3, 4, 5, 6 }.InitializeFlatArray(),
[8] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7 }.InitializeFlatArray(),
[9] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }.InitializeFlatArray(),
[10] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.InitializeFlatArray(),
[11] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.InitializeFlatArray(),
[12] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }.InitializeFlatArray(),
[13] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }.InitializeFlatArray(),
[14] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }.InitializeFlatArray(),
[15] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, }.InitializeFlatArray(),
[16] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, }.InitializeFlatArray(),
[17] = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }.InitializeFlatArray()
};

var source = mapper.Keys.ToArray().InitializeFlatArray();

var actual = source.FlatMap(Map);
var expectedItems = new RecordType?[] { MinusFifteenIdSomeStringNameRecord, PlusFifteenIdSomeStringNameRecord, null };
var expectedItems = new long[]
{
0,
0, 1,
0, 1, 2,
0, 1, 2, 3,
0, 1, 2, 3, 4,
0, 1, 2, 3, 4, 5,
0, 1, 2, 3, 4, 5, 6,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7, 8,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
};

actual.VerifyTruncatedState(expectedItems);

FlatArray<RecordType?> Map(int sourceValue)
FlatArray<long> Map(int sourceValue)
=>
mapper[sourceValue];
}
Expand Down

0 comments on commit b78d48d

Please sign in to comment.