-
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.
- Loading branch information
pmosk
committed
Jan 11, 2024
1 parent
1a4f6fa
commit 299c50e
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Cast/TryCastArray.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,78 @@ | ||
using System; | ||
using Xunit; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FlatArrayTest | ||
{ | ||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public static void TryCastArray_CastIsInvalid_ExpectNull( | ||
bool isSourceDefault) | ||
{ | ||
var source = isSourceDefault ? default : new[] { PlusFifteen, Zero }.InitializeFlatArray(); | ||
var actual = source.TryCastArray<string>(); | ||
|
||
Assert.Null(actual); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(TryCastArray_CastValueTypeIsValid_ExpectCastedInnerState_TestSource))] | ||
public static void TryCastArray_CastValueTypeIsValid_ExpectCastedInnerState( | ||
FlatArray<int> source, uint[]? expectedItems) | ||
{ | ||
var actual = source.TryCastArray<uint>(); | ||
|
||
Assert.NotNull(actual); | ||
actual.Value.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(TryCastArray_CastRefTypeIsValid_ExpectCastedInnerState_TestSource))] | ||
public static void TryCastArray_CastRefTypeIsValid_ExpectCastedInnerState( | ||
FlatArray<string?> source, object?[]? expectedItems) | ||
{ | ||
var actual = source.TryCastArray<object?>(); | ||
|
||
Assert.NotNull(actual); | ||
actual.Value.VerifyTruncatedState(expectedItems); | ||
} | ||
|
||
public static TheoryData<FlatArray<int>, uint[]?> TryCastArray_CastValueTypeIsValid_ExpectCastedInnerState_TestSource | ||
=> | ||
new() | ||
{ | ||
{ | ||
default, | ||
default | ||
}, | ||
{ | ||
new int[] { PlusFifteen, Zero, One }.InitializeFlatArray(), | ||
[ PlusFifteen, Zero, One ] | ||
}, | ||
{ | ||
new int[] { int.MaxValue, One, PlusFifteen, Zero, MinusOne }.InitializeFlatArray(4), | ||
[ int.MaxValue, One, PlusFifteen, Zero ] | ||
} | ||
}; | ||
|
||
public static TheoryData<FlatArray<string?>, object?[]?> TryCastArray_CastRefTypeIsValid_ExpectCastedInnerState_TestSource | ||
=> | ||
new() | ||
{ | ||
{ | ||
default, | ||
default | ||
}, | ||
{ | ||
new string?[] { SomeString, null }.InitializeFlatArray(), | ||
[ SomeString, null ] | ||
}, | ||
{ | ||
new string?[] { null, AnotherString, EmptyString, UpperAnotherString, WhiteSpaceString }.InitializeFlatArray(3), | ||
[ null, AnotherString, EmptyString ] | ||
} | ||
}; | ||
} |
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