@@ -270,7 +270,6 @@ where
270
270
}
271
271
}
272
272
273
- /*
274
273
#[ cfg( test) ]
275
274
mod tests {
276
275
use crate :: {
@@ -287,28 +286,23 @@ mod tests {
287
286
#[ test]
288
287
fn test_mut_scheduled ( ) {
289
288
// With the current impl, seed of 1 will result in a split at pos 2.
290
- let mut rand = XKCDRand::new();
291
- let mut corpus: InMemoryCorpus<BytesInput, _> = InMemoryCorpus::new();
292
- corpus.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into());
293
- corpus.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into());
294
-
295
- let (testcase, _) = corpus
296
- .next(&mut rand)
297
- .expect("Corpus did not contain entries");
289
+ let mut rand = XKCDRand :: with_seed ( 5 ) ;
290
+ let mut corpus: InMemoryCorpus < BytesInput > = InMemoryCorpus :: new ( ) ;
291
+ corpus
292
+ . add ( Testcase :: new ( vec ! [ 'a' as u8 , 'b' as u8 , 'c' as u8 ] ) . into ( ) )
293
+ . unwrap ( ) ;
294
+ corpus
295
+ . add ( Testcase :: new ( vec ! [ 'd' as u8 , 'e' as u8 , 'f' as u8 ] ) . into ( ) )
296
+ . unwrap ( ) ;
297
+
298
+ let testcase = corpus. get ( 0 ) . expect ( "Corpus did not contain entries" ) ;
298
299
let mut input = testcase. borrow_mut ( ) . load_input ( ) . unwrap ( ) . clone ( ) ;
299
300
300
- let mut state = State::new(corpus, (), InMemoryCorpus::new(), ());
301
+ let mut state = State :: new ( rand , corpus, ( ) , InMemoryCorpus :: new ( ) , ( ) ) ;
301
302
302
303
rand. set_seed ( 5 ) ;
303
304
304
- let mut mutator = StdScheduledMutator::<
305
- InMemoryCorpus<BytesInput, XKCDRand>,
306
- _,
307
- _,
308
- State<_, (), _, InMemoryCorpus<BytesInput, XKCDRand>, (), _>,
309
- >::new();
310
-
311
- mutation_splice(&mut mutator, &mut rand, &mut state, &mut input).unwrap();
305
+ mutation_splice ( & mut state, & mut input) . unwrap ( ) ;
312
306
313
307
#[ cfg( feature = "std" ) ]
314
308
println ! ( "{:?}" , input. bytes( ) ) ;
@@ -321,27 +315,37 @@ mod tests {
321
315
#[ test]
322
316
fn test_havoc ( ) {
323
317
// With the current impl, seed of 1 will result in a split at pos 2.
324
- let mut rand = StdRand::new(0x1337);
325
- let mut corpus: InMemoryCorpus<BytesInput, StdRand> = InMemoryCorpus::new();
326
- corpus.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into());
327
- corpus.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into());
328
-
329
- let (testcase, _) = corpus
330
- .next(&mut rand)
331
- .expect("Corpus did not contain entries");
318
+ let rand = StdRand :: with_seed ( 0x1337 ) ;
319
+ let mut corpus: InMemoryCorpus < BytesInput > = InMemoryCorpus :: new ( ) ;
320
+ corpus
321
+ . add ( Testcase :: new ( vec ! [ 'a' as u8 , 'b' as u8 , 'c' as u8 ] ) . into ( ) )
322
+ . unwrap ( ) ;
323
+ corpus
324
+ . add ( Testcase :: new ( vec ! [ 'd' as u8 , 'e' as u8 , 'f' as u8 ] ) . into ( ) )
325
+ . unwrap ( ) ;
326
+
327
+ let testcase = corpus. get ( 0 ) . expect ( "Corpus did not contain entries" ) ;
332
328
let mut input = testcase. borrow_mut ( ) . load_input ( ) . unwrap ( ) . clone ( ) ;
333
329
let input_prior = input. clone ( ) ;
334
330
335
- let mut state = State::new(corpus, (), InMemoryCorpus::new(), ());
331
+ let mut state = State :: new ( rand , corpus, ( ) , InMemoryCorpus :: new ( ) , ( ) ) ;
336
332
337
- let mut havoc = HavocBytesMutator::new(StdScheduledMutator::new());
333
+ let havoc = HavocBytesMutator :: new ( StdScheduledMutator :: new ( ) ) ;
338
334
339
335
assert_eq ! ( input, input_prior) ;
340
336
337
+ let mut equal_in_a_row = 0 ;
338
+
341
339
for i in 0 ..42 {
342
- havoc.mutate(&mut rand, &mut state, &mut input, i).unwrap();
343
- assert_ne!(input, input_prior);
340
+ havoc. mutate ( & mut state, & mut input, i) . unwrap ( ) ;
341
+
342
+ // Make sure we actually mutate something, at least sometimes
343
+ equal_in_a_row = if input == input_prior {
344
+ equal_in_a_row + 1
345
+ } else {
346
+ 0
347
+ } ;
348
+ assert_ne ! ( equal_in_a_row, 5 ) ;
344
349
}
345
350
}
346
351
}
347
- */
0 commit comments