Skip to content

Commit 7e67a9c

Browse files
committed
Fixed StyleCop warnings in HighPerformance tests
1 parent 9c90f66 commit 7e67a9c

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Buffers/Test_StringPool.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public void Test_StringPool_Cctor_Ok(int minimumSize, int x, int y, int size)
3838

3939
Assert.AreEqual(size, pool.Size);
4040

41-
Array maps = (Array)typeof(StringPool).GetField("maps", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pool);
41+
Array maps = (Array)typeof(StringPool).GetField("maps", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(pool)!;
4242

4343
Assert.AreEqual(x, maps.Length);
4444

45-
Type bucketType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap, Microsoft.Toolkit.HighPerformance");
45+
Type bucketType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap, Microsoft.Toolkit.HighPerformance")!;
4646

47-
int[] buckets = (int[])bucketType.GetField("buckets", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(maps.GetValue(0));
47+
int[] buckets = (int[])bucketType.GetField("buckets", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(maps.GetValue(0))!;
4848

4949
Assert.AreEqual(y, buckets.Length);
5050
}
@@ -64,7 +64,7 @@ public void Test_StringPool_Cctor_Fail(int size)
6464
}
6565
catch (ArgumentOutOfRangeException e)
6666
{
67-
var cctor = typeof(StringPool).GetConstructor(new[] { typeof(int) });
67+
var cctor = typeof(StringPool).GetConstructor(new[] { typeof(int) })!;
6868

6969
Assert.AreEqual(cctor.GetParameters()[0].Name, e.ParamName);
7070
}
@@ -158,7 +158,7 @@ public void Test_StringPool_Add_Overwrite()
158158
[MethodImpl(MethodImplOptions.NoInlining)]
159159
private static string ToStringNoInlining(object obj)
160160
{
161-
return obj.ToString();
161+
return obj.ToString()!;
162162
}
163163

164164
[TestCategory("StringPool")]
@@ -285,15 +285,15 @@ public void Test_StringPool_GetOrAdd_Overflow()
285285
}
286286

