1
- use itertools:: { EitherOrBoth , Itertools } ;
1
+ use itertools:: Itertools ;
2
2
use std:: fmt:: Debug ;
3
- use std:: ops:: BitXor ;
4
3
use quickcheck:: quickcheck;
5
4
6
5
struct Unspecialized < I > ( I ) ;
@@ -63,21 +62,19 @@ fn check_specialized_count_last_nth_sizeh<'a, IterItem, Iter>(
63
62
}
64
63
}
65
64
66
- fn check_specialized_fold_xor < ' a , IterItem , Iter > ( it : & Iter )
65
+ fn check_specialized_fold < IterItem , Iter > ( it : & Iter )
67
66
where
68
- IterItem : ' a
69
- + BitXor
70
- + Eq
71
- + Debug
72
- + BitXor < <IterItem as BitXor >:: Output , Output = <IterItem as BitXor >:: Output >
73
- + Clone ,
74
- <IterItem as BitXor >:: Output :
75
- BitXor < Output = <IterItem as BitXor >:: Output > + Eq + Debug + Clone ,
76
- Iter : Iterator < Item = IterItem > + Clone + ' a ,
67
+ IterItem : Eq + Debug + Clone ,
68
+ Iter : Iterator < Item = IterItem > + Clone ,
77
69
{
78
- check_specialized ( it, |mut i| {
79
- let first = i. next ( ) . map ( |f| f. clone ( ) ^ ( f. clone ( ) ^ f) ) ;
80
- i. fold ( first, |acc, v : IterItem | acc. map ( move |a| v ^ a) )
70
+ check_specialized ( it, |i| {
71
+ let mut parameters_from_fold = vec ! [ ] ;
72
+ let fold_result = i. fold ( vec ! [ ] , |mut acc, v : IterItem | {
73
+ parameters_from_fold. push ( ( acc. clone ( ) , v. clone ( ) ) ) ;
74
+ acc. push ( v) ;
75
+ acc
76
+ } ) ;
77
+ ( parameters_from_fold, fold_result)
81
78
} ) ;
82
79
}
83
80
@@ -86,13 +83,13 @@ fn put_back_test(test_vec: Vec<i32>, known_expected_size: Option<usize>) {
86
83
// Lexical lifetimes support
87
84
let pb = itertools:: put_back ( test_vec. iter ( ) ) ;
88
85
check_specialized_count_last_nth_sizeh ( & pb, known_expected_size) ;
89
- check_specialized_fold_xor ( & pb) ;
86
+ check_specialized_fold ( & pb) ;
90
87
}
91
88
92
89
let mut pb = itertools:: put_back ( test_vec. into_iter ( ) ) ;
93
90
pb. put_back ( 1 ) ;
94
91
check_specialized_count_last_nth_sizeh ( & pb, known_expected_size. map ( |x| x + 1 ) ) ;
95
- check_specialized_fold_xor ( & pb)
92
+ check_specialized_fold ( & pb)
96
93
}
97
94
98
95
#[ test]
@@ -111,28 +108,12 @@ fn merge_join_by_test(i1: Vec<usize>, i2: Vec<usize>, known_expected_size: Optio
111
108
let i2 = i2. into_iter ( ) ;
112
109
let mjb = i1. clone ( ) . merge_join_by ( i2. clone ( ) , std:: cmp:: Ord :: cmp) ;
113
110
check_specialized_count_last_nth_sizeh ( & mjb, known_expected_size) ;
114
- // Rust 1.24 compatibility:
115
- fn eob_left_z ( eob : EitherOrBoth < usize , usize > ) -> usize {
116
- eob. left ( ) . unwrap_or ( 0 )
117
- }
118
- fn eob_right_z ( eob : EitherOrBoth < usize , usize > ) -> usize {
119
- eob. right ( ) . unwrap_or ( 0 )
120
- }
121
- fn eob_both_z ( eob : EitherOrBoth < usize , usize > ) -> usize {
122
- let ( a, b) = eob. both ( ) . unwrap_or ( ( 0 , 0 ) ) ;
123
- assert_eq ! ( a, b) ;
124
- a
125
- }
126
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_left_z) ) ;
127
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_right_z) ) ;
128
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_both_z) ) ;
111
+ check_specialized_fold ( & mjb) ;
129
112
130
113
// And the other way around
131
114
let mjb = i2. merge_join_by ( i1, std:: cmp:: Ord :: cmp) ;
132
115
check_specialized_count_last_nth_sizeh ( & mjb, known_expected_size) ;
133
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_left_z) ) ;
134
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_right_z) ) ;
135
- check_specialized_fold_xor ( & mjb. clone ( ) . map ( eob_both_z) ) ;
116
+ check_specialized_fold ( & mjb) ;
136
117
}
137
118
138
119
#[ test]
0 commit comments