@@ -234,102 +234,6 @@ pub fn ComplexFindMatchLengthWithLimit(mut s1: &[u8], mut s2: &[u8], mut limit:
234234 matched + ( limit & 7usize ) // made it through the loop
235235}
236236
237- mod test {
238- #[ allow( unused) ]
239- fn construct_situation ( seed : & [ u8 ] , mut output : & mut [ u8 ] , limit : usize , matchfor : usize ) {
240- output[ ..] . clone_from_slice ( seed) ;
241- if matchfor >= limit {
242- return ;
243- }
244- output[ matchfor] = output[ matchfor] . wrapping_add ( ( matchfor as u8 % 253u8 ) . wrapping_add ( 1 ) ) ;
245- }
246- #[ test]
247- fn test_find_match_length ( ) {
248- let mut a = [ 91u8 ; 600000 ] ;
249- let mut b = [ 0u8 ; 600000 ] ;
250- for i in 1 ..a. len ( ) {
251- a[ i] = ( a[ i - 1 ] % 19u8 ) . wrapping_add ( 17 ) ;
252- }
253- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 0 ) ;
254- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 0 ) ;
255- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 1 ) ;
256- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 1 ) ;
257- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 10 ) ;
258- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 10 ) ;
259- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 9 ) ;
260- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 9 ) ;
261- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 7 ) ;
262- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 7 ) ;
263- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 8 ) ;
264- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 8 ) ;
265- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 48 ) ;
266- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 48 ) ;
267- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 49 ) ;
268- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 49 ) ;
269- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 63 ) ;
270- assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 63 ) ;
271- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 222 ) ;
272- assert_eq ! (
273- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
274- 222
275- ) ;
276- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 1590 ) ;
277- assert_eq ! (
278- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
279- 1590
280- ) ;
281- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 12590 ) ;
282- assert_eq ! (
283- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
284- 12590
285- ) ;
286- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 52592 ) ;
287- assert_eq ! (
288- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
289- 52592
290- ) ;
291- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 152592 ) ;
292- assert_eq ! (
293- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
294- 152592
295- ) ;
296- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 252591 ) ;
297- assert_eq ! (
298- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
299- 252591
300- ) ;
301- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131072 ) ;
302- assert_eq ! (
303- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
304- 131072
305- ) ;
306- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131073 ) ;
307- assert_eq ! (
308- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
309- 131073
310- ) ;
311- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131072 + 64 + 32 + 16 + 8 ) ;
312- assert_eq ! (
313- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
314- 131072 + 64 + 32 + 16 + 8
315- ) ;
316- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 272144 + 64 + 32 + 16 + 8 + 1 ) ;
317- assert_eq ! (
318- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
319- 272144 + 64 + 32 + 16 + 8 + 1
320- ) ;
321- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 2 * 272144 + 64 + 32 + 16 + 8 ) ;
322- assert_eq ! (
323- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
324- 2 * 272144 + 64 + 32 + 16 + 8
325- ) ;
326- construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , a. len ( ) ) ;
327- assert_eq ! (
328- super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
329- a. len( )
330- ) ;
331- }
332- }
333237#[ allow( unused) ]
334238pub fn slowFindMatchLengthWithLimit ( s1 : & [ u8 ] , s2 : & [ u8 ] , limit : usize ) -> usize {
335239 for ( index, it) in s1[ ..limit] . iter ( ) . zip ( s2[ ..limit] . iter ( ) ) . enumerate ( ) {
@@ -1398,3 +1302,101 @@ pub fn BrotliFindAllStaticDictionaryMatches(
13981302 }
13991303 has_found_match
14001304}
1305+
1306+ #[ cfg( test) ]
1307+ mod test {
1308+ #[ allow( unused) ]
1309+ fn construct_situation ( seed : & [ u8 ] , mut output : & mut [ u8 ] , limit : usize , matchfor : usize ) {
1310+ output[ ..] . clone_from_slice ( seed) ;
1311+ if matchfor >= limit {
1312+ return ;
1313+ }
1314+ output[ matchfor] = output[ matchfor] . wrapping_add ( ( matchfor as u8 % 253u8 ) . wrapping_add ( 1 ) ) ;
1315+ }
1316+ #[ test]
1317+ fn test_find_match_length ( ) {
1318+ let mut a = [ 91u8 ; 600000 ] ;
1319+ let mut b = [ 0u8 ; 600000 ] ;
1320+ for i in 1 ..a. len ( ) {
1321+ a[ i] = ( a[ i - 1 ] % 19u8 ) . wrapping_add ( 17 ) ;
1322+ }
1323+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 0 ) ;
1324+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 0 ) ;
1325+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 1 ) ;
1326+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 1 ) ;
1327+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 10 ) ;
1328+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 10 ) ;
1329+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 9 ) ;
1330+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 9 ) ;
1331+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 7 ) ;
1332+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 7 ) ;
1333+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 8 ) ;
1334+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 8 ) ;
1335+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 48 ) ;
1336+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 48 ) ;
1337+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 49 ) ;
1338+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 49 ) ;
1339+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 63 ) ;
1340+ assert_eq ! ( super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) , 63 ) ;
1341+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 222 ) ;
1342+ assert_eq ! (
1343+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1344+ 222
1345+ ) ;
1346+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 1590 ) ;
1347+ assert_eq ! (
1348+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1349+ 1590
1350+ ) ;
1351+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 12590 ) ;
1352+ assert_eq ! (
1353+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1354+ 12590
1355+ ) ;
1356+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 52592 ) ;
1357+ assert_eq ! (
1358+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1359+ 52592
1360+ ) ;
1361+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 152592 ) ;
1362+ assert_eq ! (
1363+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1364+ 152592
1365+ ) ;
1366+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 252591 ) ;
1367+ assert_eq ! (
1368+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1369+ 252591
1370+ ) ;
1371+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131072 ) ;
1372+ assert_eq ! (
1373+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1374+ 131072
1375+ ) ;
1376+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131073 ) ;
1377+ assert_eq ! (
1378+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1379+ 131073
1380+ ) ;
1381+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 131072 + 64 + 32 + 16 + 8 ) ;
1382+ assert_eq ! (
1383+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1384+ 131072 + 64 + 32 + 16 + 8
1385+ ) ;
1386+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 272144 + 64 + 32 + 16 + 8 + 1 ) ;
1387+ assert_eq ! (
1388+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1389+ 272144 + 64 + 32 + 16 + 8 + 1
1390+ ) ;
1391+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , 2 * 272144 + 64 + 32 + 16 + 8 ) ;
1392+ assert_eq ! (
1393+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1394+ 2 * 272144 + 64 + 32 + 16 + 8
1395+ ) ;
1396+ construct_situation ( & a[ ..] , & mut b[ ..] , a. len ( ) , a. len ( ) ) ;
1397+ assert_eq ! (
1398+ super :: FindMatchLengthWithLimit ( & a[ ..] , & b[ ..] , a. len( ) ) ,
1399+ a. len( )
1400+ ) ;
1401+ }
1402+ }
0 commit comments