@@ -59,6 +59,22 @@ public static void RunDivRem_OneSmallOneLargeBI()
59
59
}
60
60
}
61
61
62
+ [ Fact ]
63
+ public static void RunDivRem_OneLargeOneHalfBI ( )
64
+ {
65
+ byte [ ] tempByteArray1 = new byte [ 0 ] ;
66
+ byte [ ] tempByteArray2 = new byte [ 0 ] ;
67
+
68
+ // Divide Method - Two Large BigIntegers
69
+ for ( int i = - 1 ; i <= 1 ; i ++ )
70
+ for ( int j = - 1 ; j <= 1 ; j ++ )
71
+ {
72
+ tempByteArray1 = GetRandomByteArray ( s_random , 512 + i ) ;
73
+ tempByteArray2 = GetRandomByteArray ( s_random , 256 + j ) ;
74
+ VerifyDivRemString ( Print ( tempByteArray1 ) + Print ( tempByteArray2 ) + "bDivRem" ) ;
75
+ }
76
+ }
77
+
62
78
[ Fact ]
63
79
public static void RunDivRem_OneLargeOne0BI ( )
64
80
{
@@ -114,6 +130,73 @@ public static void Boundary()
114
130
VerifyDivRemString ( Math . Pow ( 2 , 33 ) + " 2 bDivRem" ) ;
115
131
}
116
132
133
+ [ Fact ]
134
+ public static void RunDivRemMedium ( )
135
+ {
136
+ byte [ ] tempByteArray1 = new byte [ 0 ] ;
137
+ byte [ ] tempByteArray2 = new byte [ 0 ] ;
138
+
139
+ for ( int i = 1 ; i < 8 ; i ++ )
140
+ {
141
+ var num = 1 << i ;
142
+ tempByteArray1 = GetRandomByteArray ( s_random , num ) ;
143
+ tempByteArray2 = GetRandomByteArray ( s_random , num / 2 ) ;
144
+ VerifyDivRemString ( Print ( tempByteArray2 ) + Print ( tempByteArray1 ) + "bDivRem" ) ;
145
+ }
146
+
147
+ // Divide Method - Two Large BigIntegers
148
+ for ( int i = - 1 ; i <= 1 ; i ++ )
149
+ for ( int j = - 1 ; j <= 1 ; j ++ )
150
+ {
151
+ int num = ( 1 << 7 ) + i ;
152
+ tempByteArray1 = GetRandomByteArray ( s_random , num ) ;
153
+ tempByteArray2 = GetRandomByteArray ( s_random , num / 3 + j ) ;
154
+ VerifyDivRemString ( Print ( tempByteArray2 ) + Print ( tempByteArray1 ) + "bDivRem" ) ;
155
+ }
156
+ }
157
+
158
+ [ Fact ]
159
+ [ OuterLoop ]
160
+ public static void RunDivRemLarge ( )
161
+ {
162
+ byte [ ] tempByteArray1 = new byte [ 0 ] ;
163
+ byte [ ] tempByteArray2 = new byte [ 0 ] ;
164
+
165
+ for ( int i = 8 ; i < 10 ; i ++ )
166
+ {
167
+ var num = 1 << i ;
168
+ tempByteArray1 = GetRandomByteArray ( s_random , num ) ;
169
+ tempByteArray2 = GetRandomByteArray ( s_random , num / 2 ) ;
170
+ VerifyDivRemString ( Print ( tempByteArray2 ) + Print ( tempByteArray1 ) + "bDivRem" ) ;
171
+ }
172
+
173
+ // Divide Method - Two Large BigIntegers
174
+ for ( int i = - 1 ; i <= 1 ; i ++ )
175
+ for ( int j = - 1 ; j <= 1 ; j ++ )
176
+ {
177
+ int num = ( 1 << 10 ) + i ;
178
+ tempByteArray1 = GetRandomByteArray ( s_random , num ) ;
179
+ tempByteArray2 = GetRandomByteArray ( s_random , num / 3 + j ) ;
180
+ VerifyDivRemString ( Print ( tempByteArray2 ) + Print ( tempByteArray1 ) + "bDivRem" ) ;
181
+ }
182
+ }
183
+
184
+ [ Fact ]
185
+ public void D3n2nBound ( )
186
+ {
187
+ var right = ( BigInteger . One << ( BigIntegerCalculator . DivideBurnikelZieglerThreshold * 4 * 32 - 1 ) )
188
+ + ( BigInteger . One << ( BigIntegerCalculator . DivideBurnikelZieglerThreshold * 2 * 32 ) ) - 1 ;
189
+ var rem = right - 1 ;
190
+
191
+ var qi = BigIntegerCalculator . DivideBurnikelZieglerThreshold * 8 * 32 * 4 - 1 ;
192
+ var q = ( BigInteger . One << qi ) - 1 ;
193
+ var left = q * right + rem ;
194
+
195
+ var ( q2 , r2 ) = BigInteger . DivRem ( left , right ) ;
196
+ Assert . Equal ( q , q2 ) ;
197
+ Assert . Equal ( rem , r2 ) ;
198
+ }
199
+
117
200
[ Fact ]
118
201
public static void RunDivRemTests ( )
119
202
{
@@ -211,4 +294,16 @@ private static string Print(byte[] bytes)
211
294
return MyBigIntImp . Print ( bytes ) ;
212
295
}
213
296
}
297
+
298
+
299
+ [ Collection ( nameof ( DisableParallelization ) ) ]
300
+ public class divremTestThreshold
301
+ {
302
+ [ Fact ]
303
+ public void RunDivRemMedium ( )
304
+ {
305
+ BigIntTools . Utils . RunWithFakeThreshold ( BigIntegerCalculator . DivideBurnikelZieglerThreshold , 8 , divremTest . RunDivRemMedium ) ;
306
+ }
307
+
308
+ }
214
309
}
0 commit comments