Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit d57b5d0

Browse files
committed
Added unit tests
1 parent dc909db commit d57b5d0

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if !WINDOWS_UWP
6+
7+
using System;
8+
using System.Runtime.CompilerServices;
9+
using Microsoft.Toolkit.HighPerformance.Enumerables;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
12+
namespace UnitTests.HighPerformance.Enumerables
13+
{
14+
[TestClass]
15+
public class Test_ReadOnlyRefEnumerable
16+
{
17+
[TestCategory("ReadOnlyRefEnumerable")]
18+
[TestMethod]
19+
[DataRow(1, 1, new[] { 1 })]
20+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
21+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
22+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
23+
public void Test_ReadOnlyRefEnumerable_DangerousCreate_Ok(int length, int step, int[] values)
24+
{
25+
Span<int> data = new[]
26+
{
27+
1, 2, 3, 4,
28+
5, 6, 7, 8,
29+
9, 10, 11, 12,
30+
13, 14, 15, 16
31+
};
32+
33+
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], length, step);
34+
35+
int[] result = enumerable.ToArray();
36+
37+
CollectionAssert.AreEqual(result, values);
38+
}
39+
40+
[TestCategory("ReadOnlyRefEnumerable")]
41+
[TestMethod]
42+
[DataRow(-44, 10)]
43+
[DataRow(10, -14)]
44+
[DataRow(-32, -1)]
45+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
46+
public void Test_ReadOnlyRefEnumerable_DangerousCreate_BelowZero(int length, int step)
47+
{
48+
_ = ReadOnlyRefEnumerable<int>.DangerousCreate(in Unsafe.NullRef<int>(), length, step);
49+
}
50+
}
51+
}
52+
53+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if !WINDOWS_UWP
6+
7+
using System;
8+
using System.Runtime.CompilerServices;
9+
using Microsoft.Toolkit.HighPerformance.Enumerables;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
12+
namespace UnitTests.HighPerformance.Enumerables
13+
{
14+
[TestClass]
15+
public class Test_RefEnumerable
16+
{
17+
[TestCategory("RefEnumerable")]
18+
[TestMethod]
19+
[DataRow(1, 1, new[] { 1 })]
20+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
21+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
22+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
23+
public void Test_RefEnumerable_DangerousCreate_Ok(int length, int step, int[] values)
24+
{
25+
Span<int> data = new[]
26+
{
27+
1, 2, 3, 4,
28+
5, 6, 7, 8,
29+
9, 10, 11, 12,
30+
13, 14, 15, 16
31+
};
32+
33+
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], length, step);
34+
35+
int[] result = enumerable.ToArray();
36+
37+
CollectionAssert.AreEqual(result, values);
38+
}
39+
40+
[TestCategory("RefEnumerable")]
41+
[TestMethod]
42+
[DataRow(-44, 10)]
43+
[DataRow(10, -14)]
44+
[DataRow(-32, -1)]
45+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
46+
public void Test_RefEnumerable_DangerousCreate_BelowZero(int length, int step)
47+
{
48+
_ = RefEnumerable<int>.DangerousCreate(ref Unsafe.NullRef<int>(), length, step);
49+
}
50+
}
51+
}
52+
53+
#endif

UnitTests/UnitTests.HighPerformance.Shared/UnitTests.HighPerformance.Shared.projitems

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<Compile Include="$(MSBuildThisFileDirectory)Buffers\Test_StringPool.cs" />
1717
<Compile Include="$(MSBuildThisFileDirectory)Buffers\Test_SpanOwner{T}.cs" />
1818
<Compile Include="$(MSBuildThisFileDirectory)Buffers\TrackingArrayPool{T}.cs" />
19+
<Compile Include="$(MSBuildThisFileDirectory)Enumerables\Test_ReadOnlyRefEnumerable{T}.cs" />
20+
<Compile Include="$(MSBuildThisFileDirectory)Enumerables\Test_RefEnumerable{T}.cs" />
1921
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_ArrayExtensions.3D.cs" />
2022
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_ArrayExtensions.2D.cs" />
2123
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_ArrayExtensions.1D.cs" />

0 commit comments

Comments
 (0)