File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -782,6 +782,30 @@ quickcheck! {
782
782
assert_eq!( it. next( ) , None ) ;
783
783
assert_eq!( it. next( ) , None ) ;
784
784
}
785
+
786
+ fn peek_nth_next_if( a: Vec <u8 >) -> ( ) {
787
+ let mut it = peek_nth( a. clone( ) ) ;
788
+ for ( idx, mut value) in a. iter( ) . copied( ) . enumerate( ) {
789
+ let should_be_none = it. next_if( |x| x != & value) ;
790
+ assert_eq!( should_be_none, None ) ;
791
+ if value % 5 == 0 {
792
+ // Sometimes, peek up to 3 further.
793
+ let n = value as usize % 3 ;
794
+ let nth = it. peek_nth( n) ;
795
+ assert_eq!( nth, a. get( idx + n) ) ;
796
+ } else if value % 5 == 1 {
797
+ // Sometimes, peek next element mutably.
798
+ if let Some ( v) = it. peek_mut( ) {
799
+ * v = v. wrapping_sub( 1 ) ;
800
+ let should_be_none = it. next_if_eq( & value) ;
801
+ assert_eq!( should_be_none, None ) ;
802
+ value = value. wrapping_sub( 1 ) ;
803
+ }
804
+ }
805
+ let eq = it. next_if_eq( & value) ;
806
+ assert_eq!( eq, Some ( value) ) ;
807
+ }
808
+ }
785
809
}
786
810
787
811
quickcheck ! {
You can’t perform that action at this time.
0 commit comments