forked from CommunityToolkit/dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_ParallelHelper.ForEach.Ref2D.cs
More file actions
49 lines (41 loc) · 1.53 KB
/
Copy pathTest_ParallelHelper.ForEach.Ref2D.cs
File metadata and controls
49 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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);
}
}