Skip to content

Commit

Permalink
add basic conformance tests in BitPackedCompressor
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Dec 18, 2024
1 parent a0c1a30 commit 22982d2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions vortex-sampling-compressor/src/compressors/bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,55 @@ impl EncodingCompressor for BitPackedCompressor {
HashSet::from([&BitPackedEncoding as EncodingRef])
}
}

#[cfg(test)]
mod tests {
use vortex_array::array::{ConstantArray, PrimitiveArray};
use vortex_array::IntoArrayData;

use crate::compressors::bitpacked::{BITPACK_NO_PATCHES, BITPACK_WITH_PATCHES};
use crate::compressors::EncodingCompressor;
use crate::SamplingCompressor;

#[test]
fn cannot_compress() {
// cannot compress when array contains negative values
assert!(BITPACK_NO_PATCHES
.can_compress(&PrimitiveArray::from(vec![-1i32, 0i32, 1i32]).into_array())
.is_none());

// Non-integer primitive array.
assert!(BITPACK_NO_PATCHES
.can_compress(&PrimitiveArray::from(vec![0f32, 1f32]).into_array())
.is_none());

// non-PrimitiveArray
assert!(BITPACK_NO_PATCHES
.can_compress(&ConstantArray::new(3u32, 10).into_array())
.is_none());
}

#[test]
fn can_compress() {
// Unsigned integers
assert!(BITPACK_NO_PATCHES
.can_compress(&PrimitiveArray::from(vec![0u32, 1u32, 2u32]).into_array())
.is_some());

// Signed non-negative integers
assert!(BITPACK_WITH_PATCHES
.can_compress(&PrimitiveArray::from(vec![0i32, 1i32, 2i32]).into_array())
.is_some());
}

#[test]
fn compress_negatives_fails() {
assert!(BITPACK_NO_PATCHES
.compress(
&PrimitiveArray::from(vec![-1i32, 0i32]).into_array(),
None,
SamplingCompressor::default(),
)
.is_err());
}
}

0 comments on commit 22982d2

Please sign in to comment.