Skip to content

Commit efd1243

Browse files
author
DaZombieKiller
committed
Add tests for RefEnumerable indexers
1 parent dae4f84 commit efd1243

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,53 @@ public void Test_ReadOnlyRefEnumerable_DangerousCreate_BelowZero(int length, int
4747
{
4848
_ = ReadOnlyRefEnumerable<int>.DangerousCreate(in Unsafe.NullRef<int>(), length, step);
4949
}
50+
51+
[TestCategory("ReadOnlyRefEnumerable")]
52+
[TestMethod]
53+
[DataRow(1, 1, new[] { 1 })]
54+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
55+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
56+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
57+
public void Test_ReadOnlyRefEnumerable_Indexer(int length, int step, int[] values)
58+
{
59+
Span<int> data = new[]
60+
{
61+
1, 2, 3, 4,
62+
5, 6, 7, 8,
63+
9, 10, 11, 12,
64+
13, 14, 15, 16
65+
};
66+
67+
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], length, step);
68+
69+
for (int i = 0; i < enumerable.Length; i++)
70+
{
71+
Assert.AreEqual(enumerable[i], values[i]);
72+
}
73+
}
74+
75+
#if NETCOREAPP3_1_OR_GREATER
76+
[TestCategory("ReadOnlyRefEnumerable")]
77+
[TestMethod]
78+
[DataRow(1, 1, new[] { 1 })]
79+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
80+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
81+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
82+
public void Test_ReadOnlyRefEnumerable_Index_Indexer(int length, int step, int[] values)
83+
{
84+
Span<int> data = new[]
85+
{
86+
1, 2, 3, 4,
87+
5, 6, 7, 8,
88+
9, 10, 11, 12,
89+
13, 14, 15, 16
90+
};
91+
92+
ReadOnlyRefEnumerable<int> enumerable = ReadOnlyRefEnumerable<int>.DangerousCreate(in data[0], length, step);
93+
94+
Assert.AreEqual(values[^1], enumerable[^1]);
95+
}
96+
#endif
5097
}
5198
}
5299

UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,53 @@ public void Test_RefEnumerable_DangerousCreate_BelowZero(int length, int step)
4747
{
4848
_ = RefEnumerable<int>.DangerousCreate(ref Unsafe.NullRef<int>(), length, step);
4949
}
50+
51+
[TestCategory("RefEnumerable")]
52+
[TestMethod]
53+
[DataRow(1, 1, new[] { 1 })]
54+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
55+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
56+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
57+
public void Test_RefEnumerable_Indexer(int length, int step, int[] values)
58+
{
59+
Span<int> data = new[]
60+
{
61+
1, 2, 3, 4,
62+
5, 6, 7, 8,
63+
9, 10, 11, 12,
64+
13, 14, 15, 16
65+
};
66+
67+
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], length, step);
68+
69+
for (int i = 0; i < enumerable.Length; i++)
70+
{
71+
Assert.AreEqual(enumerable[i], values[i]);
72+
}
73+
}
74+
75+
#if NETCOREAPP3_1_OR_GREATER
76+
[TestCategory("RefEnumerable")]
77+
[TestMethod]
78+
[DataRow(1, 1, new[] { 1 })]
79+
[DataRow(4, 1, new[] { 1, 2, 3, 4 })]
80+
[DataRow(4, 4, new[] { 1, 5, 9, 13 })]
81+
[DataRow(4, 5, new[] { 1, 6, 11, 16 })]
82+
public void Test_RefEnumerable_Index_Indexer(int length, int step, int[] values)
83+
{
84+
Span<int> data = new[]
85+
{
86+
1, 2, 3, 4,
87+
5, 6, 7, 8,
88+
9, 10, 11, 12,
89+
13, 14, 15, 16
90+
};
91+
92+
RefEnumerable<int> enumerable = RefEnumerable<int>.DangerousCreate(ref data[0], length, step);
93+
94+
Assert.AreEqual(values[^1], enumerable[^1]);
95+
}
96+
#endif
5097
}
5198
}
5299

0 commit comments

Comments
 (0)