Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v1.2.0-rc.1 #48

Merged
merged 52 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e301a86
v1.2.0-rc.1
andreise Aug 16, 2023
be49d92
Fix a comment
andreise Aug 16, 2023
41f0855
Remove OfLength with capacity
andreise Aug 16, 2023
b78ce10
Improve OfLength initialization; Minor refactor
andreise Aug 16, 2023
ff635f7
Update a test dependency
andreise Aug 16, 2023
1f13000
Fix InnerBufferHelper visibility
andreise Aug 16, 2023
dc45931
Minor refactor
andreise Aug 16, 2023
00b1a99
Add Capacity property
andreise Aug 16, 2023
ef6160a
Minor refactor
andreise Aug 16, 2023
33931fd
Remove premature protections
andreise Aug 16, 2023
b37beb3
Minor refactor
andreise Aug 16, 2023
d83be64
Remove a redundant comment
andreise Aug 16, 2023
9b34f24
Simplify MoveToFlatArray model
andreise Aug 16, 2023
443e872
Make Builder TrimExcess fluent
andreise Aug 16, 2023
bf534d3
Remove redundant Builder TrimExcess
andreise Aug 16, 2023
4ee5b7c
Minor improvement/refactor/update comments
andreise Aug 16, 2023
2e57e6b
Use more efficient copying array
andreise Aug 18, 2023
af1c5c3
Remove redundant comments
andreise Aug 18, 2023
857a67a
Use Spans in Builder
andreise Aug 18, 2023
c5dc084
Minor refactor
andreise Aug 18, 2023
5df73e4
Use Spans when concatenation of arrays
andreise Aug 18, 2023
abb4d4e
Minor refactor
andreise Aug 18, 2023
d1bfd20
Fix InnerAddRange
andreise Aug 19, 2023
432daa2
Minor refactor/improvement
andreise Aug 19, 2023
00a4270
Fix AddRange for FlatArray
andreise Aug 19, 2023
e782ce6
Refactor
andreise Aug 19, 2023
26425e9
Fix AddRange for FlatArray
andreise Aug 19, 2023
cbbeacf
Remove redundant comments
andreise Aug 19, 2023
caede77
Impove tests
andreise Aug 19, 2023
28c6e07
Minor improvement
andreise Aug 19, 2023
e7cd61b
Revert a premature improvement
andreise Aug 19, 2023
f1244c5
Revert "Revert a premature improvement"
andreise Aug 20, 2023
bc2214b
Revert "Minor improvement"
andreise Aug 20, 2023
cf19bad
Add a Debug.Assert
andreise Aug 20, 2023
a945c2a
Minor refactor
andreise Aug 20, 2023
a834c66
Add readonly modifier to FlatArray.Enumerator.Current
andreise Aug 20, 2023
66970aa
FlatArray.Builder.Enumerator.Current: supress make member readonly su…
andreise Aug 20, 2023
d9912ef
Minor improvement; Clean redundant comments
andreise Aug 20, 2023
3aed72d
Add Builder methods / building factories
andreise Aug 20, 2023
204c453
Clean usings
andreise Aug 20, 2023
f814aec
Add Cast / TryCast / CastUp methods
andreise Aug 20, 2023
b0d60d7
Fix a typo
andreise Aug 20, 2023
ab681d3
Add DoesNotReturn to an obsolete
andreise Aug 20, 2023
9fc694a
Format comment
andreise Aug 20, 2023
fdf370a
Add an IsWithin check for range
andreise Aug 20, 2023
66d5fa0
Implement From factories start/length segment based
andreise Aug 21, 2023
b78d48d
Improve FlatMap tests
andreise Aug 21, 2023
ec115b2
Improve FlatMap test cases
andreise Aug 21, 2023
adaa521
Minor refactor
andreise Aug 21, 2023
edd1771
Fix From segment factories
andreise Aug 21, 2023
9eefc22
Minor refactor
andreise Aug 21, 2023
1decb8a
Minor refactor
andreise Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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