287287
// Get the buckets
288-
Array maps = (Array)typeof(StringPool).GetField("maps", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pool);
288+
Array maps = (Array)typeof(StringPool).GetField("maps", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(pool)!;
289289

290-
Type bucketType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap, Microsoft.Toolkit.HighPerformance");
291-
FieldInfo timestampInfo = bucketType.GetField("timestamp", BindingFlags.Instance | BindingFlags.NonPublic);
290+
Type bucketType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap, Microsoft.Toolkit.HighPerformance")!;
291+
FieldInfo timestampInfo = bucketType.GetField("timestamp", BindingFlags.Instance | BindingFlags.NonPublic)!;
292292

293293
// Force the timestamp to be the maximum value, or the test would take too long
294294
for (int i = 0; i < maps.LongLength; i++)
295295
{
296-
object map = maps.GetValue(i);
296+
object map = maps.GetValue(i)!;
297297

298298
timestampInfo.SetValue(map, uint.MaxValue);
299299

@@ -305,16 +305,16 @@ public void Test_StringPool_GetOrAdd_Overflow()
305305

306306
_ = pool.GetOrAdd(text);
307307

308-
Type heapEntryType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap+HeapEntry, Microsoft.Toolkit.HighPerformance");
308+
Type heapEntryType = Type.GetType("Microsoft.Toolkit.HighPerformance.Buffers.StringPool+FixedSizePriorityMap+HeapEntry, Microsoft.Toolkit.HighPerformance")!;
309309

310310
foreach (var map in maps)
311311
{
312312
// Get the heap for each bucket
313-
Array heapEntries = (Array)bucketType.GetField("heapEntries", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(map);
314-
FieldInfo fieldInfo = heapEntryType.GetField("Timestamp");
313+
Array heapEntries = (Array)bucketType.GetField("heapEntries", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(map)!;
314+
FieldInfo fieldInfo = heapEntryType.GetField("Timestamp")!;
315315

316316
// Extract the array with the timestamps in the heap nodes
317-
uint[] array = heapEntries.Cast<object>().Select(entry => (uint)fieldInfo.GetValue(entry)).ToArray();
317+
uint[] array = heapEntries.Cast<object>().Select(entry => (uint)fieldInfo.GetValue(entry)!).ToArray();
318318

319319
static bool IsMinHeap(uint[] array)
320320
{

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ArrayExtensions.1D.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Diagnostics.CodeAnalysis;
56
using System.Runtime.CompilerServices;
67
using Microsoft.Toolkit.HighPerformance.Extensions;
78
using Microsoft.VisualStudio.TestTools.UnitTesting;
89

910
namespace UnitTests.HighPerformance.Extensions
1011
{
1112
[TestClass]
13+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Partial test class")]
1214
public partial class Test_ArrayExtensions
1315
{
1416
[TestCategory("ArrayExtensions")]

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ArrayExtensions.2D.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Runtime.CompilerServices;
87
using Microsoft.Toolkit.HighPerformance.Enumerables;
98
using Microsoft.Toolkit.HighPerformance.Extensions;
@@ -167,8 +166,6 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayBottomRightCornerBoundar
167166

168167
[TestCategory("ArrayExtensions")]
169168
[TestMethod]
170-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
171-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
172169
public void Test_ArrayExtensions_2D_GetRow_Rectangle()
173170
{
174171
int[,] array =
@@ -201,8 +198,6 @@ public void Test_ArrayExtensions_2D_GetRow_Rectangle()
201198

202199
[TestCategory("ArrayExtensions")]
203200
[TestMethod]
204-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
205-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
206201
public void Test_ArrayExtensions_2D_GetColumn_Rectangle()
207202
{
208203
int[,] array =
@@ -239,8 +234,6 @@ public void Test_ArrayExtensions_2D_GetRow_Empty()
239234

240235
[TestCategory("ArrayExtensions")]
241236
[TestMethod]
242-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
243-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
244237
public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
245238
{
246239
int[,] array =
@@ -337,8 +330,6 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
337330

338331
[TestCategory("ArrayExtensions")]
339332
[TestMethod]
340-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
341-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
342333
public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers()
343334
{
344335
int[,] array =
@@ -384,8 +375,6 @@ public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers()
384375

385376
[TestCategory("ArrayExtensions")]
386377
[TestMethod]
387-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
388-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
389378
public void Test_ArrayExtensions_2D_RefEnumerable_Misc()
390379
{
391380
int[,] array1 =

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ReadOnlySpanExtensions.Count.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private sealed class Int : IEquatable<Int>
103103

104104
public Int(int value) => Value = value;
105105

106-
public bool Equals(Int other)
106+
public bool Equals(Int? other)
107107
{
108108
if (other is null)
109109
{
@@ -118,7 +118,7 @@ public bool Equals(Int other)
118118
return this.Value == other.Value;
119119
}
120120

121-
public override bool Equals(object obj)
121+
public override bool Equals(object? obj)
122122
{
123123
return ReferenceEquals(this, obj) || (obj is Int other && Equals(other));
124124
}

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ReadOnlySpanExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Runtime.CompilerServices;
89
using System.Runtime.InteropServices;
910
using Microsoft.Toolkit.HighPerformance.Extensions;
@@ -12,6 +13,7 @@
1213
namespace UnitTests.HighPerformance.Extensions
1314
{
1415
[TestClass]
16+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Partial test class")]
1517
public partial class Test_ReadOnlySpanExtensions
1618
{
1719
[TestCategory("ReadOnlySpanExtensions")]

UnitTests/UnitTests.HighPerformance.Shared/Memory/Test_ReadOnlySpan2D{T}.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,6 @@ public void Test_ReadOnlySpan2DT_GetEnumerator_Empty()
847847

848848
[TestCategory("ReadOnlySpan2DT")]
849849
[TestMethod]
850-
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
851-
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
852850
public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc()
853851
{
854852
int[,] array1 =

0 commit comments

Comments
 (0)