From eab4b9ed28c27db0c4194478eaa7c6e91664195d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 2 Nov 2021 00:28:30 +0100 Subject: [PATCH] More whitespaces and code style tweaks --- ...eadOnlyObservableGroupedCollectionTests.cs | 52 ++-- .../Extensions/Test_ArrayExtensions.cs | 44 ++-- .../Extensions/Test_EventHandlerExtensions.cs | 6 +- .../Test_ReadOnlyRefEnumerable{T}.cs | 38 +-- .../Enumerables/Test_RefEnumerable{T}.cs | 38 +-- .../Extensions/Test_ArrayExtensions.2D.cs | 186 +++++++------- .../Extensions/Test_ReadOnlySpanExtensions.cs | 62 ++--- .../Extensions/Test_SpanExtensions.cs | 42 +-- .../Extensions/Test_SpinLockExtensions.cs | 18 +- .../Helpers/Test_ParallelHelper.For2D.cs | 16 +- .../Memory/Test_Memory2D{T}.cs | 110 ++++---- .../Memory/Test_ReadOnlyMemory2D{T}.cs | 110 ++++---- .../Memory/Test_ReadOnlySpan2D{T}.cs | 242 +++++++++--------- .../Memory/Test_Span2D{T}.cs | 238 ++++++++--------- .../Test_AsyncRelayCommand.cs | 16 +- .../Test_AsyncRelayCommand{T}.cs | 24 +- .../Test_Messenger.cs | 12 +- 17 files changed, 631 insertions(+), 623 deletions(-) diff --git a/tests/CommunityToolkit.Common.UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs b/tests/CommunityToolkit.Common.UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs index 3c35161d..71358460 100644 --- a/tests/CommunityToolkit.Common.UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs +++ b/tests/CommunityToolkit.Common.UnitTests/Collections/ReadOnlyObservableGroupedCollectionTests.cs @@ -443,45 +443,53 @@ public void ReplaceGroupInSource_ShoudReplaceGroup() private static bool IsAddEventValid(NotifyCollectionChangedEventArgs args, IEnumerable expectedGroupItems, int addIndex) { IEnumerable>? newItems = args.NewItems?.Cast>(); - 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 expectedGroupItems, int oldIndex) { IEnumerable>? oldItems = args.OldItems?.Cast>(); - 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 expectedGroupItems, int oldIndex, int newIndex) { IEnumerable>? oldItems = args.OldItems?.Cast>(); IEnumerable>? newItems = args.NewItems?.Cast>(); - 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 expectedRemovedItems, IEnumerable expectedAddItems) { IEnumerable>? oldItems = args.OldItems?.Cast>(); IEnumerable>? newItems = args.NewItems?.Cast>(); - 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; diff --git a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_ArrayExtensions.cs b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_ArrayExtensions.cs index aab9f0cb..206e2c41 100644 --- a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_ArrayExtensions.cs +++ b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_ArrayExtensions.cs @@ -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(() => - { - _ = array.GetColumn(-1).ToArray(); - }); + { + _ = array.GetColumn(-1).ToArray(); + }); _ = Assert.ThrowsException(() => - { - _ = 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(); diff --git a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_EventHandlerExtensions.cs b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_EventHandlerExtensions.cs index f4d31b9f..4b1c4fcc 100644 --- a/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_EventHandlerExtensions.cs +++ b/tests/CommunityToolkit.Common.UnitTests/Extensions/Test_EventHandlerExtensions.cs @@ -91,9 +91,9 @@ public void Test_EventHandlerExtensions_MultipleHandlersCauseAwait(int firstToRe { TaskCompletionSource[]? tsc = new[] { - new TaskCompletionSource(), - new TaskCompletionSource() - }; + new TaskCompletionSource(), + new TaskCompletionSource() + }; TestClass? testClass = new(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs index be309afb..9c42ff1f 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs @@ -24,11 +24,11 @@ public void Test_ReadOnlyRefEnumerable_DangerousCreate_Ok(int length, int step, { Span 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 enumerable = ReadOnlyRefEnumerable.DangerousCreate(in data[0], length, step); @@ -58,11 +58,11 @@ public void Test_ReadOnlyRefEnumerable_Indexer(int step, int[] values) { Span 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 enumerable = ReadOnlyRefEnumerable.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(() => ReadOnlyRefEnumerable.DangerousCreate(in array[0], array.Length, 1)[-1]); _ = Assert.ThrowsException(() => ReadOnlyRefEnumerable.DangerousCreate(in array[0], array.Length, 1)[array.Length]); @@ -96,11 +96,11 @@ public void Test_ReadOnlyRefEnumerable_Index_Indexer(int step, int[] values) { Span 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 enumerable = ReadOnlyRefEnumerable.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(() => ReadOnlyRefEnumerable.DangerousCreate(in array[0], array.Length, 1)[new Index(array.Length)]); _ = Assert.ThrowsException(() => ReadOnlyRefEnumerable.DangerousCreate(in array[0], array.Length, 1)[^0]); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs index b9fe0fc2..9dfc0f2c 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Enumerables/Test_RefEnumerable{T}.cs @@ -24,11 +24,11 @@ public void Test_RefEnumerable_DangerousCreate_Ok(int length, int step, int[] va { Span 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 enumerable = RefEnumerable.DangerousCreate(ref data[0], length, step); @@ -58,11 +58,11 @@ public void Test_RefEnumerable_Indexer(int step, int[] values) { Span 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 enumerable = RefEnumerable.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(() => RefEnumerable.DangerousCreate(ref array[0], array.Length, 1)[-1]); _ = Assert.ThrowsException(() => RefEnumerable.DangerousCreate(ref array[0], array.Length, 1)[array.Length]); @@ -96,11 +96,11 @@ public void Test_RefEnumerable_Index_Indexer(int step, int[] values) { Span 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 enumerable = RefEnumerable.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(() => RefEnumerable.DangerousCreate(ref array[0], array.Length, 1)[new Index(array.Length)]); _ = Assert.ThrowsException(() => RefEnumerable.DangerousCreate(ref array[0], array.Length, 1)[^0]); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs index 561550ed..4eed0cb7 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ArrayExtensions.2D.cs @@ -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 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 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, 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 span = array.AsSpan(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs index b21ab973..7d4fc17f 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_ReadOnlySpanExtensions.cs @@ -76,11 +76,11 @@ public void Test_ReadOnlySpanExtensions_DangerousGetLookupReferenceAt(int i) { ReadOnlySpan 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() { _ = Assert.ThrowsException(() => - { - T? a = default; + { + T? a = default; - _ = default(ReadOnlySpan).IndexOf(in a); - }); + _ = default(ReadOnlySpan).IndexOf(in a); + }); _ = Assert.ThrowsException(() => - { - ReadOnlySpan data = new T?[] { default }; + { + ReadOnlySpan data = new T?[] { default }; - _ = data.Slice(1).IndexOf(in data[0]); - }); + _ = data.Slice(1).IndexOf(in data[0]); + }); } Test(); @@ -156,28 +156,28 @@ static void Test() { // Before start _ = Assert.ThrowsException(() => - { - ReadOnlySpan data = new T?[] { default, default, default, default }; + { + ReadOnlySpan 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(() => - { - ReadOnlySpan data = new T?[] { default, default, default, default }; + { + ReadOnlySpan 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(() => - { - T?[]? dummy = new T?[] { default }; - ReadOnlySpan data = new T?[] { default, default, default, default }; + { + T?[]? dummy = new T?[] { default }; + ReadOnlySpan data = new T?[] { default, default, default, default }; - _ = data.IndexOf(in dummy[0]); - }); + _ = data.IndexOf(in dummy[0]); + }); } Test(); @@ -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); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs index 1023a379..9425d577 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpanExtensions.cs @@ -56,18 +56,18 @@ public void Test_SpanExtensions_IndexOf_Empty() static void Test() { _ = Assert.ThrowsException(() => - { - T? a = default; + { + T? a = default; - _ = default(Span).IndexOf(ref a); - }); + _ = default(Span).IndexOf(ref a); + }); _ = Assert.ThrowsException(() => - { - Span data = new T?[] { default }; + { + Span data = new T?[] { default }; - _ = data.Slice(1).IndexOf(ref data[0]); - }); + _ = data.Slice(1).IndexOf(ref data[0]); + }); } Test(); @@ -108,28 +108,28 @@ static void Test() { // Before start _ = Assert.ThrowsException(() => - { - Span data = new T?[] { default, default, default, default }; + { + Span 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(() => - { - Span data = new T?[] { default, default, default, default }; + { + Span 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(() => - { - T?[]? dummy = new T?[] { default }; - Span data = new T?[] { default, default, default, default }; + { + T?[]? dummy = new T?[] { default }; + Span data = new T?[] { default, default, default, default }; - _ = data.IndexOf(ref dummy[0]); - }); + _ = data.IndexOf(ref dummy[0]); + }); } Test(); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs index f02149cd..5303c964 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Extensions/Test_SpinLockExtensions.cs @@ -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); } diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.For2D.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.For2D.cs index a77c1d0e..09ff31a4 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.For2D.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ParallelHelper.For2D.cs @@ -17,14 +17,14 @@ public partial class Test_ParallelHelper /// private static ReadOnlySpan 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] diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs index 1cce2c33..660c0883 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Memory2D{T}.cs @@ -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 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 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 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 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 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 memory = new[] { - 1, 2, 3, 4, 5, 6 - }; + 1, 2, 3, 4, 5, 6 + }; // We also test the constructor that takes an input Memory instance. // This is only available on runtimes with fast Span 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 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 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 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 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 instance Memory2D 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.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 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 memory2d = new(array); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs index 2f5b3103..eadab8cc 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlyMemory2D{T}.cs @@ -45,8 +45,8 @@ public void Test_ReadOnlyMemory2DT_Array1DConstructor() { int[] array = { - 1, 2, 3, 4, 5, 6 - }; + 1, 2, 3, 4, 5, 6 + }; ReadOnlyMemory2D 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 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 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 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 memory2d = new(array, 1, 0, 1, 2, 2); @@ -189,8 +189,8 @@ public void Test_ReadOnlyMemory2DT_ReadOnlyMemoryConstructor() { ReadOnlyMemory memory = new[] { - 1, 2, 3, 4, 5, 6 - }; + 1, 2, 3, 4, 5, 6 + }; ReadOnlyMemory2D 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 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 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 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 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 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 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 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 memory2d = new(array); diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs index dec68f86..a09d64f5 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs @@ -101,8 +101,8 @@ public void Test_ReadOnlySpan2DT_Array1DConstructor() { int[] array = { - 1, 2, 3, 4, 5, 6 - }; + 1, 2, 3, 4, 5, 6 + }; ReadOnlySpan2D 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 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 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 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 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 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 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 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 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 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 span2d = new(array); @@ -370,9 +370,9 @@ ref Unsafe.AsRef(null), int[,] array = { - { 1, 2, 3 }, - { 4, 5, 6 } - }; + { 1, 2, 3 }, + { 4, 5, 6 } + }; ReadOnlySpan2D span2d = new(array); @@ -391,9 +391,9 @@ ref Unsafe.AsRef(null), int[,] array = { - { 1, 2, 3 }, - { 4, 5, 6 } - }; + { 1, 2, 3 }, + { 4, 5, 6 } + }; ReadOnlySpan2D 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 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 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 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 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 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 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 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 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 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 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 span2d_1 = new(array); ReadOnlySpan2D 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 span2d_1 = array; ReadOnlySpan2D 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(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(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 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 }; diff --git a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs index 1026676f..4fd3b85b 100644 --- a/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs +++ b/tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_Span2D{T}.cs @@ -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 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 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 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 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 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. These should fill // or clear the entire wrapped 2D array (just like eg. Span.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 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 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 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 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 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 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 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(null), int[,] array = { - { 1, 2, 3 }, - { 4, 5, 6 } - }; + { 1, 2, 3 }, + { 4, 5, 6 } + }; Span2D span2d = new(array); @@ -555,9 +555,9 @@ ref Unsafe.AsRef(null), int[,] array = { - { 1, 2, 3 }, - { 4, 5, 6 } - }; + { 1, 2, 3 }, + { 4, 5, 6 } + }; Span2D 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, // 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 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 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 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 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 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 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 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 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 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 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 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 enumerable = new Span2D(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 enumerable = new Span2D(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; diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs index 37544a1f..c9ec0396 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand.cs @@ -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())); diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs index 17510748..cd47566f 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_AsyncRelayCommand{T}.cs @@ -69,10 +69,10 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionTrue() AsyncRelayCommand? 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? 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( i => - { - n = i; - return Task.CompletedTask; - }, i => i > 0); + { + n = i; + return Task.CompletedTask; + }, i => i > 0); Assert.IsFalse(command.CanExecute(null)); _ = Assert.ThrowsException(() => command.Execute(null)); diff --git a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs index 77998676..14a9a593 100644 --- a/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs +++ b/tests/CommunityToolkit.Mvvm.UnitTests/Test_Messenger.cs @@ -239,9 +239,9 @@ public void Test_Messenger_DuplicateRegistrationWithMessageType(Type type) messenger.Register(recipient, (r, m) => { }); _ = Assert.ThrowsException(() => - { - messenger.Register(recipient, (r, m) => { }); - }); + { + messenger.Register(recipient, (r, m) => { }); + }); } [TestCategory("Mvvm")] @@ -256,9 +256,9 @@ public void Test_Messenger_DuplicateRegistrationWithMessageTypeAndToken(Type typ messenger.Register(recipient, nameof(MessageA), (r, m) => { }); _ = Assert.ThrowsException(() => - { - messenger.Register(recipient, nameof(MessageA), (r, m) => { }); - }); + { + messenger.Register(recipient, nameof(MessageA), (r, m) => { }); + }); } [TestCategory("Mvvm")]