Skip to content

Commit 98c697c

Browse files
committed
Test type equality in more cases
1 parent 6809909 commit 98c697c

File tree

2 files changed

+44
-51
lines changed

2 files changed

+44
-51
lines changed

MaxMind.Db.Test/DecoderTest.cs

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class DecoderTest
1616
[MemberData(nameof(TestUInt16))]
1717
[MemberData(nameof(TestUInt32))]
1818
[MemberData(nameof(TestInt32s))]
19-
[MemberData(nameof(TestInt64s))]
19+
[MemberData(nameof(TestUInt64s))]
2020
[MemberData(nameof(TestBigIntegers))]
2121
[MemberData(nameof(TestDoubles))]
2222
[MemberData(nameof(TestFloats))]
@@ -26,7 +26,7 @@ public static class DecoderTest
2626
[MemberData(nameof(TestBytes))]
2727
[MemberData(nameof(TestMaps))]
2828
[MemberData(nameof(TestArrays))]
29-
public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShouldBe = false) where T : class
29+
public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests) where T : class
3030
{
3131
foreach (var entry in tests)
3232
{
@@ -36,14 +36,7 @@ public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShou
3636
using var database = new ArrayBuffer(input);
3737
var decoder = new Decoder(database, 0, false);
3838
var val = decoder.Decode<T>(0, out _);
39-
if (useShouldBe)
40-
{
4139
Assert.Equal(expect, val);
42-
}
43-
else
44-
{
45-
Assert.Equivalent(expect, val);
46-
}
4740
}
4841
}
4942

@@ -55,7 +48,7 @@ public static IEnumerable<object[]> TestUInt16()
5548
{(1 << 8) - 1, [0xa1, 0xff] },
5649
{500, [0xa2, 0x1, 0xf4] },
5750
{10872, [0xa2, 0x2a, 0x78] },
58-
{ushort.MaxValue, [0xa2, 0xff, 0xff] }
51+
{(int) ushort.MaxValue, [0xa2, 0xff, 0xff] }
5952
};
6053

6154
yield return [uint16s];
@@ -65,13 +58,13 @@ public static IEnumerable<object[]> TestUInt32()
6558
{
6659
var uint32s = new Dictionary<object, byte[]>
6760
{
68-
{0, [0xc0] },
69-
{(1 << 8) - 1, [0xc1, 0xff] },
70-
{500, [0xc2, 0x1, 0xf4] },
71-
{10872, [0xc2, 0x2a, 0x78] },
72-
{(1 << 16) - 1, [0xc2, 0xff, 0xff] },
73-
{(1 << 24) - 1, [0xc3, 0xff, 0xff, 0xff] },
74-
{uint.MaxValue, [0xc4, 0xff, 0xff, 0xff, 0xff] }
61+
{0L, [0xc0] },
62+
{(1L << 8) - 1, [0xc1, 0xff] },
63+
{500L, [0xc2, 0x1, 0xf4] },
64+
{10872L, [0xc2, 0x2a, 0x78] },
65+
{(1L << 16) - 1, [0xc2, 0xff, 0xff] },
66+
{(1L << 24) - 1, [0xc3, 0xff, 0xff, 0xff] },
67+
{(long) uint.MaxValue, [0xc4, 0xff, 0xff, 0xff, 0xff] }
7568
};
7669

7770
yield return [uint32s];
@@ -98,18 +91,18 @@ public static IEnumerable<object[]> TestInt32s()
9891
yield return [int32s];
9992
}
10093

101-
public static IEnumerable<object[]> TestInt64s()
94+
public static IEnumerable<object[]> TestUInt64s()
10295
{
103-
var int64s = new Dictionary<object, byte[]>
96+
var uint64s = new Dictionary<object, byte[]>
10497
{
105-
{0L, [0x0, 0x2] },
106-
{500L, [0x2, 0x2, 0x1, 0xf4] },
107-
{10872, [0x2, 0x2, 0x2a, 0x78] }
98+
{0UL, [0x0, 0x2] },
99+
{500UL, [0x2, 0x2, 0x1, 0xf4] },
100+
{10872UL, [0x2, 0x2, 0x2a, 0x78] }
108101
};
109102

110103
for (var power = 1; power < 8; power++)
111104
{
112-
var key = Int64Pow(2, 8 * power) - 1;
105+
var key = UInt64Pow(2, 8 * power) - 1;
113106
var value = new byte[2 + power];
114107

115108
value[0] = (byte)power;
@@ -119,15 +112,15 @@ public static IEnumerable<object[]> TestInt64s()
119112
value[i] = 0xff;
120113
}
121114

122-
int64s.Add(key, value);
115+
uint64s.Add(key, value);
123116
}
124117

125-
yield return [int64s];
118+
yield return [uint64s];
126119
}
127120

128-
public static long Int64Pow(long x, int pow)
121+
public static ulong UInt64Pow(ulong x, int pow)
129122
{
130-
long ret = 1;
123+
ulong ret = 1;
131124
while (pow != 0)
132125
{
133126
if ((pow & 1) == 1)
@@ -162,7 +155,7 @@ public static IEnumerable<object[]> TestBigIntegers()
162155
bigInts.Add(key, value);
163156
}
164157

165-
yield return [bigInts, /*useShouldBe*/ true];
158+
yield return [bigInts];
166159
}
167160

