Skip to content

Commit 873b31b

Browse files
committed
Added tests for IntPtrComparer.
1 parent ba12e96 commit 873b31b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

ReClass.NET/Util/IntPtrComparer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using ReClassNET.Extensions;
34

45
namespace ReClassNET.Util
56
{
@@ -9,7 +10,7 @@ public class IntPtrComparer : IComparer<IntPtr>
910

1011
public int Compare(IntPtr x, IntPtr y)
1112
{
12-
return x.ToInt64().CompareTo(y.ToInt64());
13+
return x.CompareTo(y);
1314
}
1415
}
1516
}

ReClass.NET_Tests/ReClass.NET_Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="Util\DirectedGraphTest.cs" />
7575
<Compile Include="Util\GrowingListTest.cs" />
7676
<Compile Include="Util\HexadecimalFormatterTest.cs" />
77+
<Compile Include="Util\IntPtrComparerTest.cs" />
7778
<Compile Include="Util\NumberFormatTest.cs" />
7879
<Compile Include="Util\PathUtilTest.cs" />
7980
<Compile Include="Util\XElementSerializerTest.cs" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using NFluent;
7+
using ReClassNET.Util;
8+
using Xunit;
9+
10+
namespace ReClass.NET_Tests.Util
11+
{
12+
public class IntPtrComparerTest
13+
{
14+
public static TheoryData<IntPtr, IntPtr, bool> GetTestCompareData() => new TheoryData<IntPtr, IntPtr, bool>
15+
{
16+
{ IntPtr.Zero, IntPtr.Zero, false },
17+
{ (IntPtr)0x1, IntPtr.Zero, false },
18+
{ (IntPtr)0x1, (IntPtr)0x10, true },
19+
{ (IntPtr)0x1, unchecked((IntPtr)(int)0xFFFFFFFF), true },
20+
{ unchecked((IntPtr)(int)0xFFFFFFFF), unchecked((IntPtr)(int)0xFFFFFFFF), false },
21+
{ unchecked((IntPtr)(int)0xFFFFFFFF), IntPtr.Zero, false }
22+
};
23+
24+
[Theory]
25+
[MemberData(nameof(GetTestCompareData))]
26+
public void TestCompare(IntPtr lhs, IntPtr rhs, bool lhsIsSmaller)
27+
{
28+
var comparer = IntPtrComparer.Instance;
29+
30+
Check.That(comparer.Compare(lhs, rhs) < 0).IsEqualTo(lhsIsSmaller);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)