alamb commented on code in PR #7962: URL: https://github.com/apache/arrow-rs/pull/7962#discussion_r2225160768
########## arrow-ord/src/sort.rs: ########## @@ -4709,4 +4731,77 @@ mod tests { assert_eq!(&sorted[0], &expected_struct_array); } + + /// A simple, correct but slower reference implementation. + fn naive_partition(array: &BooleanArray) -> (Vec<u32>, Vec<u32>) { + let len = array.len(); + let mut valid = Vec::with_capacity(len); + let mut nulls = Vec::with_capacity(len); + for i in 0..len { + if array.is_valid(i) { + valid.push(i as u32); + } else { + nulls.push(i as u32); + } + } + (valid, nulls) + } + + #[test] + fn fuzz_partition_validity() { + let mut rng = StdRng::seed_from_u64(0xF00D_CAFE); + for _ in 0..1_000 { + // random length up to 512 + let len = rng.random_range(0..512); + // build a random BooleanArray with some nulls + let mut builder = BooleanBuilder::new(); + for _ in 0..len { + if rng.random_bool(0.2) { + builder.append_null(); + } else { + builder.append_value(rng.random_bool(0.5)); + } + } + let array = builder.finish(); + + // run both implementations + let (v1, n1) = partition_validity(&array); + let (v2, n2) = naive_partition(&array); + + assert_eq!(v1, v2, "valid mismatch on random array {array:?}"); + assert_eq!(n1, n2, "null mismatch on random array {array:?}"); + + // also test a sliced view + if len >= 4 { + let slice = array.slice(2, len - 4); Review Comment: I recommend picking a random slice not just always by 2 Specifically I think it is important to ensure we slice some arrays by more than 64 to ensure they have to skip an entire 64 bit word in addition to having an offset -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org