Skip to content

Commit

Permalink
Merge pull request #74 from pfpack/release/1.4.0-rc.2
Browse files Browse the repository at this point in the history
release/v1.4.0-rc.2
  • Loading branch information
andreise authored Mar 13, 2024
2 parents 2f7df6d + 45863cd commit f7a7774
Show file tree
Hide file tree
Showing 19 changed files with 446 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(Slice_SourceIsEmpty_InRange_ExpectDefault_CaseSource))]
public void Slice_SourceIsEmpty_InRange_ExpectDefault(FlatArray<int> source)
{
#pragma warning disable IDE0057 // Use range operator
var actual = source.Slice(0, 0);
#pragma warning restore IDE0057 // Use range operator
actual.VerifyInnerState_Default();
}

public static TheoryData<FlatArray<int>> Slice_SourceIsEmpty_InRange_ExpectDefault_CaseSource
{
get
{
FlatArray<int>[] sources =
[
default,
new[] { MinusFifteen }.InitializeFlatArray(0),
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(0),
];
return new(sources);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;
using static System.FormattableString;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(Slice_SourceIsEmpty_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource))]
public void Slice_SourceIsEmpty_OutOfRange_ExpectArgumentOutOfRangeException(
FlatArray<int> source,
int start,
int length)
{
var actualException = Assert.Throws<ArgumentOutOfRangeException>(() => _ = source.Slice(start, length));
var expectedMessage = Invariant(
$"Segment must be within the array bounds. Segment start was {start}. Segment length was {length}. Array length was {source.Length}.");
Assert.Equal(expectedMessage, actualException.Message);
}

public static TheoryData<FlatArray<int>, int, int> Slice_SourceIsEmpty_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource
{
get
{
FlatArray<int>[] sources =
[
default,
new[] { MinusFifteen }.InitializeFlatArray(0),
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(0),
];

IReadOnlyCollection<(int Start, int Length)> segments =
[
(0, 1),
(0, int.MaxValue),
(0, -1),
(0, int.MinValue),
(1, 1),
(1, 2),
(1, -1),
(1, 0),
(2, 1),
(-1, -2),
(-1, int.MinValue),
(-1, 0),
(-1, 1),
(-1, int.MaxValue),
(1, int.MinValue),
(1, int.MaxValue),
(int.MinValue, 0),
(int.MaxValue, 0),
(int.MinValue, int.MinValue),
(int.MaxValue, int.MaxValue),
(int.MaxValue, int.MinValue),
(int.MinValue, int.MaxValue)
];
Debug.Assert(segments.Distinct().Count() == segments.Count);

TheoryData<FlatArray<int>, int, int> result = [];
foreach (var source in sources)
{
foreach (var (Start, Length) in segments)
{
result.Add(source, Start, Length);
}
}
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(Slice_SourceNotEmpty_InRange_ExpectCorrectResult_CaseSource))]
public void Slice_SourceNotEmpty_InRange_ExpectCorrectResult(
FlatArray<int> source,
int start,
int length,
int[]? expectedItems)
{
var actual = source.Slice(start, length);
actual.VerifyInnerState(expectedItems, expectedItems?.Length ?? default);
}

public static TheoryData<FlatArray<int>, int, int, int[]?> Slice_SourceNotEmpty_InRange_ExpectCorrectResult_CaseSource
{
get
{
TheoryData<FlatArray<int>, int, int, int[]?> result = [];

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
0, 0,
null);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
1, 0,
null);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
0, 1,
[MinusFifteen]);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
1, 1,
[PlusFifteen]);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen }.InitializeFlatArray(),
1, 2,
[MinusOne, Zero]);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen, int.MinValue }.InitializeFlatArray(5),
0, 3,
[MinusFifteen, MinusOne, Zero]);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen, int.MaxValue }.InitializeFlatArray(5),
1, 4,
[MinusOne, Zero, One, PlusFifteen]);

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;
using static System.FormattableString;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(Slice_SourceNotEmpty_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource))]
public void Slice_SourceNotEmpty_OutOfRange_ExpectArgumentOutOfRangeException(
FlatArray<int> source,
int start,
int length)
{
var actualException = Assert.Throws<ArgumentOutOfRangeException>(() => _ = source.Slice(start, length));
var expectedMessage = Invariant(
$"Segment must be within the array bounds. Segment start was {start}. Segment length was {length}. Array length was {source.Length}.");
Assert.Equal(expectedMessage, actualException.Message);
}

public static TheoryData<FlatArray<int>, int, int> Slice_SourceNotEmpty_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource
{
get
{
TheoryData<FlatArray<int>, int, int> result = [];

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
-1, 0);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
0, 2);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(),
2, 0);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
2, 1);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
3, 1);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen }.InitializeFlatArray(),
5, int.MaxValue);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen, int.MinValue }.InitializeFlatArray(5),
4, 2);

result.Add(
new[] { MinusFifteen, MinusOne, Zero, One, PlusFifteen, int.MaxValue }.InitializeFlatArray(5),
int.MinValue, int.MaxValue);

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(SliceOperator_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource))]
public void SliceOperator_OutOfRange_ExpectArgumentOutOfRangeException(
FlatArray<int> source,
Range range)
{
var actualException = Assert.Throws<ArgumentOutOfRangeException>(() => _ = source[range]);
Assert.StartsWith("Segment must be within the array bounds.", actualException.Message);
}

public static TheoryData<FlatArray<int>, Range> SliceOperator_OutOfRange_ExpectArgumentOutOfRangeException_CaseSource
{
get
{
TheoryData<FlatArray<int>, Range> result = [];

result.Add(
default,
..1);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(0),
1..2);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
..3);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
2..0);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
2..1);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
2..3);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(),
2..4);

result.Add(
new[] { MinusFifteen, PlusFifteen, MinusOne, One }.InitializeFlatArray(3),
1..4);

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;

partial class FlatArrayTest
{
[Theory]
[MemberData(nameof(SliceOperator_SourceIsEmpty_InRange_ExpectCorrectResult_CaseSource))]
public void SliceOperator_SourceIsEmpty_InRange_ExpectCorrectResult(
FlatArray<int> source,
Range range)
{
var actual = source[range];
actual.VerifyInnerState_Default();
}

public static TheoryData<FlatArray<int>, Range> SliceOperator_SourceIsEmpty_InRange_ExpectCorrectResult_CaseSource
{
get
{
TheoryData<FlatArray<int>, Range> result = [];

result.Add(
default,
..);

result.Add(
default,
..0);

result.Add(
new[] { MinusFifteen }.InitializeFlatArray(0),
..);

result.Add(
new[] { MinusFifteen, PlusFifteen }.InitializeFlatArray(0),
..0);

return result;
}
}
}
Loading

0 comments on commit f7a7774

Please sign in to comment.