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.3.0-rc.2 #64

Merged
merged 16 commits into from
Jan 13, 2024
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 @@ -8,9 +8,15 @@ namespace PrimeFuncPack.Core.Tests;
partial class FlatArrayBuilderTest
{
[Theory]
[InlineData(int.MinValue)]
[InlineData(int.MinValue + 1)]
[InlineData(MinusFifteen)]
[InlineData(-1)]
[InlineData(0)]
[InlineData(1)]
[InlineData(PlusFifteen)]
[InlineData(int.MaxValue - 1)]
[InlineData(int.MaxValue)]
public void Indexer_SourceIsDefault_ExpectIndexOutOfRangeException(int index)
{
var source = new FlatArray<StructType>.Builder();
Expand All @@ -19,10 +25,16 @@ public void Indexer_SourceIsDefault_ExpectIndexOutOfRangeException(int index)
}

[Theory]
[InlineData(0, 1, TabString)]
[InlineData(0, 1, EmptyString)]
[InlineData(0, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(1, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(2, 3, AnotherString, AnotherString, null, SomeString)]
[InlineData(3, 4, "Zero", "One", "Two", "Three")]
[InlineData(0, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(1, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(2, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(0, 4, null, "One", "Two", "Three")]
[InlineData(1, 4, null, "One", "Two", "Three")]
[InlineData(2, 4, null, "One", "Two", "Three")]
[InlineData(3, 4, null, "One", "Two", "Three")]
public void Indexer_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
int index, int sourceLength, params string?[] sourceItems)
{
Expand All @@ -35,10 +47,42 @@ public void Indexer_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
}

[Theory]
// Effective Length: 1, Inner array length: 1
[InlineData(int.MinValue, 1, SomeString)]
[InlineData(int.MinValue + 1, 1, SomeString)]
[InlineData(MinusFifteen, 1, SomeString)]
[InlineData(-1, 1, SomeString)]
[InlineData(1, 1, SomeString)]
[InlineData(1, 1, AnotherString, SomeString)]
[InlineData(5, 2, EmptyString, TabString)]
[InlineData(PlusFifteen, 1, SomeString)]
[InlineData(int.MaxValue - 1, 1, SomeString)]
[InlineData(int.MaxValue, 1, SomeString)]
// Effective Length: 1, Inner array length: 2
[InlineData(int.MinValue, 1, EmptyString, AnotherString)]
[InlineData(int.MinValue + 1, 1, EmptyString, AnotherString)]
[InlineData(MinusFifteen, 1, EmptyString, AnotherString)]
[InlineData(-1, 1, EmptyString, AnotherString)]
[InlineData(1, 1, EmptyString, AnotherString)]
[InlineData(PlusFifteen, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue - 1, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue, 1, EmptyString, AnotherString)]
// Effective Length: 2, Inner array length: 2
[InlineData(int.MinValue, 2, EmptyString, SomeString)]
[InlineData(int.MinValue + 1, 2, EmptyString, SomeString)]
[InlineData(MinusFifteen, 2, EmptyString, SomeString)]
[InlineData(-1, 2, EmptyString, SomeString)]
[InlineData(2, 2, EmptyString, SomeString)]
[InlineData(PlusFifteen, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue - 1, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue, 2, EmptyString, SomeString)]
// Effective Length: 3, Inner array length: 3
[InlineData(int.MinValue, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MinValue + 1, 3, LowerSomeString, null, SomeString)]
[InlineData(MinusFifteen, 3, LowerSomeString, null, SomeString)]
[InlineData(-1, 3, LowerSomeString, null, SomeString)]
[InlineData(3, 3, LowerSomeString, null, SomeString)]
[InlineData(PlusFifteen, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue - 1, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue, 3, LowerSomeString, null, SomeString)]
public void Indexer_IndexIsOutOfRange_ExpectIndexOutOfRangeException(
int index, int sourceLength, params string?[] sourceItems)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayBuilderTest
{
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(PlusFifteen)]
[InlineData(int.MaxValue - 1)]
[InlineData(int.MaxValue)]
public void IndexerRef_IndexFromEnd_SourceIsDefault_ExpectIndexOutOfRangeException(int indexFromEnd)
{
var fromEnd = Index.FromEnd(indexFromEnd);

var source = new FlatArray<StructType>.Builder();

_ = Assert.Throws<IndexOutOfRangeException>(() => _ = source.ItemRef(fromEnd));
}

[Theory]
[InlineData(0, 1, 1, EmptyString)]
[InlineData(0, 2, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(0, 3, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(0, 4, 4, null, "One", "Two", "Three")]
[InlineData(1, 1, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(2, 1, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(3, 1, 4, null, "One", "Two", "Three")]
public void IndexerRef_IndexFromEnd_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
int index, int indexFromEnd, int sourceLength, params string?[] sourceItems)
{
var fromEnd = Index.FromEnd(indexFromEnd);

var source = sourceItems.InitializeFlatArrayBuilder(sourceLength);

var actual = source.ItemRef(fromEnd);
var expected = sourceItems[index];

Assert.Equal(expected, actual);
}

[Theory]
// Effective Length: 1, Inner array length: 1
[InlineData(0, 1, SomeString)]
[InlineData(2, 1, SomeString)]
[InlineData(int.MaxValue - 1, 1, SomeString)]
[InlineData(int.MaxValue, 1, SomeString)]
// Effective Length: 1, Inner array length: 2
[InlineData(0, 1, EmptyString, AnotherString)]
[InlineData(2, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue - 1, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue, 1, EmptyString, AnotherString)]
// Effective Length: 2, Inner array length: 2
[InlineData(0, 2, EmptyString, SomeString)]
[InlineData(3, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue - 1, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue, 2, EmptyString, SomeString)]
// Effective Length: 3, Inner array length: 3
[InlineData(0, 3, LowerSomeString, null, SomeString)]
[InlineData(4, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue - 1, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue, 3, LowerSomeString, null, SomeString)]
public void IndexerRef_IndexFromEnd_IndexIsOutOfRange_ExpectIndexOutOfRangeException(
int indexFromEnd, int sourceLength, params string?[] sourceItems)
{
var fromEnd = Index.FromEnd(indexFromEnd);

var source = sourceItems.InitializeFlatArrayBuilder(sourceLength);

_ = Assert.Throws<IndexOutOfRangeException>(() => _ = source.ItemRef(fromEnd));
}
}
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 FlatArrayBuilderTest
{
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(PlusFifteen)]
[InlineData(int.MaxValue - 1)]
[InlineData(int.MaxValue)]
public void IndexerRef_IndexFromStart_SourceIsDefault_ExpectIndexOutOfRangeException(int index)
{
var fromStart = Index.FromStart(index);

var source = new FlatArray<StructType>.Builder();

_ = Assert.Throws<IndexOutOfRangeException>(() => _ = source.ItemRef(fromStart));
}

[Theory]
[InlineData(0, 1, EmptyString)]
[InlineData(0, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(1, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(0, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(1, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(2, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(0, 4, null, "One", "Two", "Three")]
[InlineData(1, 4, null, "One", "Two", "Three")]
[InlineData(2, 4, null, "One", "Two", "Three")]
[InlineData(3, 4, null, "One", "Two", "Three")]
public void IndexerRef_IndexFromStart_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
int index, int sourceLength, params string?[] sourceItems)
{
var fromStart = Index.FromStart(index);

var source = sourceItems.InitializeFlatArrayBuilder(sourceLength);

var actual = source.ItemRef(fromStart);
var expected = sourceItems[index];

Assert.Equal(expected, actual);
}

[Theory]
// Effective Length: 1, Inner array length: 1
[InlineData(1, 1, SomeString)]
[InlineData(PlusFifteen, 1, SomeString)]
[InlineData(int.MaxValue - 1, 1, SomeString)]
[InlineData(int.MaxValue, 1, SomeString)]
// Effective Length: 1, Inner array length: 2
[InlineData(1, 1, EmptyString, AnotherString)]
[InlineData(PlusFifteen, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue - 1, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue, 1, EmptyString, AnotherString)]
// Effective Length: 2, Inner array length: 2
[InlineData(2, 2, EmptyString, SomeString)]
[InlineData(PlusFifteen, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue - 1, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue, 2, EmptyString, SomeString)]
// Effective Length: 3, Inner array length: 3
[InlineData(3, 3, LowerSomeString, null, SomeString)]
[InlineData(PlusFifteen, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue - 1, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue, 3, LowerSomeString, null, SomeString)]
public void IndexerRef_IndexFromStart_IndexIsOutOfRange_ExpectIndexOutOfRangeException(
int index, int sourceLength, params string?[] sourceItems)
{
var fromStart = Index.FromStart(index);

var source = sourceItems.InitializeFlatArrayBuilder(sourceLength);

_ = Assert.Throws<IndexOutOfRangeException>(() => _ = source.ItemRef(fromStart));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ namespace PrimeFuncPack.Core.Tests;
partial class FlatArrayBuilderTest
{
[Theory]
[InlineData(int.MinValue)]
[InlineData(int.MinValue + 1)]
[InlineData(MinusFifteen)]
[InlineData(-1)]
[InlineData(0)]
[InlineData(1)]
[InlineData(PlusFifteen)]
[InlineData(int.MaxValue - 1)]
[InlineData(int.MaxValue)]
public void IndexerRef_SourceIsDefault_ExpectIndexOutOfRangeException(int index)
{
var source = new FlatArray<StructType>.Builder();
Expand All @@ -19,10 +25,16 @@ public void IndexerRef_SourceIsDefault_ExpectIndexOutOfRangeException(int index)
}

[Theory]
[InlineData(0, 1, TabString)]
[InlineData(0, 1, EmptyString)]
[InlineData(0, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(1, 2, AnotherString, SomeString, LowerSomeString)]
[InlineData(2, 3, AnotherString, AnotherString, null, SomeString)]
[InlineData(3, 4, "Zero", "One", "Two", "Three")]
[InlineData(0, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(1, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(2, 3, SomeString, AnotherString, null, LowerSomeString)]
[InlineData(0, 4, null, "One", "Two", "Three")]
[InlineData(1, 4, null, "One", "Two", "Three")]
[InlineData(2, 4, null, "One", "Two", "Three")]
[InlineData(3, 4, null, "One", "Two", "Three")]
public void IndexerRef_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
int index, int sourceLength, params string?[] sourceItems)
{
Expand All @@ -35,10 +47,42 @@ public void IndexerRef_IndexIsInRange_ExpectItemIsFromSourceItemsByIndex(
}

[Theory]
// Effective Length: 1, Inner array length: 1
[InlineData(int.MinValue, 1, SomeString)]
[InlineData(int.MinValue + 1, 1, SomeString)]
[InlineData(MinusFifteen, 1, SomeString)]
[InlineData(-1, 1, SomeString)]
[InlineData(1, 1, SomeString)]
[InlineData(1, 1, AnotherString, SomeString)]
[InlineData(5, 2, EmptyString, TabString)]
[InlineData(PlusFifteen, 1, SomeString)]
[InlineData(int.MaxValue - 1, 1, SomeString)]
[InlineData(int.MaxValue, 1, SomeString)]
// Effective Length: 1, Inner array length: 2
[InlineData(int.MinValue, 1, EmptyString, AnotherString)]
[InlineData(int.MinValue + 1, 1, EmptyString, AnotherString)]
[InlineData(MinusFifteen, 1, EmptyString, AnotherString)]
[InlineData(-1, 1, EmptyString, AnotherString)]
[InlineData(1, 1, EmptyString, AnotherString)]
[InlineData(PlusFifteen, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue - 1, 1, EmptyString, AnotherString)]
[InlineData(int.MaxValue, 1, EmptyString, AnotherString)]
// Effective Length: 2, Inner array length: 2
[InlineData(int.MinValue, 2, EmptyString, SomeString)]
[InlineData(int.MinValue + 1, 2, EmptyString, SomeString)]
[InlineData(MinusFifteen, 2, EmptyString, SomeString)]
[InlineData(-1, 2, EmptyString, SomeString)]
[InlineData(2, 2, EmptyString, SomeString)]
[InlineData(PlusFifteen, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue - 1, 2, EmptyString, SomeString)]
[InlineData(int.MaxValue, 2, EmptyString, SomeString)]
// Effective Length: 3, Inner array length: 3
[InlineData(int.MinValue, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MinValue + 1, 3, LowerSomeString, null, SomeString)]
[InlineData(MinusFifteen, 3, LowerSomeString, null, SomeString)]
[InlineData(-1, 3, LowerSomeString, null, SomeString)]
[InlineData(3, 3, LowerSomeString, null, SomeString)]
[InlineData(PlusFifteen, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue - 1, 3, LowerSomeString, null, SomeString)]
[InlineData(int.MaxValue, 3, LowerSomeString, null, SomeString)]
public void IndexerRef_IndexIsOutOfRange_ExpectIndexOutOfRangeException(
int index, int sourceLength, params string?[] sourceItems)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if NET8_0_OR_GREATER
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayBuilderTest
{
[Fact]
public static void ConstructFromCollectionExpression_SourceIsEmpty_ExpectDefault()
{
FlatArray<string?>.Builder actual = [];
actual.VerifyInnerState([], default);
}

[Fact]
public static void ConstructFromCollectionExpression_SourceIsNotEmpty_ExpectInnerStateIsSourceCollection()
{
FlatArray<string?>.Builder actual = [ SomeString, null, EmptyString, WhiteSpaceString, AnotherString ];
string?[] expectedItems = [ SomeString, null, EmptyString, WhiteSpaceString, AnotherString ];

actual.VerifyInnerState(expectedItems, expectedItems.Length);
}
}
#endif
Loading