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

feature/improve-dynamic-building #43

Merged
merged 8 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -13,4 +13,13 @@ internal static void VerifyInnerState<T>(this FlatArray<T> actual, T[]? expected
var actualItems = actual.GetFieldValue<T[]?>("items");
Assert.Equal(expectedItems, actualItems);
}

internal static void VerifyInnerState_TheSameAssert<T>(this FlatArray<T> actual, T[]? expectedItems, int expectedLength)
{
var actualLength = actual.GetStructFieldValue<int>("length");
Assert.StrictEqual(expectedLength, actualLength);

var actualItems = actual.GetFieldValue<T[]?>("items");
Assert.Same(expectedItems, actualItems);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
using System;
using System.Collections.Generic;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests.TestData;

internal class ReadingCollectionsTestSource
{
public static IEnumerable<object?[]> EnumerateStringNonEmptyCases()
{
yield return new object[]
{
new string?[] { null },
new string?[] { null, null, null, null }
};
yield return new object[]
{
new string[] { SomeString },
new string?[] { SomeString, null, null, null }
};
yield return new object[]
{
new string?[] { SomeString, null },
new string?[] { SomeString, null, null, null }
};
yield return new object[]
{
new string?[] { null, SomeString },
new string?[] { null, SomeString, null, null }
};
yield return new object[]
{
new string?[] { "0" },
new string?[] { "0", null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1" },
new string?[] { "0", "1", null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2" },
new string?[] { "0", "1", "2", null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3" },
new string?[] { "0", "1", "2", "3" }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4" },
new string?[] { "0", "1", "2", "3", "4", null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5" },
new string?[] { "0", "1", "2", "3", "4", "5", null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7" }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", null, null, null, null, null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", null, null, null, null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", null, null, null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", null, null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", null, null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", null, null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", null }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }
};
yield return new object[]
{
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" },
new string?[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null }
};
}

public static IEnumerable<object?[]> EnumerateInt32NullableNonEmptyCases()
{
yield return new object[]
{
new int?[] { null },
new int?[] { null, null, null, null }
};
yield return new object[]
{
new int?[] { MinusFifteen },
new int?[] { MinusFifteen, null, null, null }
};
yield return new object[]
{
new int?[] { MinusFifteen, null },
new int?[] { MinusFifteen, null, null, null }
};
yield return new object[]
{
new int?[] { null, MinusFifteen },
new int?[] { null, MinusFifteen, null, null }
};
yield return new object[]
{
new int?[] { 0 },
new int?[] { 0, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1 },
new int?[] { 0, 1, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2 },
new int?[] { 0, 1, 2, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3 },
new int?[] { 0, 1, 2, 3 }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4 },
new int?[] { 0, 1, 2, 3, 4, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5 },
new int?[] { 0, 1, 2, 3, 4, 5, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7 }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, null, null, null, null, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, null, null, null, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, null, null, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, null, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, null, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, null, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, null }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
};
yield return new object[]
{
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
new int?[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null }
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;
Expand All @@ -25,17 +26,26 @@ public void MoveToFlatArray_SourceIsDefault_ExpectBuilderStateIsDefault()
source.VerifyInnerState(Array.Empty<RefType>(), default);
}

[Fact]
public void MoveToFlatArray_SourceIsNotDefault_ExpectArrayItemsAreBuilderItems()
[Theory]
[MemberData(nameof(MoveToFlatArray_SourceIsNotDefault_ExpectInnerStateTheSameAsBuilderState_CaseSource))]
public void MoveToFlatArray_SourceIsNotDefault_ExpectInnerStateTheSameAsBuilderState(
int length,
RefType[] sourceItems)
{
const int length = 3;

var sourceItems = new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, ZeroIdRefType };
var source = sourceItems.InitializeFlatArrayBuilder(length);

var actual = source.MoveToFlatArray();
var expectedItems = new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, ZeroIdRefType };
actual.VerifyInnerState_TheSameAssert(sourceItems, length);
}

[Theory]
[MemberData(nameof(MoveToFlatArray_SourceIsNotDefault_WithHugeCapacity_ExpectInnerStateCorrespondToBuilderState_CaseSource))]
public void MoveToFlatArray_SourceIsNotDefault_WithHugeCapacity_ExpectInnerStateCorrespondToBuilderState(
int length,
RefType[] sourceItems,
RefType[] expectedItems)
{
var source = sourceItems.InitializeFlatArrayBuilder(length);
var actual = source.MoveToFlatArray();
actual.VerifyInnerState(expectedItems, length);
}

Expand All @@ -47,4 +57,62 @@ public void MoveToFlatArray_SourceIsNotDefault_ExpectBuilderStateIsDefault()

source.VerifyInnerState(Array.Empty<int>(), default);
}
}

public static IEnumerable<object[]> MoveToFlatArray_SourceIsNotDefault_ExpectInnerStateTheSameAsBuilderState_CaseSource()
{
yield return new object[]
{
2,
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType }
};
yield return new object[]
{
2,
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType, null }
};
yield return new object[]
{
3,
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType }
};
yield return new object[]
{
3,
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, null }
};
yield return new object[]
{
3,
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, null, null }
};
}


public static IEnumerable<object[]> MoveToFlatArray_SourceIsNotDefault_WithHugeCapacity_ExpectInnerStateCorrespondToBuilderState_CaseSource()
{
yield return new object[]
{
2,
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType, null, null },
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType }
};
yield return new object[]
{
2,
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType, null, null, null },
new[] { PlusFifteenIdRefType, MinusFifteenIdRefType }
};
yield return new object[]
{
3,
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, null, null, null },
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType }
};
yield return new object[]
{
3,
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType, null, null, null, null },
new[] { PlusFifteenIdRefType, null, MinusFifteenIdRefType }
};
}
}
Loading