-
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.
Add Slice_SourceNotEmpty_OutOfRange_ExpectArgumentOutOfRangeException…
… test
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
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; | ||
} | ||
} | ||
} |