-
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 branch 'main' into feature/item-ref-index
- Loading branch information
Showing
11 changed files
with
161 additions
and
98 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray.T/Cast/CanCastArray.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,146 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FlatArrayTest | ||
{ | ||
// Value types | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_ValueType_TypeTheSame_ExpectTrue_CaseSource))] | ||
public void CanCastArray_ValueType_TypeTheSame_ExpectTrue(FlatArray<byte> source) | ||
{ | ||
var actual = source.CanCastArray<byte>(); | ||
Assert.True(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<byte>> CanCastArray_ValueType_TypeTheSame_ExpectTrue_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<byte>().InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1 }.InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1, 2 }.InitializeFlatArray() | ||
} | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_ValueType_TypeCompatible_ExpectTrue_CaseSource))] | ||
public void CanCastArray_ValueType_TypeCompatible_ExpectTrue(FlatArray<byte> source) | ||
{ | ||
var actual = source.CanCastArray<sbyte>(); | ||
Assert.True(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<byte>> CanCastArray_ValueType_TypeCompatible_ExpectTrue_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<byte>().InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1 }.InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1, 2 }.InitializeFlatArray() | ||
} | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_ValueType_TypeIncompatible_ExpectFalse_CaseSource))] | ||
public void CanCastArray_ValueType_TypeIncompatible_ExpectFalse(FlatArray<byte> source) | ||
{ | ||
var actual = source.CanCastArray<ushort>(); | ||
Assert.False(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<byte>> CanCastArray_ValueType_TypeIncompatible_ExpectFalse_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<byte>().InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1 }.InitializeFlatArray() | ||
}, | ||
{ | ||
new byte[] { 1, 2 }.InitializeFlatArray() | ||
} | ||
}; | ||
|
||
// Reference types | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_RefType_TypeTheSame_ExpectTrue_CaseSource))] | ||
public void CanCastArray_RefType_TypeTheSame_ExpectTrue(FlatArray<string> source) | ||
{ | ||
var actual = source.CanCastArray<string>(); | ||
Assert.True(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<string>> CanCastArray_RefType_TypeTheSame_ExpectTrue_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<string>().InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { "1" }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { "1", "2" }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { null!, "1", "2" }.InitializeFlatArray() | ||
} | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_RefType_TypeCompatible_ExpectTrue_CaseSource))] | ||
public void CanCastArray_RefType_TypeCompatible_ExpectTrue(FlatArray<string> source) | ||
{ | ||
var actual = source.CanCastArray<object>(); | ||
Assert.True(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<string>> CanCastArray_RefType_TypeCompatible_ExpectTrue_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<string>().InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { "1" }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { "1", "2" }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { null!, "1", "2" }.InitializeFlatArray() | ||
} | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(CanCastArray_RefType_TypeIncompatible_ExpectFalse_CaseSource))] | ||
public void CanCastArray_RefType_TypeIncompatible_ExpectFalse(FlatArray<object> source) | ||
{ | ||
var actual = source.CanCastArray<string>(); | ||
Assert.False(actual); | ||
} | ||
|
||
public static TheoryData<FlatArray<object>> CanCastArray_RefType_TypeIncompatible_ExpectFalse_CaseSource => new() | ||
{ | ||
{ | ||
Array.Empty<object>().InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { new object() }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { new object(), new object() }.InitializeFlatArray() | ||
}, | ||
{ | ||
new[] { null!, new object(), new object() }.InitializeFlatArray() | ||
} | ||
}; | ||
} |
35 changes: 0 additions & 35 deletions
35
src/flatcollections-array/FlatArray.Tests/Tests.FlatArray/CastUp.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/flatcollections-array/FlatArray/FlatArray.T/Cast/Cast.CastArray.Can.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,8 @@ | ||
namespace System; | ||
|
||
partial struct FlatArray<T> | ||
{ | ||
public bool CanCastArray<TResult>() | ||
=> | ||
InnerItems() is TResult[]; | ||
} |
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
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
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
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
30 changes: 0 additions & 30 deletions
30
src/flatcollections-array/FlatArray/FlatArray.T/Functional/Functional.Cast.cs
This file was deleted.
Oops, something went wrong.
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
9 changes: 0 additions & 9 deletions
9
src/flatcollections-array/FlatArray/FlatArray/FlatArray.CastUp.cs
This file was deleted.
Oops, something went wrong.
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