11#region
22
3- using FluentAssertions ;
43using System ;
54using System . Collections . Generic ;
65using System . Numerics ;
@@ -17,7 +16,7 @@ public static class DecoderTest
1716 [ MemberData ( nameof ( TestUInt16 ) ) ]
1817 [ MemberData ( nameof ( TestUInt32 ) ) ]
1918 [ MemberData ( nameof ( TestInt32s ) ) ]
20- [ MemberData ( nameof ( TestInt64s ) ) ]
19+ [ MemberData ( nameof ( TestUInt64s ) ) ]
2120 [ MemberData ( nameof ( TestBigIntegers ) ) ]
2221 [ MemberData ( nameof ( TestDoubles ) ) ]
2322 [ MemberData ( nameof ( TestFloats ) ) ]
@@ -27,7 +26,7 @@ public static class DecoderTest
2726 [ MemberData ( nameof ( TestBytes ) ) ]
2827 [ MemberData ( nameof ( TestMaps ) ) ]
2928 [ MemberData ( nameof ( TestArrays ) ) ]
30- 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
3130 {
3231 foreach ( var entry in tests )
3332 {
@@ -37,14 +36,7 @@ public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShou
3736 using var database = new ArrayBuffer ( input ) ;
3837 var decoder = new Decoder ( database , 0 , false ) ;
3938 var val = decoder . Decode < T > ( 0 , out _ ) ;
40- if ( useShouldBe )
41- {
42- val . Should ( ) . Be ( expect ) ;
43- }
44- else
45- {
46- val . Should ( ) . BeEquivalentTo ( expect , options => options . RespectingRuntimeTypes ( ) ) ;
47- }
39+ Assert . Equal ( expect , val ) ;
4840 }
4941 }
5042
@@ -56,7 +48,7 @@ public static IEnumerable<object[]> TestUInt16()
5648 { ( 1 << 8 ) - 1 , [ 0xa1 , 0xff ] } ,
5749 { 500 , [ 0xa2 , 0x1 , 0xf4 ] } ,
5850 { 10872 , [ 0xa2 , 0x2a , 0x78 ] } ,
59- { ushort . MaxValue , [ 0xa2 , 0xff , 0xff ] }
51+ { ( int ) ushort . MaxValue , [ 0xa2 , 0xff , 0xff ] }
6052 } ;
6153
6254 yield return [ uint16s ] ;
@@ -66,13 +58,13 @@ public static IEnumerable<object[]> TestUInt32()
6658 {
6759 var uint32s = new Dictionary < object , byte [ ] >
6860 {
69- { 0 , [ 0xc0 ] } ,
70- { ( 1 << 8 ) - 1 , [ 0xc1 , 0xff ] } ,
71- { 500 , [ 0xc2 , 0x1 , 0xf4 ] } ,
72- { 10872 , [ 0xc2 , 0x2a , 0x78 ] } ,
73- { ( 1 << 16 ) - 1 , [ 0xc2 , 0xff , 0xff ] } ,
74- { ( 1 << 24 ) - 1 , [ 0xc3 , 0xff , 0xff , 0xff ] } ,
75- { 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 ] }
7668 } ;
7769
7870 yield return [ uint32s ] ;
@@ -99,18 +91,18 @@ public static IEnumerable<object[]> TestInt32s()
9991 yield return [ int32s ] ;
10092 }
10193
102- public static IEnumerable < object [ ] > TestInt64s ( )
94+ public static IEnumerable < object [ ] > TestUInt64s ( )
10395 {
104- var int64s = new Dictionary < object , byte [ ] >
96+ var uint64s = new Dictionary < object , byte [ ] >
10597 {
106- { 0L , [ 0x0 , 0x2 ] } ,
107- { 500L , [ 0x2 , 0x2 , 0x1 , 0xf4 ] } ,
108- { 10872 , [ 0x2 , 0x2 , 0x2a , 0x78 ] }
98+ { 0UL , [ 0x0 , 0x2 ] } ,
99+ { 500UL , [ 0x2 , 0x2 , 0x1 , 0xf4 ] } ,
100+ { 10872UL , [ 0x2 , 0x2 , 0x2a , 0x78 ] }
109101 } ;
110102
111103 for ( var power = 1 ; power < 8 ; power ++ )
112104 {
113- var key = Int64Pow ( 2 , 8 * power ) - 1 ;
105+ var key = UInt64Pow ( 2 , 8 * power ) - 1 ;
114106 var value = new byte [ 2 + power ] ;
115107
116108 value [ 0 ] = ( byte ) power ;
@@ -120,15 +112,15 @@ public static IEnumerable<object[]> TestInt64s()
120112 value [ i ] = 0xff ;
121113 }
122114
123- int64s . Add ( key , value ) ;
115+ uint64s . Add ( key , value ) ;
124116 }
125117
126- yield return [ int64s ] ;
118+ yield return [ uint64s ] ;
127119 }
128120
129- public static long Int64Pow ( long x , int pow )
121+ public static ulong UInt64Pow ( ulong x , int pow )
130122 {
131- long ret = 1 ;
123+ ulong ret = 1 ;
132124 while ( pow != 0 )
133125 {
134126 if ( ( pow & 1 ) == 1 )
@@ -163,7 +155,7 @@ public static IEnumerable<object[]> TestBigIntegers()
163155 bigInts . Add ( key , value ) ;
164156 }
165157
166- yield return [ bigInts , /*useShouldBe*/ true ] ;
158+ yield return [ bigInts ] ;
167159 }
168160
169161 public static IEnumerable < object [ ] > TestDoubles ( )
@@ -205,16 +197,16 @@ public static IEnumerable<object[]> TestPointers()
205197 {
206198 var pointers = new Dictionary < object , byte [ ] >
207199 {
208- { 0 , [ 0x20 , 0x0 ] } ,
209- { 5 , [ 0x20 , 0x5 ] } ,
210- { 10 , [ 0x20 , 0xa ] } ,
211- { ( 1 << 10 ) - 1 , [ 0x23 , 0xff ] } ,
212- { 3017 , [ 0x28 , 0x3 , 0xc9 ] } ,
213- { ( 1 << 19 ) - 5 , [ 0x2f , 0xf7 , 0xfb ] } ,
214- { ( 1 << 19 ) + ( 1 << 11 ) - 1 , [ 0x2f , 0xff , 0xff ] } ,
215- { ( 1 << 27 ) - 2 , [ 0x37 , 0xf7 , 0xf7 , 0xfe ] } ,
216- { ( ( long ) 1 << 27 ) + ( 1 << 19 ) + ( 1 << 11 ) - 1 , [ 0x37 , 0xff , 0xff , 0xff ] } ,
217- { ( ( 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 ] }
218210 } ;
219211
220212 yield return [ pointers ] ;
0 commit comments