|
8 | 8 | use std::collections::BTreeMap;
|
9 | 9 | use std::fmt;
|
10 | 10 |
|
11 |
| -pub fn least_satisfying<T, P>(slice: &[T], start_check: bool, mut predicate: P) -> usize |
| 11 | +pub fn least_satisfying<T, P>(slice: &[T], mut predicate: P) -> usize |
12 | 12 | where
|
13 | 13 | T: fmt::Display + fmt::Debug,
|
14 | 14 | P: FnMut(&T) -> Satisfies,
|
15 | 15 | {
|
16 | 16 | let mut cache = BTreeMap::new();
|
17 | 17 | let mut predicate = |idx: usize| *cache.entry(idx).or_insert_with(|| predicate(&slice[idx]));
|
18 | 18 | let mut unknown_ranges: Vec<(usize, usize)> = Vec::new();
|
19 |
| - let mut rm_no = 0; // presume that the slice starts with a no |
| 19 | + // presume that the slice starts with a no |
| 20 | + // this should be tested before call |
| 21 | + let mut rm_no = 0; |
20 | 22 |
|
21 |
| - if start_check { |
22 |
| - eprintln!("verifying the start of the range does not reproduce the regression"); |
23 |
| - match predicate(rm_no) { |
24 |
| - Satisfies::No => { |
25 |
| - eprintln!("confirmed the start of the range does not reproduce the regression") |
26 |
| - } |
27 |
| - _ => panic!("the start of the range to test must not reproduce the regression"), |
28 |
| - } |
29 |
| - } |
30 |
| - |
31 |
| - let mut lm_yes = slice.len() - 1; // presume that the slice ends with a yes |
32 |
| - |
33 |
| - eprintln!("verifying the end of the range reproduces the regression"); |
34 |
| - match predicate(lm_yes) { |
35 |
| - Satisfies::Yes => eprintln!("confirmed the end of the range reproduces the regression"), |
36 |
| - _ => panic!("the end of the range to test must reproduce the regression"), |
37 |
| - } |
| 23 | + // presume that the slice ends with a yes |
| 24 | + // this should be tested before the call |
| 25 | + let mut lm_yes = slice.len() - 1; |
38 | 26 |
|
39 | 27 | let mut next = (rm_no + lm_yes) / 2;
|
40 | 28 |
|
@@ -105,111 +93,111 @@ mod tests {
|
105 | 93 | }
|
106 | 94 | }
|
107 | 95 |
|
108 |
| - let res = least_satisfying(&satisfies_v, true, |i| *i); |
| 96 | + let res = least_satisfying(&satisfies_v, |i| *i); |
109 | 97 | let exp = first_yes.unwrap();
|
110 | 98 | TestResult::from_bool(res == exp)
|
111 | 99 | }
|
112 | 100 |
|
113 | 101 | #[test]
|
114 | 102 | fn least_satisfying_1() {
|
115 | 103 | assert_eq!(
|
116 |
| - least_satisfying(&[No, Unknown, Unknown, No, Yes], true,|i| *i), |
| 104 | + least_satisfying(&[No, Unknown, Unknown, No, Yes],|i| *i), |
117 | 105 | 4
|
118 | 106 | );
|
119 | 107 | }
|
120 | 108 |
|
121 | 109 | #[test]
|
122 | 110 | fn least_satisfying_1f() {
|
123 | 111 | assert_eq!(
|
124 |
| - least_satisfying(&[No, Unknown, Unknown, No, Yes], false,|i| *i), |
| 112 | + least_satisfying(&[No, Unknown, Unknown, No, Yes],|i| *i), |
125 | 113 | 4
|
126 | 114 | );
|
127 | 115 | }
|
128 | 116 |
|
129 | 117 | #[test]
|
130 | 118 | fn least_satisfying_2() {
|
131 | 119 | assert_eq!(
|
132 |
| - least_satisfying(&[No, Unknown, Yes, Unknown, Yes], true, |i| *i), |
| 120 | + least_satisfying(&[No, Unknown, Yes, Unknown, Yes], |i| *i), |
133 | 121 | 2
|
134 | 122 | );
|
135 | 123 | }
|
136 | 124 |
|
137 | 125 | #[test]
|
138 | 126 | fn least_satisfying_2f() {
|
139 | 127 | assert_eq!(
|
140 |
| - least_satisfying(&[No, Unknown, Yes, Unknown, Yes], false, |i| *i), |
| 128 | + least_satisfying(&[No, Unknown, Yes, Unknown, Yes], |i| *i), |
141 | 129 | 2
|
142 | 130 | );
|
143 | 131 | }
|
144 | 132 |
|
145 | 133 | #[test]
|
146 | 134 | fn least_satisfying_3() {
|
147 |
| - assert_eq!(least_satisfying(&[No, No, No, No, Yes], true, |i| *i), 4); |
| 135 | + assert_eq!(least_satisfying(&[No, No, No, No, Yes], |i| *i), 4); |
148 | 136 | }
|
149 | 137 |
|
150 | 138 | #[test]
|
151 | 139 | fn least_satisfying_3f() {
|
152 |
| - assert_eq!(least_satisfying(&[No, No, No, No, Yes], false, |i| *i), 4); |
| 140 | + assert_eq!(least_satisfying(&[No, No, No, No, Yes], |i| *i), 4); |
153 | 141 | }
|
154 | 142 |
|
155 | 143 | #[test]
|
156 | 144 | fn least_satisfying_4() {
|
157 |
| - assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], true, |i| *i), 2); |
| 145 | + assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], |i| *i), 2); |
158 | 146 | }
|
159 | 147 |
|
160 | 148 | #[test]
|
161 | 149 | fn least_satisfying_4f() {
|
162 |
| - assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], false, |i| *i), 2); |
| 150 | + assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], |i| *i), 2); |
163 | 151 | }
|
164 | 152 |
|
165 | 153 | #[test]
|
166 | 154 | fn least_satisfying_5() {
|
167 |
| - assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], true, |i| *i), 1); |
| 155 | + assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], |i| *i), 1); |
168 | 156 | }
|
169 | 157 |
|
170 | 158 | #[test]
|
171 | 159 | fn least_satisfying_5f() {
|
172 |
| - assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], false, |i| *i), 1); |
| 160 | + assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], |i| *i), 1); |
173 | 161 | }
|
174 | 162 |
|
175 | 163 | #[test]
|
176 | 164 | fn least_satisfying_6() {
|
177 | 165 | assert_eq!(
|
178 |
| - least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], true, |i| *i), |
| 166 | + least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], |i| *i), |
179 | 167 | 1
|
180 | 168 | );
|
181 | 169 | }
|
182 | 170 |
|
183 | 171 | #[test]
|
184 | 172 | fn least_satisfying_6f() {
|
185 | 173 | assert_eq!(
|
186 |
| - least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], false, |i| *i), |
| 174 | + least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], |i| *i), |
187 | 175 | 1
|
188 | 176 | );
|
189 | 177 | }
|
190 | 178 |
|
191 | 179 | #[test]
|
192 | 180 | fn least_satisfying_7() {
|
193 |
| - assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], true, |i| *i), 1); |
| 181 | + assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], |i| *i), 1); |
194 | 182 | }
|
195 | 183 |
|
196 | 184 | #[test]
|
197 | 185 | fn least_satisfying_7f() {
|
198 |
| - assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], false, |i| *i), 1); |
| 186 | + assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], |i| *i), 1); |
199 | 187 | }
|
200 | 188 |
|
201 | 189 | #[test]
|
202 | 190 | fn least_satisfying_8() {
|
203 | 191 | assert_eq!(
|
204 |
| - least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], true,|i| *i), |
| 192 | + least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes],|i| *i), |
205 | 193 | 5
|
206 | 194 | );
|
207 | 195 | }
|
208 | 196 |
|
209 | 197 | #[test]
|
210 | 198 | fn least_satisfying_8f() {
|
211 | 199 | assert_eq!(
|
212 |
| - least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], false,|i| *i), |
| 200 | + least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes],|i| *i), |
213 | 201 | 5
|
214 | 202 | );
|
215 | 203 | }
|
|
0 commit comments