| 182 | }; |
| 183 | |
| 184 | fn build_input_array(size: usize) -> Vec<Option<i32>> { |
| 185 | // The input array is created by shuffling and repeating |
| 186 | // the seed values random number of times. |
| 187 | let mut seed: Vec<Option<i32>> = vec![ |
| 188 | None, |
| 189 | None, |
| 190 | None, |
| 191 | Some(1), |
| 192 | Some(2), |
| 193 | Some(3), |
| 194 | Some(4), |
| 195 | Some(5), |
| 196 | Some(6), |
| 197 | Some(7), |
| 198 | Some(8), |
| 199 | Some(9), |
| 200 | ]; |
| 201 | let mut result: Vec<Option<i32>> = Vec::with_capacity(size); |
| 202 | let mut ix = 0; |
| 203 | let mut rng = rng(); |
| 204 | // run length can go up to 8. Cap the max run length for smaller arrays to size / 2. |
| 205 | let max_run_length = 8_usize.min(1_usize.max(size / 2)); |
| 206 | while result.len() < size { |
| 207 | // shuffle the seed array if all the values are iterated. |
| 208 | if ix == 0 { |
| 209 | seed.shuffle(&mut rng); |
| 210 | } |
| 211 | // repeat the items between 1 and 8 times. Cap the length for smaller sized arrays |
| 212 | let num = max_run_length.min(rng.random_range(1..=max_run_length)); |
| 213 | for _ in 0..num { |
| 214 | result.push(seed[ix]); |
| 215 | } |
| 216 | ix += 1; |
| 217 | if ix == seed.len() { |
| 218 | ix = 0 |
| 219 | } |
| 220 | } |
| 221 | result.resize(size, None); |
| 222 | result |
| 223 | } |
| 224 | |
| 225 | #[test] |
| 226 | fn test_primitive_array_iter_round_trip() { |