-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from pfpack/release/1.4.0-rc.2
release/v1.4.0-rc.2
- Loading branch information
Showing
19 changed files
with
446 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ctions-array/FlatArray.Tests/Tests.FlatArray.T/Array/Array.Slice.SourceIsEmpty_InRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...ons-array/FlatArray.Tests/Tests.FlatArray.T/Array/Array.Slice.SourceIsEmpty_OutOfRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...tions-array/FlatArray.Tests/Tests.FlatArray.T/Array/Array.Slice.SourceNotEmpty_InRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ns-array/FlatArray.Tests/Tests.FlatArray.T/Array/Array.Slice.SourceNotEmpty_OutOfRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...llections-array/FlatArray.Tests/Tests.FlatArray.T/Array/Array.SliceOperator.OutOfRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rray/FlatArray.Tests/Tests.FlatArray.T/Array/Array.SliceOperator.SourceIsEmpty_InRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.