1
0
mirror of https://github.com/chylex/.NET-Community-Toolkit.git synced 2025-08-16 05:31:46 +02:00
Files
.github
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
CommunityToolkit.Mvvm
CommunityToolkit.Mvvm.SourceGenerators
build
tests
CommunityToolkit.Common.UnitTests
CommunityToolkit.Diagnostics.UnitTests
CommunityToolkit.HighPerformance.UnitTests
Buffers
Enumerables
Extensions
Helpers
Internals
Test_BitHelper.cs
Test_HashCode{T}.cs
Test_ObjectMarshal.cs
Test_ParallelHelper.For.cs
Test_ParallelHelper.For2D.cs
Test_ParallelHelper.ForEach.In.cs
Test_ParallelHelper.ForEach.In2D.cs
Test_ParallelHelper.ForEach.Ref.cs
Test_ParallelHelper.ForEach.Ref2D.cs
Test_ParallelHelper.ThrowExceptions.cs
Memory
Streams
CommunityToolkit.HighPerformance.UnitTests.csproj
Test_Box{T}.cs
Test_NullableReadOnlyRef{T}.cs
Test_NullableRef{T}.cs
Test_ReadOnlyRef{T}.cs
Test_Ref{T}.cs
CommunityToolkit.Mvvm.DisableINotifyPropertyChanging.UnitTests
CommunityToolkit.Mvvm.ExternalAssembly
CommunityToolkit.Mvvm.Internals.UnitTests
CommunityToolkit.Mvvm.SourceGenerators.UnitTests
CommunityToolkit.Mvvm.UnitTests
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
.runsettings
CODE_OF_CONDUCT.md
Contributing.md
Directory.Build.props
Directory.Build.targets
License.md
README.md
ThirdPartyNotices.txt
azure-pipelines.yml
dotnet Community Toolkit.sln
toolkit.snk
version.json
2022-05-03 21:21:10 -07:00

50 lines
1.5 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using CommunityToolkit.HighPerformance.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommunityToolkit.HighPerformance.UnitTests.Helpers;
public partial class Test_ParallelHelper
{
[TestMethod]
[DataRow(1, 1, 0, 0, 1, 1)]
[DataRow(1, 2, 0, 0, 1, 2)]
[DataRow(2, 3, 0, 0, 2, 3)]
[DataRow(2, 3, 0, 1, 2, 2)]
[DataRow(3, 3, 1, 1, 2, 2)]
[DataRow(12, 12, 2, 4, 3, 3)]
[DataRow(64, 64, 0, 0, 32, 32)]
[DataRow(64, 64, 13, 14, 23, 22)]
public void Test_ParallelHelper_ForEach_Ref2D(
int sizeY,
int sizeX,
int row,
int column,
int height,
int width)
{
int[,] data = CreateRandomData2D(sizeY, sizeX);
int[,] copy = (int[,])data.Clone();
// Prepare the target data iteratively
foreach (ref int n in copy.AsSpan2D(row, column, height, width))
{
n = unchecked(n * 397);
}
Memory2D<int> memory = data.AsMemory2D(row, column, height, width);
Assert.AreEqual(memory.Length, height * width);
Assert.AreEqual(memory.Height, height);
Assert.AreEqual(memory.Width, width);
// Do the same computation in parallel, then compare the two arrays
ParallelHelper.ForEach(memory, new Multiplier(397));
CollectionAssert.AreEqual(data, copy);
}
}