Skip to content

Commit

Permalink
Merge pull request #48 from pfpack/release/v1.2.0-rc.1
Browse files Browse the repository at this point in the history
release/v1.2.0-rc.1
  • Loading branch information
andreise authored Aug 21, 2023
2 parents 7ac1249 + 1decb8a commit 98856bb
Show file tree
Hide file tree
Showing 59 changed files with 805 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,146 @@ public static void FlatMapWithIndex_SourceIsDefault_ExpectDefault()
new(null, SomeTextRecordStruct, AnotherTextRecordStruct);
}

[Fact]
public static void FlatMapWithIndex_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault()
[Theory]
[MemberData(nameof(FlatMapWithIndex_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault_CaseSource))]
public static void FlatMapWithIndex_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault(
int[] source)
{
var source = new[] { EmptyString, SomeString, WhiteSpaceString }.InitializeFlatArray();

var actual = source.FlatMap(Map);
var actual = source.InitializeFlatArray().FlatMap(Map);

actual.VerifyInnerState(default, default);

static FlatArray<StructType> Map(string sourceValue, int index)
static FlatArray<long> Map(int sourceValue, int index)
=>
default;
}

[Fact]
public static void FlatMapWithIndex_SourceIsNotDefault_ExpectMappedValues()
{
var mapper = new Dictionary<string, FlatArray<decimal?>>
var mapper = new Dictionary<int, 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()
[-1] = new decimal?[] { 8, 4, 2, 1 }.InitializeFlatArray(3),
[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(1),
[17] = default,
};

var sourceItems = new[] { SomeString, AnotherString, WhiteSpaceString, UpperSomeString };
var source = mapper.Keys.ToArray().InitializeFlatArray(sourceItems.Length);
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,
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
};

actual.VerifyTruncatedState(expectedItems);

FlatArray<decimal?> Map(string sourceValue, int index)
FlatArray<decimal?> Map(int sourceValue)
=>
mapper[sourceValue];
}

public static IEnumerable<object[]> FlatMapWithIndex_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault_CaseSource()
{
yield return new object[]
{
new[] { 0 }
};
yield return new object[]
{
new[] { 0, 1 }
};
yield return new object[]
{
new[] { 0, 1, 2 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5 }
};
yield return new object[]
{
Assert.Equal(sourceItems[index], sourceValue);
return mapper[sourceValue];
}
new[] { 0, 1, 2, 3, 4, 5, 6 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,145 @@ static FlatArray<string> Map(RecordStruct? _)
new(SomeString, AnotherString);
}

[Fact]
public static void FlatMap_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault()
[Theory]
[MemberData(nameof(FlatMap_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault_CaseSource))]
public static void FlatMap_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault(
int[] source)
{
var source = new[] { SomeTextStructType, LowerSomeTextStructType }.InitializeFlatArray();

var actual = source.FlatMap(Map);
var actual = source.InitializeFlatArray().FlatMap(Map);

actual.VerifyInnerState(default, default);

static FlatArray<RefType> Map(StructType sourceValue)
static FlatArray<long> Map(int sourceValue)
=>
default;
}

[Fact]
public static void FlatMap_SourceIsNotDefault_ExpectMappedValues()
{
var mapper = new Dictionary<int, FlatArray<RecordType?>>
var mapper = new Dictionary<int, FlatArray<long>>
{
[MinusFifteen] = new RecordType?[] { MinusFifteenIdSomeStringNameRecord }.InitializeFlatArray(),
[One] = default,
[int.MaxValue] = new RecordType?[] { PlusFifteenIdSomeStringNameRecord, null, ZeroIdNullNameRecord }.InitializeFlatArray(2),
[PlusFifteen] = new RecordType?[] { MinusFifteenIdNullNameRecord }.InitializeFlatArray()
[-1] = default,
[0] = new long[] { 0 }.InitializeFlatArray(),
[1] = default,
[2] = new long[] { 0, 1 }.InitializeFlatArray(0),
[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(10),
[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(16)
};

var source = mapper.Keys.ToArray().InitializeFlatArray(3);
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, 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,
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
};

actual.VerifyTruncatedState(expectedItems);

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

public static IEnumerable<object[]> FlatMap_SourceIsNotDefaultAndAllMapResultAreDefault_ExpectDefault_CaseSource()
{
yield return new object[]
{
new[] { 0 }
};
yield return new object[]
{
new[] { 0, 1 }
};
yield return new object[]
{
new[] { 0, 1, 2 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
};
yield return new object[]
{
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ internal static FlatArray<T>.Builder Empty<T>()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static FlatArray<T>.Builder Empty<T>(int capacity)
=>
FlatArray<T>.Builder.InternalEmpty(capacity, nameof(capacity));
FlatArray<T>.Builder.InternalEmptyChecked(capacity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ partial class Builder
{
public static FlatArray<T>.Builder OfLength<T>(int length)
=>
FlatArray<T>.Builder.InternalOfLength(length, nameof(length));
FlatArray<T>.Builder.InternalOfLengthChecked(length);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ partial class Builder
// TODO: Add the tests and make public
internal Builder Add(T item)
{
if (items.Length == length)
if (length == items.Length)
{
InnerBufferHelper.EnlargeBuffer(ref items);
}
Expand Down
Loading

0 comments on commit 98856bb

Please sign in to comment.