Skip to content

Commit

Permalink
Fixed StyleCop warnings in HighPerformance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 5, 2020
1 parent 9c90f66 commit 7e67a9c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void Test_StringPool_Cctor_Ok(int minimumSize, int x, int y, int size)

Assert.AreEqual(size, pool.Size);

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

Assert.AreEqual(x, maps.Length);

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

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

Assert.AreEqual(y, buckets.Length);
}
Expand All @@ -64,7 +64,7 @@ public void Test_StringPool_Cctor_Fail(int size)
}
catch (ArgumentOutOfRangeException e)
{
var cctor = typeof(StringPool).GetConstructor(new[] { typeof(int) });
var cctor = typeof(StringPool).GetConstructor(new[] { typeof(int) })!;

Assert.AreEqual(cctor.GetParameters()[0].Name, e.ParamName);
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public void Test_StringPool_Add_Overwrite()
[MethodImpl(MethodImplOptions.NoInlining)]
private static string ToStringNoInlining(object obj)
{
return obj.ToString();
return obj.ToString()!;
}

[TestCategory("StringPool")]
Expand Down Expand Up @@ -285,15 +285,15 @@ public void Test_StringPool_GetOrAdd_Overflow()
}

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

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

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

timestampInfo.SetValue(map, uint.MaxValue);

Expand All @@ -305,16 +305,16 @@ public void Test_StringPool_GetOrAdd_Overflow()

_ = pool.GetOrAdd(text);

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

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

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

static bool IsMinHeap(uint[] array)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTests.HighPerformance.Extensions
{
[TestClass]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Partial test class")]
public partial class Test_ArrayExtensions
{
[TestCategory("ArrayExtensions")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.HighPerformance.Enumerables;
using Microsoft.Toolkit.HighPerformance.Extensions;
Expand Down Expand Up @@ -167,8 +166,6 @@ public void Test_ArrayExtensions_2D_AsSpan2DAndFillArrayBottomRightCornerBoundar

[TestCategory("ArrayExtensions")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ArrayExtensions_2D_GetRow_Rectangle()
{
int[,] array =
Expand Down Expand Up @@ -201,8 +198,6 @@ public void Test_ArrayExtensions_2D_GetRow_Rectangle()

[TestCategory("ArrayExtensions")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ArrayExtensions_2D_GetColumn_Rectangle()
{
int[,] array =
Expand Down Expand Up @@ -239,8 +234,6 @@ public void Test_ArrayExtensions_2D_GetRow_Empty()

[TestCategory("ArrayExtensions")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()
{
int[,] array =
Expand Down Expand Up @@ -337,8 +330,6 @@ public void Test_ArrayExtensions_2D_GetRowOrColumn_Helpers()

[TestCategory("ArrayExtensions")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers()
{
int[,] array =
Expand Down Expand Up @@ -384,8 +375,6 @@ public void Test_ArrayExtensions_2D_ReadOnlyGetRowOrColumn_Helpers()

[TestCategory("ArrayExtensions")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ArrayExtensions_2D_RefEnumerable_Misc()
{
int[,] array1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private sealed class Int : IEquatable<Int>

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

public bool Equals(Int other)
public bool Equals(Int? other)
{
if (other is null)
{
Expand All @@ -118,7 +118,7 @@ public bool Equals(Int other)
return this.Value == other.Value;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || (obj is Int other && Equals(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Toolkit.HighPerformance.Extensions;
Expand All @@ -12,6 +13,7 @@
namespace UnitTests.HighPerformance.Extensions
{
[TestClass]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Partial test class")]
public partial class Test_ReadOnlySpanExtensions
{
[TestCategory("ReadOnlySpanExtensions")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,6 @@ public void Test_ReadOnlySpan2DT_GetEnumerator_Empty()

[TestCategory("ReadOnlySpan2DT")]
[TestMethod]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312", Justification = "Dummy loop variable")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501", Justification = "Empty test loop")]
public void Test_ReadOnlySpan2DT_ReadOnlyRefEnumerable_Misc()
{
int[,] array1 =
Expand Down

0 comments on commit 7e67a9c

Please sign in to comment.