Skip to main content

vortex_array/
test_harness.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::io::Write;
5
6use goldenfile::Mint;
7use goldenfile::differs::binary_diff;
8use itertools::Itertools;
9use vortex_error::VortexResult;
10
11use crate::arrays::BoolArray;
12use crate::arrays::bool::BoolArrayExt;
13
14/// Check that a named metadata matches its previous versioning.
15///
16/// Goldenfile takes care of checking for equality against a checked-in file.
17#[allow(clippy::unwrap_used)]
18pub fn check_metadata(name: &str, metadata: &[u8]) {
19    let mut mint = Mint::new("goldenfiles/");
20    let mut f = mint
21        .new_goldenfile_with_differ(name, Box::new(binary_diff))
22        .unwrap();
23    f.write_all(metadata).unwrap();
24}
25
26/// Outputs the indices of the true values in a BoolArray
27pub fn to_int_indices(indices_bits: BoolArray) -> VortexResult<Vec<u64>> {
28    let buffer = indices_bits.to_bit_buffer();
29    let mask = indices_bits.validity_mask()?;
30    Ok(buffer
31        .iter()
32        .enumerate()
33        .filter_map(|(idx, v)| (v && mask.value(idx)).then_some(idx as u64))
34        .collect_vec())
35}