1
1
#region
2
2
3
- using FluentAssertions ;
4
3
using System ;
5
4
using System . Collections . Generic ;
6
5
using System . Numerics ;
@@ -17,7 +16,7 @@ public static class DecoderTest
17
16
[ MemberData ( nameof ( TestUInt16 ) ) ]
18
17
[ MemberData ( nameof ( TestUInt32 ) ) ]
19
18
[ MemberData ( nameof ( TestInt32s ) ) ]
20
- [ MemberData ( nameof ( TestInt64s ) ) ]
19
+ [ MemberData ( nameof ( TestUInt64s ) ) ]
21
20
[ MemberData ( nameof ( TestBigIntegers ) ) ]
22
21
[ MemberData ( nameof ( TestDoubles ) ) ]
23
22
[ MemberData ( nameof ( TestFloats ) ) ]
@@ -27,7 +26,7 @@ public static class DecoderTest
27
26
[ MemberData ( nameof ( TestBytes ) ) ]
28
27
[ MemberData ( nameof ( TestMaps ) ) ]
29
28
[ 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
31
30
{
32
31
foreach ( var entry in tests )
33
32
{
@@ -37,14 +36,7 @@ public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShou
37
36
using var database = new ArrayBuffer ( input ) ;
38
37
var decoder = new Decoder ( database , 0 , false ) ;
39
38
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 ) ;
48
40
}
49
41
}
50
42
@@ -56,7 +48,7 @@ public static IEnumerable<object[]> TestUInt16()
56
48
{ ( 1 << 8 ) - 1 , [ 0xa1 , 0xff ] } ,
57
49
{ 500 , [ 0xa2 , 0x1 , 0xf4 ] } ,
58
50
{ 10872 , [ 0xa2 , 0x2a , 0x78 ] } ,
59
- { ushort . MaxValue , [ 0xa2 , 0xff , 0xff ] }
51
+ { ( int ) ushort . MaxValue , [ 0xa2 , 0xff , 0xff ] }
60
52
} ;
61
53
62
54
yield return [ uint16s ] ;
@@ -66,13 +58,13 @@ public static IEnumerable<object[]> TestUInt32()
66
58
{
67
59
var uint32s = new Dictionary < object , byte [ ] >
68
60
{
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 ] }
76
68
} ;
77
69
78
70
yield return [ uint32s ] ;
@@ -99,18 +91,18 @@ public static IEnumerable<object[]> TestInt32s()
99
91
yield return [ int32s ] ;
100
92
}
101
93
102
- public static IEnumerable < object [ ] > TestInt64s ( )
94
+ public static IEnumerable < object [ ] > TestUInt64s ( )
103
95
{
104
- var int64s = new Dictionary < object , byte [ ] >
96
+ var uint64s = new Dictionary < object , byte [ ] >
105
97
{
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 ] }
109
101
} ;
110
102
111
103
for ( var power = 1 ; power < 8 ; power ++ )
112
104
{
113
- var key = Int64Pow ( 2 , 8 * power ) - 1 ;
105
+ var key = UInt64Pow ( 2 , 8 * power ) - 1 ;
114
106
var value = new byte [ 2 + power ] ;
115
107
116
108
value [ 0 ] = ( byte ) power ;
@@ -120,15 +112,15 @@ public static IEnumerable<object[]> TestInt64s()
120
112
value [ i ] = 0xff ;
121
113
}
122
114
123
- int64s . Add ( key , value ) ;
115
+ uint64s . Add ( key , value ) ;
124
116
}
125
117
126
- yield return [ int64s ] ;
118
+ yield return [ uint64s ] ;
127
119
}
128
120
129
- public static long Int64Pow ( long x , int pow )
121
+ public static ulong UInt64Pow ( ulong x , int pow )
130
122
{
131
- long ret = 1 ;
123
+ ulong ret = 1 ;
132
124
while ( pow != 0 )
133
125
{
134
126
if ( ( pow & 1 ) == 1 )
@@ -163,7 +155,7 @@ public static IEnumerable<object[]> TestBigIntegers()
163
155
bigInts . Add ( key , value ) ;
164
156
}
165
157
166
- yield return [ bigInts , /*useShouldBe*/ true ] ;
158
+ yield return [ bigInts ] ;
167
159
}
168
160
169
161
public static IEnumerable < object [ ] > TestDoubles ( )
@@ -205,16 +197,16 @@ public static IEnumerable<object[]> TestPointers()
205
197
{
206
198
var pointers = new Dictionary < object , byte [ ] >
207
199
{
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 ] }
218
210
} ;
219
211
220
212
yield return [ pointers ] ;
0 commit comments