168161
public static IEnumerable<object[]> TestDoubles()
@@ -204,16 +197,16 @@ public static IEnumerable<object[]> TestPointers()
204197
{
205198
var pointers = new Dictionary<object, byte[]>
206199
{
207-
{0, [0x20, 0x0] },
208-
{5, [0x20, 0x5] },
209-
{10, [0x20, 0xa] },
210-
{(1 << 10) - 1, [0x23, 0xff] },
211-
{3017, [0x28, 0x3, 0xc9] },
212-
{(1 << 19) - 5, [0x2f, 0xf7, 0xfb] },
213-
{(1 << 19) + (1 << 11) - 1, [0x2f, 0xff, 0xff] },
214-
{(1 << 27) - 2, [0x37, 0xf7, 0xf7, 0xfe] },
215-
{((long) 1 << 27) + (1 << 19) + (1 << 11) - 1, [0x37, 0xff, 0xff, 0xff] },
216-
{((long) 1 << 31) - 1, [0x38, 0x7f, 0xff, 0xff, 0xff] }
200+
{0L, [0x20, 0x0] },
201+
{5L, [0x20, 0x5] },
202+
{10L, [0x20, 0xa] },
203+
{(1L << 10) - 1, [0x23, 0xff] },
204+
{3017L, [0x28, 0x3, 0xc9] },
205+
{(1L << 19) - 5, [0x2f, 0xf7, 0xfb] },
206+
{(1L << 19) + (1 << 11) - 1, [0x2f, 0xff, 0xff] },
207+
{(1L << 27) - 2, [0x37, 0xf7, 0xf7, 0xfe] },
208+
{(1L << 27) + (1 << 19) + (1 << 11) - 1, [0x37, 0xff, 0xff, 0xff] },
209+
{(1L << 31) - 1, [0x38, 0x7f, 0xff, 0xff, 0xff] }
217210
};
218211

219212
yield return [pointers];

MaxMind.Db.Test/ReaderTest.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ private static void TestDecodingTypes(IDictionary<string, object>? record)
351351
Assert.Equal("unicode! ☯ - ♫", record["utf8_string"]);
352352

353353
var array = (List<object>)record["array"];
354-
Assert.Equivalent(3, array.Count);
355-
Assert.Equivalent(1, array[0]);
356-
Assert.Equivalent(2, array[1]);
357-
Assert.Equivalent(3, array[2]);
354+
Assert.Equal(3, array.Count);
355+
Assert.Equal(1L, array[0]);
356+
Assert.Equal(2L, array[1]);
357+
Assert.Equal(3L, array[2]);
358358

359359
var map = (Dictionary<string, object>)record["map"];
360360
Assert.Single(map);
@@ -364,17 +364,17 @@ private static void TestDecodingTypes(IDictionary<string, object>? record)
364364
Assert.Equal("hello", mapX["utf8_stringX"]);
365365

366366
var arrayX = (List<object>)mapX["arrayX"];
367-
Assert.Equivalent(3, arrayX.Count);
368-
Assert.Equivalent(7, arrayX[0]);
369-
Assert.Equivalent(8, arrayX[1]);
370-
Assert.Equivalent(9, arrayX[2]);
367+
Assert.Equal(3, arrayX.Count);
368+
Assert.Equal(7L, arrayX[0]);
369+
Assert.Equal(8L, arrayX[1]);
370+
Assert.Equal(9L, arrayX[2]);
371371

372372
Assert.Equal(42.123456, (double)record["double"], 9);
373373
Assert.Equal(1.1F, (float)record["float"], 5);
374374
Assert.Equal(-268435456, record["int32"]);
375375
Assert.Equal(100, record["uint16"]);
376-
Assert.Equivalent(268435456, record["uint32"]);
377-
Assert.Equivalent(1152921504606846976, record["uint64"]);
376+
Assert.Equal(268435456L, record["uint32"]);
377+
Assert.Equal(1152921504606846976UL, record["uint64"]);
378378
Assert.Equal(
379379
BigInteger.Parse("1329227995784915872903807060280344576"),
380380
record["uint128"]);
@@ -407,7 +407,7 @@ public void TestDecodingTypesToObject()
407407
Assert.Equal(-268435456, record.Int32);
408408
Assert.Equal(100, record.Uint16);
409409
Assert.Equal(268435456, record.Uint32);
410-
Assert.Equivalent(1152921504606846976, record.Uint64);
410+
Assert.Equal(1152921504606846976UL, record.Uint64);
411411
Assert.Equal(BigInteger.Parse("1329227995784915872903807060280344576"), record.Uint128);
412412

413413
Assert.Equal("injected string", record.Nonexistant.Injected);
@@ -443,8 +443,8 @@ public void TestZeros()
443443
Assert.Equal(0, (float)record["float"], 5);
444444
Assert.Equal(0, record["int32"]);
445445
Assert.Equal(0, record["uint16"]);
446-
Assert.Equivalent(0, record["uint32"]);
447-
Assert.Equivalent(0, record["uint64"]);
446+
Assert.Equal(0L, record["uint32"]);
447+
Assert.Equal(0UL, record["uint64"]);
448448
Assert.Equal(new BigInteger(0), record["uint128"]);
449449
}
450450

0 commit comments

Comments
 (0)