mirror of
https://github.com/chylex/.NET-Community-Toolkit.git
synced 2025-02-24 15:46:02 +01:00
More whitespaces and code style tweaks
This commit is contained in:
parent
a1db2247fc
commit
eab4b9ed28
tests
CommunityToolkit.Common.UnitTests
Collections
Extensions
CommunityToolkit.HighPerformance.UnitTests
Enumerables
Extensions
Test_ArrayExtensions.2D.csTest_ReadOnlySpanExtensions.csTest_SpanExtensions.csTest_SpinLockExtensions.cs
Helpers
Memory
CommunityToolkit.Mvvm.UnitTests
@ -443,45 +443,53 @@ public void ReplaceGroupInSource_ShoudReplaceGroup()
|
||||
private static bool IsAddEventValid(NotifyCollectionChangedEventArgs args, IEnumerable<int> expectedGroupItems, int addIndex)
|
||||
{
|
||||
IEnumerable<IEnumerable<int>>? newItems = args.NewItems?.Cast<IEnumerable<int>>();
|
||||
return args.Action == NotifyCollectionChangedAction.Add &&
|
||||
args.NewStartingIndex == addIndex &&
|
||||
args.OldItems == null &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedGroupItems);
|
||||
|
||||
return
|
||||
args.Action == NotifyCollectionChangedAction.Add &&
|
||||
args.NewStartingIndex == addIndex &&
|
||||
args.OldItems == null &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedGroupItems);
|
||||
}
|
||||
|
||||
private static bool IsRemoveEventValid(NotifyCollectionChangedEventArgs args, IEnumerable<int> expectedGroupItems, int oldIndex)
|
||||
{
|
||||
IEnumerable<IEnumerable<int>>? oldItems = args.OldItems?.Cast<IEnumerable<int>>();
|
||||
return args.Action == NotifyCollectionChangedAction.Remove &&
|
||||
args.NewItems == null &&
|
||||
args.OldStartingIndex == oldIndex &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedGroupItems);
|
||||
|
||||
return
|
||||
args.Action == NotifyCollectionChangedAction.Remove &&
|
||||
args.NewItems == null &&
|
||||
args.OldStartingIndex == oldIndex &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedGroupItems);
|
||||
}
|
||||
|
||||
private static bool IsMoveEventValid(NotifyCollectionChangedEventArgs args, IEnumerable<int> expectedGroupItems, int oldIndex, int newIndex)
|
||||
{
|
||||
IEnumerable<IEnumerable<int>>? oldItems = args.OldItems?.Cast<IEnumerable<int>>();
|
||||
IEnumerable<IEnumerable<int>>? newItems = args.NewItems?.Cast<IEnumerable<int>>();
|
||||
return args.Action == NotifyCollectionChangedAction.Move &&
|
||||
args.OldStartingIndex == oldIndex &&
|
||||
args.NewStartingIndex == newIndex &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedGroupItems) &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedGroupItems);
|
||||
|
||||
return
|
||||
args.Action == NotifyCollectionChangedAction.Move &&
|
||||
args.OldStartingIndex == oldIndex &&
|
||||
args.NewStartingIndex == newIndex &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedGroupItems) &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedGroupItems);
|
||||
}
|
||||
|
||||
private static bool IsReplaceEventValid(NotifyCollectionChangedEventArgs args, IEnumerable<int> expectedRemovedItems, IEnumerable<int> expectedAddItems)
|
||||
{
|
||||
IEnumerable<IEnumerable<int>>? oldItems = args.OldItems?.Cast<IEnumerable<int>>();
|
||||
IEnumerable<IEnumerable<int>>? newItems = args.NewItems?.Cast<IEnumerable<int>>();
|
||||
return args.Action == NotifyCollectionChangedAction.Replace &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedRemovedItems) &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedAddItems);
|
||||
|
||||
return
|
||||
args.Action == NotifyCollectionChangedAction.Replace &&
|
||||
oldItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(oldItems.ElementAt(0), expectedRemovedItems) &&
|
||||
newItems?.Count() == 1 &&
|
||||
Enumerable.SequenceEqual(newItems.ElementAt(0), expectedAddItems);
|
||||
}
|
||||
|
||||
private static bool IsResetEventValid(NotifyCollectionChangedEventArgs args) => args.Action == NotifyCollectionChangedAction.Reset && args.NewItems == null && args.OldItems == null;
|
||||
|
@ -18,10 +18,10 @@ public void Test_ArrayExtensions_Jagged_GetColumn()
|
||||
{
|
||||
int[][] array =
|
||||
{
|
||||
new int[] { 5, 2, 4 },
|
||||
new int[] { 6, 3 },
|
||||
new int[] { 7 }
|
||||
};
|
||||
new int[] { 5, 2, 4 },
|
||||
new int[] { 6, 3 },
|
||||
new int[] { 7 }
|
||||
};
|
||||
|
||||
int[]? col = array.GetColumn(1).ToArray();
|
||||
|
||||
@ -34,20 +34,20 @@ public void Test_ArrayExtensions_Jagged_GetColumn_Exception()
|
||||
{
|
||||
int[][] array =
|
||||
{
|
||||
new int[] { 5, 2, 4 },
|
||||
new int[] { 6, 3 },
|
||||
new int[] { 7 }
|
||||
};
|
||||
new int[] { 5, 2, 4 },
|
||||
new int[] { 6, 3 },
|
||||
new int[] { 7 }
|
||||
};
|
||||
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
_ = array.GetColumn(-1).ToArray();
|
||||
});
|
||||
{
|
||||
_ = array.GetColumn(-1).ToArray();
|
||||
});
|
||||
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
_ = array.GetColumn(3).ToArray();
|
||||
});
|
||||
{
|
||||
_ = array.GetColumn(3).ToArray();
|
||||
});
|
||||
}
|
||||
|
||||
[TestCategory("ArrayExtensions")]
|
||||
@ -56,10 +56,10 @@ public void Test_ArrayExtensions_Rectangular_ToString()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 5, 2, 4 },
|
||||
{ 6, 3, -1 },
|
||||
{ 7, 0, 9 }
|
||||
};
|
||||
{ 5, 2, 4 },
|
||||
{ 6, 3, -1 },
|
||||
{ 7, 0, 9 }
|
||||
};
|
||||
|
||||
string value = array.ToArrayString();
|
||||
|
||||
@ -74,10 +74,10 @@ public void Test_ArrayExtensions_Jagged_ToString()
|
||||
{
|
||||
int[][] array =
|
||||
{
|
||||
new int[] { 5, 2 },
|
||||
new int[] { 6, 3, -1, 2 },
|
||||
new int[] { 7, 0, 9 }
|
||||
};
|
||||
new int[] { 5, 2 },
|
||||
new int[] { 6, 3, -1, 2 },
|
||||
new int[] { 7, 0, 9 }
|
||||
};
|
||||
|
||||
string value = array.ToArrayString();
|
||||
|
||||
|
@ -91,9 +91,9 @@ public void Test_EventHandlerExtensions_MultipleHandlersCauseAwait(int firstToRe
|
||||
{
|
||||
TaskCompletionSource<bool>[]? tsc = new[]
|
||||
{
|
||||
new TaskCompletionSource<bool>(),
|
||||
new TaskCompletionSource<bool>()
|
||||
};
|
||||
new TaskCompletionSource<bool>(),
|
||||
new TaskCompletionSource<bool>()
|
||||
};
|
||||
|
||||
TestClass? testClass = new();
|
||||
|
||||
|
@ -24,11 +24,11 @@ public void Test_ReadOnlyRefEnumerable_DangerousCreate_Ok(int length, int step,
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], length, step);
|
||||
|
||||
@ -58,11 +58,11 @@ public void Test_ReadOnlyRefEnumerable_Indexer(int step, int[] values)
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], values.Length, step);
|
||||
|
||||
@ -78,8 +78,8 @@ public void Test_ReadOnlyRefEnumerable_Indexer_ThrowsIndexOutOfRange()
|
||||
{
|
||||
int[] array = new[]
|
||||
{
|
||||
0, 0, 0, 0
|
||||
};
|
||||
0, 0, 0, 0
|
||||
};
|
||||
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => ReadOnlyRefEnumerable<int>.DangerousCreate(in array[0], array.Length, 1)[-1]);
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => ReadOnlyRefEnumerable<int>.DangerousCreate(in array[0], array.Length, 1)[array.Length]);
|
||||
@ -96,11 +96,11 @@ public void Test_ReadOnlyRefEnumerable_Index_Indexer(int step, int[] values)
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], values.Length, step);
|
||||
|
||||
@ -116,8 +116,8 @@ public void Test_ReadOnlyRefEnumerable_Index_Indexer_ThrowsIndexOutOfRange()
|
||||
{
|
||||
int[] array = new[]
|
||||
{
|
||||
0, 0, 0, 0
|
||||
};
|
||||
0, 0, 0, 0
|
||||
};
|
||||
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => ReadOnlyRefEnumerable<int>.DangerousCreate(in array[0], array.Length, 1)[new Index(array.Length)]);
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => ReadOnlyRefEnumerable<int>.DangerousCreate(in array[0], array.Length, 1)[^0]);
|
||||
|
@ -24,11 +24,11 @@ public void Test_RefEnumerable_DangerousCreate_Ok(int length, int step, int[] va
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], length, step);
|
||||
|
||||
@ -58,11 +58,11 @@ public void Test_RefEnumerable_Indexer(int step, int[] values)
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], values.Length, step);
|
||||
|
||||
@ -78,8 +78,8 @@ public void Test_RefEnumerable_Indexer_ThrowsIndexOutOfRange()
|
||||
{
|
||||
int[] array = new[]
|
||||
{
|
||||
0, 0, 0, 0
|
||||
};
|
||||
0, 0, 0, 0
|
||||
};
|
||||
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => RefEnumerable<int>.DangerousCreate(ref array[0], array.Length, 1)[-1]);
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => RefEnumerable<int>.DangerousCreate(ref array[0], array.Length, 1)[array.Length]);
|
||||
@ -96,11 +96,11 @@ public void Test_RefEnumerable_Index_Indexer(int step, int[] values)
|
||||
{
|
||||
Span<int> data = new[]
|
||||
{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
|
||||
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], values.Length, step);
|
||||
|
||||
@ -116,8 +116,8 @@ public void Test_RefEnumerable_Index_Indexer_ThrowsIndexOutOfRange()
|
||||
{
|
||||
int[] array = new[]
|
||||
{
|
||||
0, 0, 0, 0
|
||||
};
|
||||
0, 0, 0, 0
|
||||
};
|
||||
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => RefEnumerable<int>.DangerousCreate(ref array[0], array.Length, 1)[new Index(array.Length)]);
|
||||
_ = Assert.ThrowsException<IndexOutOfRangeException>(() => RefEnumerable<int>.DangerousCreate(ref array[0], array.Length, 1)[^0]);
|
||||
|
@ -17,10 +17,10 @@ public void Test_ArrayExtensions_2D_DangerousGetReference_Int()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
// See comments in Test_ArrayExtensions.1D for how these tests work
|
||||
ref int r0 = ref array.DangerousGetReference();
|
||||
@ -35,9 +35,9 @@ public void Test_ArrayExtensions_2D_DangerousGetReference_String()
|
||||
{
|
||||
string[,] array =
|
||||
{
|
||||
{ "a", "bb", "ccc" },
|
||||
{ "dddd", "eeeee", "ffffff" }
|
||||
};
|
||||
{ "a", "bb", "ccc" },
|
||||
{ "dddd", "eeeee", "ffffff" }
|
||||
};
|
||||
|
||||
ref string r0 = ref array.DangerousGetReference();
|
||||
ref string r1 = ref array[0, 0];
|
||||
@ -51,10 +51,10 @@ public void Test_ArrayExtensions_2D_DangerousGetReferenceAt_Zero()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
ref int r0 = ref array.DangerousGetReferenceAt(0, 0);
|
||||
ref int r1 = ref array[0, 0];
|
||||
@ -68,10 +68,10 @@ public void Test_ArrayExtensions_2D_DangerousGetReferenceAt_Index()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
ref int r0 = ref array.DangerousGetReferenceAt(1, 3);
|
||||
ref int r1 = ref array[1, 3];
|
||||
@ -94,11 +94,11 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayMid()
|
||||
|
||||
bool[,]? expected = new[,]
|
||||
{
|
||||
{ false, false, false, false, false },
|
||||
{ false, true, true, true, false },
|
||||
{ false, true, true, true, false },
|
||||
{ false, false, false, false, false },
|
||||
};
|
||||
{ false, false, false, false, false },
|
||||
{ false, true, true, true, false },
|
||||
{ false, true, true, true, false },
|
||||
{ false, false, false, false, false },
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, test);
|
||||
}
|
||||
@ -114,11 +114,11 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayTwice()
|
||||
|
||||
bool[,]? expected = new[,]
|
||||
{
|
||||
{ true, false, false, false, false },
|
||||
{ true, false, false, true, true },
|
||||
{ false, false, false, true, true },
|
||||
{ false, false, false, false, false },
|
||||
};
|
||||
{ true, false, false, false, false },
|
||||
{ true, false, false, true, true },
|
||||
{ false, false, false, true, true },
|
||||
{ false, false, false, false, false },
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, test);
|
||||
}
|
||||
@ -133,11 +133,11 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayBottomEdgeBoundary()
|
||||
|
||||
bool[,]? expected = new[,]
|
||||
{
|
||||
{ false, false, false, false, false },
|
||||
{ false, false, true, true, false },
|
||||
{ false, false, true, true, false },
|
||||
{ false, false, true, true, false },
|
||||
};
|
||||
{ false, false, false, false, false },
|
||||
{ false, false, true, true, false },
|
||||
{ false, false, true, true, false },
|
||||
{ false, false, true, true, false },
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, test);
|
||||
}
|
||||
@ -152,12 +152,12 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayBottomRightCornerBoundar
|
||||
|
||||
bool[,]? expected = new[,]
|
||||
{
|
||||
{ false, false, false, false },
|
||||
{ false, false, false, false },
|
||||
{ false, false, false, false },
|
||||
{ false, false, true, true },
|
||||
{ false, false, true, true },
|
||||
};
|
||||
{ false, false, false, false },
|
||||
{ false, false, false, false },
|
||||
{ false, false, false, false },
|
||||
{ false, false, true, true },
|
||||
{ false, false, true, true },
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, test);
|
||||
}
|
||||
@ -168,10 +168,10 @@ public void Test_ArrayExtensions_2D_GetRow_Rectangle()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
// Here we use the enumerator on the RefEnumerator<T> type to traverse items in a row
|
||||
// by reference. For each one, we check that the reference does in fact point to the
|
||||
@ -200,10 +200,10 @@ public void Test_ArrayExtensions_2D_GetColumn_Rectangle()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
// Same as above, but this time we iterate a column instead (so non contiguous items)
|
||||
int i = 0;
|
||||
@ -236,11 +236,11 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
// Get a row and test the Clear method. Note that the Span2D<T> here is sliced
|
||||
// starting from the second column, so this method should clear the row from index 1.
|
||||
@ -248,11 +248,11 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 0, 0, 0 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 0, 0, 0 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, expected);
|
||||
|
||||
@ -261,11 +261,11 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
|
||||
|
||||
expected = new[,]
|
||||
{
|
||||
{ 1, 2, 42, 4 },
|
||||
{ 5, 0, 42, 0 },
|
||||
{ 9, 10, 42, 12 },
|
||||
{ 13, 14, 42, 16 }
|
||||
};
|
||||
{ 1, 2, 42, 4 },
|
||||
{ 5, 0, 42, 0 },
|
||||
{ 9, 10, 42, 12 },
|
||||
{ 13, 14, 42, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, expected);
|
||||
|
||||
@ -305,11 +305,11 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
|
||||
|
||||
expected = new[,]
|
||||
{
|
||||
{ 1, 2, 42, 4 },
|
||||
{ 5, 0, 42, 0 },
|
||||
{ 99, 99, 99, 99 },
|
||||
{ 13, 14, 42, 16 }
|
||||
};
|
||||
{ 1, 2, 42, 4 },
|
||||
{ 5, 0, 42, 0 },
|
||||
{ 99, 99, 99, 99 },
|
||||
{ 13, 14, 42, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, expected);
|
||||
|
||||
@ -317,11 +317,11 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
|
||||
|
||||
expected = new[,]
|
||||
{
|
||||
{ 1, 2, 0, 4 },
|
||||
{ 5, 0, 0, 0 },
|
||||
{ 99, 99, 0, 99 },
|
||||
{ 13, 14, 0, 16 }
|
||||
};
|
||||
{ 1, 2, 0, 4 },
|
||||
{ 5, 0, 0, 0 },
|
||||
{ 99, 99, 0, 99 },
|
||||
{ 13, 14, 0, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, expected);
|
||||
}
|
||||
@ -332,11 +332,11 @@ public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
// This test pretty much does the same things as the method above, but this time
|
||||
// using a source ReadOnlySpan2D<T>, so that the sequence type being tested is
|
||||
@ -377,11 +377,11 @@ public void Test_ArrayExtensions_2D_RefEnumerable_Misc()
|
||||
{
|
||||
int[,] array1 =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
int[,] array2 = new int[4, 4];
|
||||
|
||||
@ -399,11 +399,11 @@ public void Test_ArrayExtensions_2D_RefEnumerable_Misc()
|
||||
|
||||
int[,] result =
|
||||
{
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 0, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 0, 8, 0, 16 }
|
||||
};
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 0, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 0, 8, 0, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array2, result);
|
||||
|
||||
@ -413,11 +413,11 @@ public void Test_ArrayExtensions_2D_RefEnumerable_Misc()
|
||||
|
||||
result = new[,]
|
||||
{
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 2, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 4, 8, 0, 16 }
|
||||
};
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 2, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 4, 8, 0, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array2, result);
|
||||
|
||||
@ -454,10 +454,10 @@ public void Test_ArrayExtensions_2D_AsSpan_Populated()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 }
|
||||
};
|
||||
|
||||
Span<int> span = array.AsSpan();
|
||||
|
||||
|
@ -76,11 +76,11 @@ public void Test_ReadOnlySpanExtensions_DangerousGetLookupReferenceAt(int i)
|
||||
{
|
||||
ReadOnlySpan<byte> table = new byte[]
|
||||
{
|
||||
0xFF, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 1, 0, 1, 1, 1, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 1
|
||||
0xFF, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 1, 0, 1, 1, 1, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 1
|
||||
};
|
||||
|
||||
ref byte ri = ref Unsafe.AsRef(table.DangerousGetLookupReferenceAt(i));
|
||||
@ -104,18 +104,18 @@ public void Test_ReadOnlySpanExtensions_IndexOf_Empty()
|
||||
static void Test<T>()
|
||||
{
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
T? a = default;
|
||||
{
|
||||
T? a = default;
|
||||
|
||||
_ = default(ReadOnlySpan<T?>).IndexOf(in a);
|
||||
});
|
||||
_ = default(ReadOnlySpan<T?>).IndexOf(in a);
|
||||
});
|
||||
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default };
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default };
|
||||
|
||||
_ = data.Slice(1).IndexOf(in data[0]);
|
||||
});
|
||||
_ = data.Slice(1).IndexOf(in data[0]);
|
||||
});
|
||||
}
|
||||
|
||||
Test<byte>();
|
||||
@ -156,28 +156,28 @@ static void Test<T>()
|
||||
{
|
||||
// Before start
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.Slice(1).IndexOf(in data[0]);
|
||||
});
|
||||
_ = data.Slice(1).IndexOf(in data[0]);
|
||||
});
|
||||
|
||||
// After end
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.Slice(0, 2).IndexOf(in data[2]);
|
||||
});
|
||||
_ = data.Slice(0, 2).IndexOf(in data[2]);
|
||||
});
|
||||
|
||||
// Local variable
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
T?[]? dummy = new T?[] { default };
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
T?[]? dummy = new T?[] { default };
|
||||
ReadOnlySpan<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.IndexOf(in dummy[0]);
|
||||
});
|
||||
_ = data.IndexOf(in dummy[0]);
|
||||
});
|
||||
}
|
||||
|
||||
Test<byte>();
|
||||
@ -286,11 +286,11 @@ public void Test_ReadOnlySpanExtensions_CopyTo_RefEnumerable()
|
||||
|
||||
int[,] result =
|
||||
{
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 0, 33, 0, 0, 0 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 0, 33, 0, 0, 0 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, result);
|
||||
|
||||
|
@ -56,18 +56,18 @@ public void Test_SpanExtensions_IndexOf_Empty()
|
||||
static void Test<T>()
|
||||
{
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
T? a = default;
|
||||
{
|
||||
T? a = default;
|
||||
|
||||
_ = default(Span<T?>).IndexOf(ref a);
|
||||
});
|
||||
_ = default(Span<T?>).IndexOf(ref a);
|
||||
});
|
||||
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
Span<T?> data = new T?[] { default };
|
||||
{
|
||||
Span<T?> data = new T?[] { default };
|
||||
|
||||
_ = data.Slice(1).IndexOf(ref data[0]);
|
||||
});
|
||||
_ = data.Slice(1).IndexOf(ref data[0]);
|
||||
});
|
||||
}
|
||||
|
||||
Test<byte>();
|
||||
@ -108,28 +108,28 @@ static void Test<T>()
|
||||
{
|
||||
// Before start
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.Slice(1).IndexOf(ref data[0]);
|
||||
});
|
||||
_ = data.Slice(1).IndexOf(ref data[0]);
|
||||
});
|
||||
|
||||
// After end
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.Slice(0, 2).IndexOf(ref data[2]);
|
||||
});
|
||||
_ = data.Slice(0, 2).IndexOf(ref data[2]);
|
||||
});
|
||||
|
||||
// Local variable
|
||||
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
T?[]? dummy = new T?[] { default };
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
{
|
||||
T?[]? dummy = new T?[] { default };
|
||||
Span<T?> data = new T?[] { default, default, default, default };
|
||||
|
||||
_ = data.IndexOf(ref dummy[0]);
|
||||
});
|
||||
_ = data.IndexOf(ref dummy[0]);
|
||||
});
|
||||
}
|
||||
|
||||
Test<byte>();
|
||||
|
@ -21,15 +21,15 @@ public unsafe void Test_ArrayExtensions_Pointer()
|
||||
int sum = 0;
|
||||
|
||||
_ = Parallel.For(0, 1000, i =>
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
using (SpinLockExtensions.Enter(p))
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
});
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
using (SpinLockExtensions.Enter(p))
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.AreEqual(sum, 1000 * 10);
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ public partial class Test_ParallelHelper
|
||||
/// </summary>
|
||||
private static ReadOnlySpan<Size> TestFor2DSizes => new[]
|
||||
{
|
||||
new Size(0, 0),
|
||||
new Size(0, 1),
|
||||
new Size(1, 1),
|
||||
new Size(3, 3),
|
||||
new Size(1024, 1024),
|
||||
new Size(512, 2175),
|
||||
new Size(4039, 11231)
|
||||
};
|
||||
new Size(0, 0),
|
||||
new Size(0, 1),
|
||||
new Size(1, 1),
|
||||
new Size(3, 3),
|
||||
new Size(1024, 1024),
|
||||
new Size(512, 2175),
|
||||
new Size(4039, 11231)
|
||||
};
|
||||
|
||||
[TestCategory("ParallelHelper")]
|
||||
[TestMethod]
|
||||
|
@ -54,8 +54,8 @@ public void Test_Memory2DT_Array1DConstructor()
|
||||
{
|
||||
int[] array =
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
// Create a memory over a 1D array with 2D data in row-major order. This tests
|
||||
// the T[] array constructor for Memory2D<T> with custom size and pitch.
|
||||
@ -87,9 +87,9 @@ public void Test_Memory2DT_Array2DConstructor_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Test the constructor taking a T[,] array that is mapped directly (no slicing)
|
||||
Memory2D<int> memory2d = new(array);
|
||||
@ -112,9 +112,9 @@ public void Test_Memory2DT_Array2DConstructor_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but this time we also slice the memory to test the other constructor
|
||||
Memory2D<int> memory2d = new(array, 0, 1, 2, 2);
|
||||
@ -135,15 +135,15 @@ public void Test_Memory2DT_Array3DConstructor_1()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
// Same as above, but we test the constructor taking a layer within a 3D array
|
||||
Memory2D<int> memory2d = new(array, 1);
|
||||
@ -167,15 +167,15 @@ public void Test_Memory2DT_Array3DConstructor_2()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
// Same as above, but we also slice the target layer in the 3D array. In this case we're creating
|
||||
// a Memory<int> instance from a slice in the layer at depth 1 in our 3D array, and with an area
|
||||
@ -209,8 +209,8 @@ public void Test_Memory2DT_MemoryConstructor()
|
||||
{
|
||||
Memory<int> memory = new[]
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
// We also test the constructor that takes an input Memory<T> instance.
|
||||
// This is only available on runtimes with fast Span<T> support, as otherwise
|
||||
@ -242,9 +242,9 @@ public void Test_Memory2DT_Slice_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
@ -289,9 +289,9 @@ public void Test_Memory2DT_Slice_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
@ -326,9 +326,9 @@ public void Test_Memory2DT_TryGetMemory_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
@ -422,9 +422,9 @@ public void Test_Memory2DT_ToArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Here we create a Memory2D<T> instance from a 2D array and then verify that
|
||||
// calling ToArray() creates an array that matches the contents of the first.
|
||||
@ -444,9 +444,9 @@ public void Test_Memory2DT_ToArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with a sliced Memory2D<T> instance
|
||||
Memory2D<int> memory2d = new(array, 0, 0, 2, 2);
|
||||
@ -458,9 +458,9 @@ public void Test_Memory2DT_ToArray_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, copy);
|
||||
}
|
||||
@ -471,9 +471,9 @@ public void Test_Memory2DT_Equals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Here we want to verify that the Memory2D<T>.Equals method works correctly. This is true
|
||||
// when the wrapped instance is the same, and the various internal offsets and sizes match.
|
||||
@ -500,9 +500,9 @@ public void Test_Memory2DT_GetHashCode()
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
@ -524,9 +524,9 @@ public void Test_Memory2DT_ToString()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
|
@ -45,8 +45,8 @@ public void Test_ReadOnlyMemory2DT_Array1DConstructor()
|
||||
{
|
||||
int[] array =
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array, 1, 2, 2, 1);
|
||||
|
||||
@ -76,9 +76,9 @@ public void Test_ReadOnlyMemory2DT_Array2DConstructor_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -98,9 +98,9 @@ public void Test_ReadOnlyMemory2DT_Array2DConstructor_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array, 0, 1, 2, 2);
|
||||
|
||||
@ -122,15 +122,15 @@ public void Test_ReadOnlyMemory2DT_Array3DConstructor_1()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array, 1);
|
||||
|
||||
@ -152,15 +152,15 @@ public void Test_ReadOnlyMemory2DT_Array3DConstructor_2()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array, 1, 0, 1, 2, 2);
|
||||
|
||||
@ -189,8 +189,8 @@ public void Test_ReadOnlyMemory2DT_ReadOnlyMemoryConstructor()
|
||||
{
|
||||
ReadOnlyMemory<int> memory = new[]
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = memory.AsMemory2D(1, 2, 2, 1);
|
||||
|
||||
@ -218,9 +218,9 @@ public void Test_ReadOnlyMemory2DT_Slice_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -260,9 +260,9 @@ public void Test_ReadOnlyMemory2DT_Slice_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -296,9 +296,9 @@ public void Test_ReadOnlyMemory2DT_TryGetReadOnlyMemory_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -380,9 +380,9 @@ public void Test_ReadOnlyMemory2DT_ToArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -400,9 +400,9 @@ public void Test_ReadOnlyMemory2DT_ToArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array, 0, 0, 2, 2);
|
||||
|
||||
@ -413,9 +413,9 @@ public void Test_ReadOnlyMemory2DT_ToArray_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, copy);
|
||||
}
|
||||
@ -426,9 +426,9 @@ public void Test_ReadOnlyMemory2DT_Equals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> readOnlyMemory2D = new(array);
|
||||
|
||||
@ -451,9 +451,9 @@ public void Test_ReadOnlyMemory2DT_GetHashCode()
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
@ -473,9 +473,9 @@ public void Test_ReadOnlyMemory2DT_ToString()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
|
@ -101,8 +101,8 @@ public void Test_ReadOnlySpan2DT_Array1DConstructor()
|
||||
{
|
||||
int[] array =
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 1, 2, 2, 1);
|
||||
|
||||
@ -129,9 +129,9 @@ public void Test_ReadOnlySpan2DT_Array2DConstructor_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -151,9 +151,9 @@ public void Test_ReadOnlySpan2DT_Array2DConstructor_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
|
||||
@ -175,15 +175,15 @@ public void Test_ReadOnlySpan2DT_Array3DConstructor_1()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 1);
|
||||
|
||||
@ -205,15 +205,15 @@ public void Test_ReadOnlySpan2DT_Array3DConstructor_2()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 1, 0, 1, 2, 2);
|
||||
|
||||
@ -238,9 +238,9 @@ public void Test_ReadOnlySpan2DT_CopyTo_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -259,9 +259,9 @@ public void Test_ReadOnlySpan2DT_CopyTo_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
|
||||
@ -282,9 +282,9 @@ public void Test_ReadOnlySpan2DT_CopyTo2D_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -303,9 +303,9 @@ public void Test_ReadOnlySpan2DT_CopyTo2D_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
|
||||
@ -315,9 +315,9 @@ public void Test_ReadOnlySpan2DT_CopyTo2D_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 2, 3 },
|
||||
{ 5, 6 }
|
||||
};
|
||||
{ 2, 3 },
|
||||
{ 5, 6 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(target, expected);
|
||||
|
||||
@ -330,9 +330,9 @@ public void Test_ReadOnlySpan2DT_TryCopyTo()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -348,9 +348,9 @@ public void Test_ReadOnlySpan2DT_TryCopyTo2D()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -370,9 +370,9 @@ ref Unsafe.AsRef<int>(null),
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -391,9 +391,9 @@ ref Unsafe.AsRef<int>(null),
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -491,9 +491,9 @@ public void Test_ReadOnlySpan2DT_Slice_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -529,9 +529,9 @@ public void Test_ReadOnlySpan2DT_Slice_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -566,9 +566,9 @@ public void Test_ReadOnlySpan2DT_GetRowReadOnlySpan()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -636,9 +636,9 @@ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_From2DArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -660,9 +660,9 @@ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_From2DArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 0, 0, 2, 2);
|
||||
|
||||
@ -678,9 +678,9 @@ public void Test_ReadOnlySpan2DT_ToArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -698,9 +698,9 @@ public void Test_ReadOnlySpan2DT_ToArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array, 0, 0, 2, 2);
|
||||
|
||||
@ -711,9 +711,9 @@ public void Test_ReadOnlySpan2DT_ToArray_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, copy);
|
||||
}
|
||||
@ -725,9 +725,9 @@ public void Test_ReadOnlySpan2DT_Equals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -741,9 +741,9 @@ public void Test_ReadOnlySpan2DT_GetHashCode()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -756,9 +756,9 @@ public void Test_ReadOnlySpan2DT_ToString()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d = new(array);
|
||||
|
||||
@ -775,9 +775,9 @@ public void Test_ReadOnlySpan2DT_opEquals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d_1 = new(array);
|
||||
ReadOnlySpan2D<int> span2d_2 = new(array);
|
||||
@ -798,9 +798,9 @@ public void Test_ReadOnlySpan2DT_ImplicitCast()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span2d_1 = array;
|
||||
ReadOnlySpan2D<int> span2d_2 = new(array);
|
||||
@ -814,9 +814,9 @@ public void Test_ReadOnlySpan2DT_GetRow()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (ref readonly int value in new ReadOnlySpan2D<int>(array).GetRow(1))
|
||||
@ -874,9 +874,9 @@ public void Test_ReadOnlySpan2DT_GetColumn()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (ref readonly int value in new ReadOnlySpan2D<int>(array).GetColumn(1))
|
||||
@ -932,9 +932,9 @@ public void Test_ReadOnlySpan2DT_GetEnumerator()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
int[] result = new int[4];
|
||||
int i = 0;
|
||||
@ -991,11 +991,11 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc()
|
||||
{
|
||||
int[,] array1 =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
ReadOnlySpan2D<int> span1 = array1;
|
||||
|
||||
@ -1015,11 +1015,11 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc()
|
||||
|
||||
int[,] result =
|
||||
{
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 0, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 0, 8, 0, 16 }
|
||||
};
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 0, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 0, 8, 0, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array2, result);
|
||||
|
||||
@ -1029,11 +1029,11 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc()
|
||||
|
||||
result = new[,]
|
||||
{
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 2, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 4, 8, 0, 16 }
|
||||
};
|
||||
{ 1, 5, 3, 4 },
|
||||
{ 2, 6, 0, 8 },
|
||||
{ 3, 7, 11, 12 },
|
||||
{ 4, 8, 0, 16 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array2, result);
|
||||
|
||||
@ -1047,11 +1047,11 @@ public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Cast()
|
||||
{
|
||||
int[,] array1 =
|
||||
{
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
{ 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8 },
|
||||
{ 9, 10, 11, 12 },
|
||||
{ 13, 14, 15, 16 }
|
||||
};
|
||||
|
||||
int[] result = { 5, 6, 7, 8 };
|
||||
|
||||
|
@ -125,8 +125,8 @@ public void Test_Span2DT_Array1DConstructor()
|
||||
{
|
||||
int[] array =
|
||||
{
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
1, 2, 3, 4, 5, 6
|
||||
};
|
||||
|
||||
// Same as above, but wrapping a 1D array with data in row-major order
|
||||
Span2D<int> span2d = new(array, 1, 2, 2, 1);
|
||||
@ -158,9 +158,9 @@ public void Test_Span2DT_Array2DConstructor_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but directly wrapping a 2D array
|
||||
Span2D<int> span2d = new(array);
|
||||
@ -185,9 +185,9 @@ public void Test_Span2DT_Array2DConstructor_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with a custom slicing over the target 2D array
|
||||
Span2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
@ -212,15 +212,15 @@ public void Test_Span2DT_Array3DConstructor_1()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
// Here we wrap a layer in a 3D array instead, the rest is the same
|
||||
Span2D<int> span2d = new(array, 1);
|
||||
@ -247,15 +247,15 @@ public void Test_Span2DT_Array3DConstructor_2()
|
||||
{
|
||||
int[,,] array =
|
||||
{
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
},
|
||||
{
|
||||
{ 10, 20, 30 },
|
||||
{ 40, 50, 60 }
|
||||
}
|
||||
};
|
||||
|
||||
// Same as above, but also slicing a target 2D area in the 3D array layer
|
||||
Span2D<int> span2d = new(array, 1, 0, 1, 2, 2);
|
||||
@ -285,9 +285,9 @@ public void Test_Span2DT_FillAndClear_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Tests for the Fill and Clear APIs for Span2D<T>. These should fill
|
||||
// or clear the entire wrapped 2D array (just like eg. Span<T>.Fill).
|
||||
@ -308,9 +308,9 @@ public void Test_Span2DT_Fill_Empty()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with an initial slicing as well to ensure
|
||||
// these method work correctly with different internal offsets
|
||||
@ -331,9 +331,9 @@ public void Test_Span2DT_FillAndClear_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, just with different slicing to a target smaller 2D area
|
||||
Span2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
@ -342,9 +342,9 @@ public void Test_Span2DT_FillAndClear_2()
|
||||
|
||||
int[,] filled =
|
||||
{
|
||||
{ 1, 42, 42 },
|
||||
{ 4, 42, 42 }
|
||||
};
|
||||
{ 1, 42, 42 },
|
||||
{ 4, 42, 42 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, filled);
|
||||
|
||||
@ -352,9 +352,9 @@ public void Test_Span2DT_FillAndClear_2()
|
||||
|
||||
int[,] cleared =
|
||||
{
|
||||
{ 1, 0, 0 },
|
||||
{ 4, 0, 0 }
|
||||
};
|
||||
{ 1, 0, 0 },
|
||||
{ 4, 0, 0 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, cleared);
|
||||
}
|
||||
@ -377,9 +377,9 @@ public void Test_Span2DT_CopyTo_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -401,9 +401,9 @@ public void Test_Span2DT_CopyTo_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with different initial slicing
|
||||
Span2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
@ -426,9 +426,9 @@ public void Test_Span2DT_CopyTo2D_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -449,9 +449,9 @@ public void Test_Span2DT_CopyTo2D_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with extra initial slicing
|
||||
Span2D<int> span2d = new(array, 0, 1, 2, 2);
|
||||
@ -462,9 +462,9 @@ public void Test_Span2DT_CopyTo2D_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 2, 3 },
|
||||
{ 5, 6 }
|
||||
};
|
||||
{ 2, 3 },
|
||||
{ 5, 6 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(target, expected);
|
||||
|
||||
@ -477,9 +477,9 @@ public void Test_Span2DT_TryCopyTo()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -500,9 +500,9 @@ public void Test_Span2DT_TryCopyTo2D()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but copying to a 2D array with the safe TryCopyTo method
|
||||
Span2D<int> span2d = new(array);
|
||||
@ -514,9 +514,9 @@ public void Test_Span2DT_TryCopyTo2D()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(target, expected);
|
||||
}
|
||||
@ -532,9 +532,9 @@ ref Unsafe.AsRef<int>(null),
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -555,9 +555,9 @@ ref Unsafe.AsRef<int>(null),
|
||||
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -655,9 +655,9 @@ public void Test_Span2DT_Slice_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Here we have a number of tests that just take an initial 2D array, create a Span2D<T>,
|
||||
// perform a number of slicing operations and then validate the parameters for the resulting
|
||||
@ -697,9 +697,9 @@ public void Test_Span2DT_Slice_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -735,9 +735,9 @@ public void Test_Span2DT_GetRowSpan()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -826,9 +826,9 @@ public void Test_Span2DT_TryGetSpan_From2DArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -855,9 +855,9 @@ public void Test_Span2DT_TryGetSpan_From2DArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but this will always fail because we're creating
|
||||
// a Span2D<T> wrapping non contiguous data (the pitch is not 0).
|
||||
@ -875,9 +875,9 @@ public void Test_Span2DT_ToArray_1()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Here we create a Span2D<T> and verify that ToArray() produces
|
||||
// a 2D array that is identical to the original one being wrapped.
|
||||
@ -897,9 +897,9 @@ public void Test_Span2DT_ToArray_2()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but with extra initial slicing
|
||||
Span2D<int> span2d = new(array, 0, 0, 2, 2);
|
||||
@ -911,9 +911,9 @@ public void Test_Span2DT_ToArray_2()
|
||||
|
||||
int[,] expected =
|
||||
{
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
{ 1, 2 },
|
||||
{ 4, 5 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(expected, copy);
|
||||
}
|
||||
@ -925,9 +925,9 @@ public void Test_Span2DT_Equals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -942,9 +942,9 @@ public void Test_Span2DT_GetHashCode()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -958,9 +958,9 @@ public void Test_Span2DT_ToString()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
Span2D<int> span2d = new(array);
|
||||
|
||||
@ -978,9 +978,9 @@ public void Test_Span2DT_opEquals()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Create two Span2D<T> instances wrapping the same array with the same
|
||||
// parameters, and verify that the equality operators work correctly.
|
||||
@ -1004,9 +1004,9 @@ public void Test_Span2DT_ImplicitCast()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Verify that an explicit constructor and the implicit conversion
|
||||
// operator generate an identical Span2D<T> instance from the array.
|
||||
@ -1022,9 +1022,9 @@ public void Test_Span2DT_GetRow()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Get a target row and verify the contents match with our data
|
||||
RefEnumerable<int> enumerable = new Span2D<int>(array).GetRow(1);
|
||||
@ -1070,9 +1070,9 @@ public void Test_Span2DT_GetColumn()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
// Same as above, but getting a column instead
|
||||
RefEnumerable<int> enumerable = new Span2D<int>(array).GetColumn(2);
|
||||
@ -1118,9 +1118,9 @@ public void Test_Span2DT_GetEnumerator()
|
||||
{
|
||||
int[,] array =
|
||||
{
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
|
||||
int[] result = new int[4];
|
||||
int i = 0;
|
||||
|
@ -72,10 +72,10 @@ public void Test_AsyncRelayCommand_WithCanExecuteFunctionTrue()
|
||||
|
||||
AsyncRelayCommand? command = new(
|
||||
() =>
|
||||
{
|
||||
ticks++;
|
||||
return Task.CompletedTask;
|
||||
}, () => true);
|
||||
{
|
||||
ticks++;
|
||||
return Task.CompletedTask;
|
||||
}, () => true);
|
||||
|
||||
Assert.IsTrue(command.CanExecute(null));
|
||||
Assert.IsTrue(command.CanExecute(new object()));
|
||||
@ -100,10 +100,10 @@ public void Test_AsyncRelayCommand_WithCanExecuteFunctionFalse()
|
||||
|
||||
AsyncRelayCommand? command = new(
|
||||
() =>
|
||||
{
|
||||
ticks++;
|
||||
return Task.CompletedTask;
|
||||
}, () => false);
|
||||
{
|
||||
ticks++;
|
||||
return Task.CompletedTask;
|
||||
}, () => false);
|
||||
|
||||
Assert.IsFalse(command.CanExecute(null));
|
||||
Assert.IsFalse(command.CanExecute(new object()));
|
||||
|
@ -69,10 +69,10 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionTrue()
|
||||
|
||||
AsyncRelayCommand<string>? command = new(
|
||||
s =>
|
||||
{
|
||||
ticks = int.Parse(s!);
|
||||
return Task.CompletedTask;
|
||||
}, s => true);
|
||||
{
|
||||
ticks = int.Parse(s!);
|
||||
return Task.CompletedTask;
|
||||
}, s => true);
|
||||
|
||||
Assert.IsTrue(command.CanExecute(null));
|
||||
Assert.IsTrue(command.CanExecute("1"));
|
||||
@ -94,10 +94,10 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionFalse()
|
||||
|
||||
AsyncRelayCommand<string>? command = new(
|
||||
s =>
|
||||
{
|
||||
ticks = int.Parse(s!);
|
||||
return Task.CompletedTask;
|
||||
}, s => false);
|
||||
{
|
||||
ticks = int.Parse(s!);
|
||||
return Task.CompletedTask;
|
||||
}, s => false);
|
||||
|
||||
Assert.IsFalse(command.CanExecute(null));
|
||||
Assert.IsFalse(command.CanExecute("1"));
|
||||
@ -128,10 +128,10 @@ public void Test_AsyncRelayCommandOfT_NullWithValueType()
|
||||
|
||||
command = new AsyncRelayCommand<int>(
|
||||
i =>
|
||||
{
|
||||
n = i;
|
||||
return Task.CompletedTask;
|
||||
}, i => i > 0);
|
||||
{
|
||||
n = i;
|
||||
return Task.CompletedTask;
|
||||
}, i => i > 0);
|
||||
|
||||
Assert.IsFalse(command.CanExecute(null));
|
||||
_ = Assert.ThrowsException<NullReferenceException>(() => command.Execute(null));
|
||||
|
@ -239,9 +239,9 @@ public void Test_Messenger_DuplicateRegistrationWithMessageType(Type type)
|
||||
messenger.Register<MessageA>(recipient, (r, m) => { });
|
||||
|
||||
_ = Assert.ThrowsException<InvalidOperationException>(() =>
|
||||
{
|
||||
messenger.Register<MessageA>(recipient, (r, m) => { });
|
||||
});
|
||||
{
|
||||
messenger.Register<MessageA>(recipient, (r, m) => { });
|
||||
});
|
||||
}
|
||||
|
||||
[TestCategory("Mvvm")]
|
||||
@ -256,9 +256,9 @@ public void Test_Messenger_DuplicateRegistrationWithMessageTypeAndToken(Type typ
|
||||
messenger.Register<MessageA, string>(recipient, nameof(MessageA), (r, m) => { });
|
||||
|
||||
_ = Assert.ThrowsException<InvalidOperationException>(() =>
|
||||
{
|
||||
messenger.Register<MessageA, string>(recipient, nameof(MessageA), (r, m) => { });
|
||||
});
|
||||
{
|
||||
messenger.Register<MessageA, string>(recipient, nameof(MessageA), (r, m) => { });
|
||||
});
|
||||
}
|
||||
|
||||
[TestCategory("Mvvm")]
|
||||
|
Loading…
Reference in New Issue
Block a user